def test_currentsession(self):
tester = app.test_client(self)
response = tester.get('/api/v1/session' , content_type='application/json')
#print response.data
#self.assertIn(b'REDACTED', response.data)
# def test_login_correct(self):
# tester = app.test_client(self)
# credentials = { "credentials" : {
# "user" : "admin",
# "password" : "nbv12345",
# "server" : "172.28.225.163"
# }}
# response = tester.post(
# '/api/v1/session' ,
# data = json.dumps(credentials),
# content_type='application/json'
# )
# self.assertIn(b'success', response.data)
python类test_client()的实例源码
def setUp(self):
"""Setup method for spinning up a test instance of app"""
app.config['TESTING'] = True
app.config['WTF_CSRF_ENABLED'] = False
self.app = app.test_client()
self.app.testing = True
self.authorization = {
'Authorization': "Basic {user}".format(
user=base64.b64encode(b"test:asdf").decode("ascii")
)
}
self.content_type = 'application/json'
self.dummy_name = 'dummy'
self.dummy_user = json.dumps(
{'username': 'dummy', 'languages': ['testLang']}
)
self.dummy_lang = json.dumps(
{'name': 'dummy', 'users': ['No one']}
)
def setUp(self):
self.ctx = app.app_context()
self.ctx.push()
db.drop_all() # just in case
db.create_all()
self.client = app.test_client()
def setup_class(cls):
"""
When a Test is created override the ``database`` attribute for all
the tables with a SqliteDatabase in memory.
"""
for table in TABLES:
table._meta.database = cls.TEST_DB
table.create_table(fail_silently=True)
cls.app = app.test_client()
def setUp(self):
app.config['TESTING'] = True
self.app = app.test_client()
self.app_context = app.app_context()
self.app_context.push()
def setUp(self):
self.app = app.test_client()
def setUp(self):
self.db_fd, self.db_filename = tempfile.mkstemp()
# FIXME: this isn't actually working.
app.config['DATABASE_URI'] = 'sqlite:///' + self.db_filename
self.app = app.test_client()
db.create_all()
def setUp(self):
'''Creates a test client, disables logging, connects to the database
and creates state and city tables for temporary testing purposes.
'''
self.app = app.test_client()
logging.disable(logging.CRITICAL)
BaseModel.database.connect()
BaseModel.database.create_tables([User, State, City, Place, PlaceBook])
'''Create table items for ForeignKeyField requirements.'''
self.app.post('/users', data=dict(
first_name="test",
last_name="test",
email="test",
password="test"
))
self.app.post('/states', data=dict(
name="test"
))
self.app.post('/states/1/cities', data=dict(
name="test",
state=1
))
self.app.post('/places', data=dict(
owner=1,
city=1,
name="test",
description="test",
latitude=0,
longitude=0
))
def setUp(self):
'''Creates a test client, disables logging, connects to the database
and creates a table State for temporary testing purposes.
'''
self.app = app.test_client()
logging.disable(logging.CRITICAL)
BaseModel.database.connect()
BaseModel.database.create_tables([State])
def setUp(self):
'''Creates a test client, disables logging, connects to the database
and creates state and city tables for temporary testing purposes.
'''
self.app = app.test_client()
logging.disable(logging.CRITICAL)
BaseModel.database.connect()
BaseModel.database.create_tables([User, City, Place, State, PlaceBook])
'''Create items in tables for ForeignKeyField requirements'''
self.app.post('/states', data=dict(name="test"))
self.app.post('/states/1/cities', data=dict(
name="test",
state=1
))
self.app.post('/users', data=dict(
first_name="test",
last_name="test",
email="test",
password="test"
))
'''Create two places.'''
for i in range(1, 3):
self.create_place('/places', 'test_' + str(i))
'''Create a book on place 1, belonging to user 1.'''
self.app.post('/places/1/books', data=dict(
place=1,
user=1,
date_start="2000/1/1 00:00:00",
description="test",
number_nights=10,
latitude=0,
longitude=0
))
def setUp(self):
'''Creates a test client, disables logging, connects to the database
and creates state and city tables for temporary testing purposes.
'''
self.app = app.test_client()
logging.disable(logging.CRITICAL)
BaseModel.database.connect()
BaseModel.database.create_tables([State, City])
'''Create a state for routing purposes.'''
self.app.post('/states', data=dict(name="test"))
'''Create two new cities.'''
for i in range(1, 3):
res = self.create_city("test_" + str(i))
def setUp(self):
'''Creates a test client and propagates the exceptions to the test
client.
'''
self.app = app.test_client()
self.app.testing = True
def setUp(self):
'''Creates a test client, disables logging, connects to the database
and creates a table User for temporary testing purposes.
'''
self.app = app.test_client()
logging.disable(logging.CRITICAL)
BaseModel.database.connect()
BaseModel.database.create_tables([User, Place, Review, ReviewPlace,
ReviewUser, City, State])
'''Add two new users.'''
for i in range(1, 3):
self.app.post('/users', data=dict(first_name="user_" + str(i),
last_name="user_" + str(i),
email="user_" + str(i),
password="user_" + str(i)))
'''Add a state.'''
self.app.post('/states', data=dict(name="state_1"))
'''Add a city.'''
self.app.post('/states/1/cities', data=dict(name="city_1", state=1))
'''Add a place.'''
self.app.post('/places', data=dict(owner=1, city=1, name="place_1",
description="place_1", latitude=0,
longitude=0))
def setUp(self):
'''Creates a test client, disables logging, connects to the database
and creates a table User for temporary testing purposes.
'''
self.app = app.test_client()
logging.disable(logging.CRITICAL)
BaseModel.database.connect()
BaseModel.database.create_tables([User])
def setUp(self):
app.config['TESTING'] = True
app.config['DEBUG'] = True
self.client = app.test_client()
super(TestCaseWeb, self).setUp()
def test_api(self):
tester=app.test_client(self)
response = tester.get('/', content_type='application/json')
self.assertEqual(response.status_code,200)
def setUp(self):
self.app = app
self.app.config.from_object('app.config')
self.app.config["NO_PASSWORD"] = False
self.app.config["DEBUG"] = True
self.app.config["TESTING"] = True
self.app = app.test_client()
db.create_all()
def setUp(self):
self.app = app.test_client()
test_all_users_listing.py 文件源码
项目:Cycling_admin
作者: Social-projects-Rivne
项目源码
文件源码
阅读 19
收藏 0
点赞 0
评论 0
def test_controller_with_empty_db(self, db):
"""
Imitate situation when there is no any user available in the db and
sqlalchemy output becomes an empty list []. Message 'There are no
users in the database' instead of users table is expected as default
behavior in this case.
"""
db.session.query.return_value.all.return_value = []
with app.test_client() as test_client:
responce = test_client.get('/users/all')
data = responce.data
self.assertIn('There are no users in the database.', data)
test_all_users_listing.py 文件源码
项目:Cycling_admin
作者: Social-projects-Rivne
项目源码
文件源码
阅读 23
收藏 0
点赞 0
评论 0
def test_unavailable_db(self):
"""
Check if "Can not access database" message appears if db is
unavailable.
"""
#break db uri to call exception inside controller
app.config['SQLALCHEMY_DATABASE_URI'] = ''
with app.test_client() as test_client:
responce = test_client.get('/users/all')
data = responce.data
self.assertIn("Can not access database.", data)
self.assertNotIn('<table class="table">', data)
def setUp(self):
# creates a test client
self.app = app.test_client()
# propagate the exceptions to the test client
self.app.testing = True
def setUp(self):
# creates a test client
self.app = app.test_client()
# propagate the exceptions to the test client
self.app.testing = True
def setUp(self):
# creates a test client
self.app = app.test_client()
# propagate the exceptions to the test client
self.app.testing = True
def setUp(self):
app.config['TESTING'] = True
app.config['WTF_CSRF_ENABLED'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'test.db')
self.app = app.test_client()
db.create_all()
def test_index(self):
"""initial test. ensure flask was set up correctly"""
tester = app.test_client(self)
response = tester.get('/', content_type='html/text')
self.assertEqual(response.status_code, 200)
def setUp(self):
"""Set up a blank temp database before each test"""
basedir = os.path.abspath(os.path.dirname(__file__))
app.config['TESTING'] = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
os.path.join(basedir, TEST_DB)
self.app = app.test_client()
db.create_all()
def setUp(self):
# Necessary to disable SSLify
app.debug = True
self.test_app = app.test_client()
self.session = app.requests_session
def test_health_endpoint(self):
"""Assert that the health endpoint works."""
response = app.test_client().get('/health')
self.assertEquals(response.data, ';-)')
def test_root_endpoint(self):
"""Assert that the / endpoint correctly redirects to login.uber.com."""
response = app.test_client().get('/')
self.assertIn('login.uber.com', response.data)
def test_submit_endpoint_failure(self):
"""Assert that the submit endpoint returns no code in the response."""
with app.test_client() as client:
with client.session_transaction() as session:
session['access_token'] = test_auth_token
with Betamax(app.requests_session).use_cassette('submit_failure'):
response = client.get('/submit?code=not_a_code')
self.assertIn('None', response.data)