def setUp(self): self.app = application.test_client() self.app.testing = True user = {'phone_num': '13333333333', 'password': '******'} self.app.post(LOGIN_URL, data=json.dumps(user), content_type='application/json')
def setUp(self): """Initialization for the test cases This is executed prior to each test. """ application.config['TESTING'] = True application.config['WTF_CSRF_ENABLED'] = False application.config['DEBUG'] = False self.app = application.test_client() # setup plaid client self.client = Client(ENV_VARS["PLAID_CLIENT_ID"], ENV_VARS["PLAID_SECRET"], ENV_VARS["PLAID_PUBLIC_KEY"], "sandbox") self.public_token = sandbox.PublicToken(self.client) db.drop_all() db.create_all() # Create a test user and test plaid item self.test_user = classes.User(first_name="first", last_name="last", email="*****@*****.**", phone="9876543210", password="******") db.session.add(self.test_user) db.session.commit() self.test_item = classes.PlaidItems(user=self.test_user, item_id="item", access_token="token") db.session.add(self.test_item) db.session.commit()
def test_video(walk): walk.return_value = (('/some/path/2013.03.05', [], ['video.mp4']), ('/some/path/2009.08.01', [], ['video_0.mp4', 'video_2.mp4']), ('/some/path/2014.12.25', [], ['video.mp4'])) settings.VIDEO_FILES_PATH = '/some/path' settings.VIDEO_FILES_LOCATION = '/static/video' settings.THUMBNAIL_FILES_LOCATION = '/thumbnails/video' client = application.test_client() resp = client.get('/api/video/') walk.assert_called_with('/some/path') assert resp.status_code == 200 assert resp.mimetype == 'application/json' expected = [{ 'date': '2014.12.25', 'url': 'http://localhost/static/video/2014.12.25/video.mp4', 'thumbnail': 'http://localhost/thumbnails/video/2014.12.25/video.png' }, { 'date': '2013.03.05', 'url': 'http://localhost/static/video/2013.03.05/video.mp4', 'thumbnail': 'http://localhost/thumbnails/video/2013.03.05/video.png' }, { 'date': '2009.08.01', 'url': 'http://localhost/static/video/2009.08.01/video_0.mp4', 'thumbnail': 'http://localhost/thumbnails/video/2009.08.01/video_0.png' }, { 'date': '2009.08.01', 'url': 'http://localhost/static/video/2009.08.01/video_2.mp4', 'thumbnail': 'http://localhost/thumbnails/video/2009.08.01/video_2.png' }] assert json.dumps(expected) == resp.data
def client(): _init_flask_app(application, "config.TestConfiguration") ctx = application.app_context() ctx.push() with application.test_client() as client: yield client
def setUp(self): application.config['RUN_MODE'] = 'test' application.config.from_object('app.config.test.Config') self.app = application.test_client(self) self.app_context = application.app_context() self.app_context.push()
def setUp(self): application.config['TESTING'] = True application.config['WTF_CSRF_ENABLED'] = False application.config[ 'SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/result_aggregation_test.db' self.application = application.test_client() db.create_all()
def test_icorrect_login(self): tester = application.test_client(self) response = tester.post( '/login', data=dict(username="******", password="******"), follow_redirects = True ) self.assertIn(b'Invalid credentials. Please try again.' ,response.data)
def test_correct_login(self): tester = application.test_client(self) response = tester.post( '/login', data=dict(username="******", password="******"), follow_redirects = True ) self.assertIn(b'Successfully logged in.' ,response.data)
def test_client(): test_client = application.test_client() ctx = application.app_context() ctx.push() yield test_client ctx.pop()
def setUp(self): application.config['RUN_MODE'] = 'test' application.config.from_object('app.config.test.Config') db.session.close() db.drop_all() db.create_all() self.app = application.test_client(self) self.app_context = application.app_context() self.app_context.push()
def setUp(self): """Initialization for the test cases This is executed prior to each test. """ application.config['TESTING'] = True application.config['WTF_CSRF_ENABLED'] = False application.config['DEBUG'] = False self.app = application.test_client() db.drop_all() db.create_all()
def setUp(self): # self.db, application.config['DATABASE'] = tempfile.mkstemp() application.config.from_pyfile('config/test.cfg') application.config['TESTING'] = True self.client = application.test_client() self.db = db self.db.create_all() self.auth = Auth.create( email="*****@*****.**", password='******', token='SUmnfqii5wcuJz8WZrWJw66AsE9', )
def setUp(self): app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \ os.path.join(PROJECT_DIR, TEST_DB) self.app = app.test_client() db.drop_all() db.create_all() self.assertEqual(app.debug, False)
def setUp(self, populate=True): # Load testing configuration application.config.from_object('config.TestingConfig') self.app = application.test_client() db.create_all() # Initialize the request context self.context = application.test_request_context() self.context.push() # load data if (populate): self.populate()
def setUp(self): # application.config.from_pyfile('config/test.cfg') application.config['TESTING'] = True self.client = application.test_client() self.db = db gen_time = datetime.datetime.now() dummy_id = ObjectId.from_datetime(gen_time) self.post = Post.create( id=dummy_id, title='chao buoi sang', content='day la mini project de demo ve microservice', tags=['microservice', 'python', 'docker'], account_id='1')
def setUp(self): # Creates a test client application.config['TESTING'] = True application.config['WTF_CSRF_ENABLED'] = False application.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://*****:*****@10.1.144.91/OpenSourceEngDB' application.config['SQLALCHEMY_ECHO'] = True self.app = application.test_client() self.app.testing = True # Add dummy data to test. db.create_all() db.session.add(Roles("*****@*****.**","letmein")) db.session.add(ChatRoom(3122,None,31,22)) db.session.commit()
def setUp(self): # self.db, application.config['DATABASE'] = tempfile.mkstemp() application.config.from_pyfile('config/test.cfg') application.config['TESTING'] = True self.client = application.test_client() self.db = db self.db.create_all() self.user = User.create( first_name="cong", last_name="quan", password='******', email='*****@*****.**', role=UserRole.MEMBER, )
def client(): from app import application db_fixture = DatabaseFixture(application) with application.app_context(): application.config.from_object('settings.test_settings') db_fixture.connect_db() client = application.test_client() yield client db_fixture.delete_db()
def setUp(self): app.config["TEST_DBNAME"] = "ui_test" try: app.mongo = PyMongo(app, config_prefix="TEST") except: pass self.client = app.test_client() num_trees, height = (5, 5) self.row = pb.TrainingRow( forestConfig=fake_data.fake_config(num_trees), forest=fake_data.fake_forest(height, num_trees) ) with app.test_request_context(): self._id = str(app.mongo.db.decisiontrees.insert(protobuf_to_dict(self.row)))
def test_message_handler_with_unauthorized_access(self, db, role_service): self.mock_patched_values_with_null(db, role_service) with app.test_client() as client: # Arrange client.application.cache = Cache() sent = self._create_webhook_payload( self.valid_phone, 'placeholder text because I\'m unauthorized to see this') expected = AWSUnauthorized().message # Act result = client.post('/receive-events', data=sent) result_payload = result.data.decode("utf-8") # assert self.assertEqual(expected, json.loads(result_payload)['body'])
def test_sqs_message_handler_with_no_queue_returns_missing_resource( self, db, role_service): self._setup_mock_values(db, role_service) with app.test_client() as client: # Arrange client.application.cache = Cache() sent = self._create_webhook_payload(self.valid_phone, 'sqs size') expected = AWSResourceMissing('sqs').message # Act result = client.post('/receive-events', data=sent) result_payload = result.data.decode("utf-8") # assert self.assertEqual(expected, json.loads(result_payload)['body'])
def setUp(self): app.config['TEST_DBNAME'] = 'ui_test' try: app.mongo = PyMongo(app, config_prefix='TEST') except: pass self.client = app.test_client() num_trees, height = (5, 5) self.row = pb.TrainingRow( forestConfig=fake_data.fake_config(num_trees), forest=fake_data.fake_forest(height, num_trees), ) with app.test_request_context(): self._id = str( app.mongo.db.decisiontrees.insert(protobuf_to_dict(self.row)))
def test_kinesis_message_handler_without_name_returns_resource_message( self, db, role_service): self._setup_mock_values(db, role_service) with app.test_client() as client: # Arrange client.application.cache = Cache() self._create_and_populate_test_stream(self.stream_name, 123) sent = self._create_webhook_payload( self.valid_phone, 'what is the kinesis stream encryption type') expected = AWSResourceMissing('kinesis').message # Act result = client.post('/receive-events', data=sent) result_payload = result.data.decode("utf-8") # assert self.assertEqual(expected, json.loads(result_payload)['body'])
def setUp(self): """Initialization for the test cases This is executed prior to each test. """ application.config['TESTING'] = True application.config['WTF_CSRF_ENABLED'] = False application.config['DEBUG'] = False self.app = application.test_client() # setup plaid client self.client = Client( ENV_VARS["PLAID_CLIENT_ID"], ENV_VARS["PLAID_SECRET"], ENV_VARS["PLAID_PUBLIC_KEY"], "sandbox" ) self.public_token = sandbox.PublicToken(self.client) db.drop_all() db.create_all()
def test_kinesis_message_handler_with_no_intent_returns_missing_resource( self, db, role_service): self._setup_mock_values(db, role_service) with app.test_client() as client: # Arrange client.application.cache = Cache() self._create_and_populate_test_stream(self.stream_name, 123) sent = self._create_webhook_payload( self.valid_phone, 'what is the kinesis stream test_kinesis_stream blaaah') expected = AWSInvalidCommand( 'kinesis', set(KinesisHandler.intents.keys())).message # Act result = client.post('/receive-events', data=sent) result_payload = result.data.decode("utf-8") # assert self.assertEqual(expected, json.loads(result_payload)['body'])
def test_sqs_message_handler_with_size_message_returns_size_metadata( self, db, role_service): self._setup_mock_values(db, role_service) with app.test_client() as client: # Arrange client.application.cache = Cache() self._create_and_populate_test_queue(self.test_queue_name) sent = self._create_webhook_payload(self.valid_phone, 'sqs size test_sqs_queue') expected = SQSAttributeHandler( 'ApproximateNumberOfMessages').handle_response( self.test_queue_name, 0) # Act result = client.post('/receive-events', data=sent) result_payload = result.data.decode("utf-8") # assert self.assertEqual(expected, json.loads(result_payload)['body'])
def test_kinesis_message_handler_with_encryption_type_message_returns_size_metadata( self, db, role_service): self._setup_mock_values(db, role_service) with app.test_client() as client: # Arrange client.application.cache = Cache() self._create_and_populate_test_stream(self.stream_name, 123) sent = self._create_webhook_payload( self.valid_phone, 'what is the kinesis stream test_kinesis_stream encryption type' ) expected = KinesisAttributeHandler( 'EncryptionType').handle_response(self.stream_name, 'None') # Act result = client.post('/receive-events', data=sent) result_payload = result.data.decode("utf-8") # assert self.assertEqual(expected, json.loads(result_payload)['body'])
def test_dynamo_message_handler_with_count_type_message_returns_count(self, db, role_service): self._setup_mock_values(db, role_service) with app.test_client() as client: # Arrange client.application.cache = Cache() self._create_test_table(self.table_name) sent = self._create_webhook_payload( self.valid_phone, 'what is the dynamodb test_dynamo_table count' ) expected = DynamoTableAttributeHandler('ItemCount').handle_response(self.table_name, '0') # Act result = client.post( '/receive-events', data=sent ) result_payload = result.data.decode("utf-8") # assert self.assertEqual(expected, json.loads(result_payload)['body'])
def setUp(self): self.app = application.test_client()
def test_route_api_networks_returns_list(self): test_client = application.test_client() n = test_client.get('/api/networks/') data = json.loads(n.data.decode('utf8')) self.assertEqual(type(data), list)
def test_if_returns_code_200(self): test_client = application.test_client() n = test_client.get('/api/countries/') self.assertEqual(n.status_code, 200)
def test_login_page_loads(self): tester = application.test_client(self) response = tester.get('/login', content_type='html/text') self.assertTrue(b'Login' in response.data)
def setUp(self): application.config['TESTING'] = True application.config['WTF_CSRF_ENABLED'] = False application.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/result_aggregation_test.db' self.application = application.test_client() db.create_all()
def test_index(self): tester = application.test_client(self) response = tester.get('/login', content_type='html/text') self.assertEqual(response.status_code, 200)
def setUp(self): # creates a test client self.client = app.test_client() # propagate the exceptions to the test client self.client.testing = True
def test_dashboard_route_requires_login(self): tester = application.test_client(self) response = tester.get('/dashBoard', follow_redirects = True) self.assertTrue(b'Please login first.' in response.data)
def setUp(self): application.config['TESTING'] = True self.application = application.test_client()
def setUp(self) -> None: self.app = application.test_client() self.db = db.get_db()
def before_all(context): context.thread = threading.Thread(target=application.test_client()) context.thread.start() context.browser = webdriver.Chrome()
def setUp(self): application.config['TESTING'] = True application.config['WTF_CSRF_ENABLED'] = False application.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql+psycopg2://dhineshns:raga51am@localhost/reretailer' self.application = application.test_client() db.create_all()
import unittest import sys sys.path.append("../") from app import application, db from app.models import * import itertools import operator from app import redis test_app = application.test_client() def auth_token_helper(username): response = test_app.post( '/owner_login', data=dict( username=username, password='******') ) headers = {'Authorization': 'Bearer {}'.format(response.get_json()['access_token'])} return headers class unittestNewspaper(unittest.TestCase): """ Runs unit tests on all routes in newspaper.py blueprint """ def test_login_correct_password(self): """ log into existing profile """ owner = Owner.query.all()[1] username = owner.username
def test_route_api_networks_returns_code_200(self): test_client = application.test_client() n = test_client.get('/api/networks/') self.assertEqual(n.status_code, 200)