def _test_path(self, path, *strings): """Helper function. Test response for 200 status code. Also test if response body contains event/service name. """ with app.test_request_context(): login(self.app, u'*****@*****.**', u'test') response = self.app.get(path, follow_redirects=True) # Check GET APIs normally self.assertEqual(response.status_code, 200) for string in strings: self.assertIn(string, response.data) headers_keys = [key.lower() for key in response.headers.keys()] # Check if ETag header was returned self.assertIn('etag', headers_keys) # Check if ETag value is not empty etag = response.headers.get('etag') self.assertNotEqual(etag, '') # Send new request with If-None-Match header set response = self.app.get(path, headers={'If-None-Match': etag}, follow_redirects=True) # Check if response was 304 Not Modified self.assertEqual(response.status_code, 304) self.assertEqual(response.data, '')
def _test_model(self, name): """ Tests - 1. When just one item, check if next and prev urls are empty 2. When one more item added, limit results to 1 and see if next is not empty 3. start from position 2 and see if prev is not empty """ login(self.app, u'*****@*****.**', u'test') if name == 'event': path = get_path('page') else: path = get_path(1, name + 's', 'page') data = self._json_from_url(path) self.assertEqual(data['next'], '') self.assertEqual(data['previous'], '') # add second service with app.test_request_context(): create_event(name='TestEvent2') create_services(1) data = self._json_from_url(path + '?limit=1') self.assertIn('start=2', data['next']) self.assertEqual(data['previous'], '') # check from start=2 data = self._json_from_url(path + '?start=2') self.assertIn('limit=1', data['previous']) self.assertEqual(data['next'], '') self.assertIn('http', data['previous']) # check absolute link
def _test_model(self, name): """ Tests - 1. When just one item, check if next and prev urls are empty 2. When one more item added, limit results to 1 and see if next is not empty 3. start from position 2 and see if prev is not empty """ login(self.app, u'*****@*****.**', u'test') if name == 'event': path = get_path('page') else: path = get_path(1, name + 's', 'page') data = self._json_from_url(path) self.assertEqual(data['next'], '') self.assertEqual(data['previous'], '') # add second service with app.test_request_context(): create_event(name='TestEvent2') create_services(1) data = self._json_from_url(path + '?limit=1') self.assertIn('start=2', data['next']) self.assertEqual(data['previous'], '') # check from start=2 data = self._json_from_url(path + '?start=2') self.assertIn('limit=1', data['previous']) self.assertEqual(data['next'], '') self.assertIn('http', data['previous']) # check absolute link
def test_admin_dashboard_attempt(self): with app.test_request_context(): logout(self.app) register(self.app, "*****@*****.**", "SomeRandomPassword") login(self.app, "*****@*****.**", "SomeRandomPassword") rv = self.app.get(url_for('sadmin.index_view'), follow_redirects=True) self.assertEqual(rv.status_code, 403)
def _test_path(self, path, *strings): """Helper function. Test response for 200 status code. Also test if response body contains event/service name. """ with app.test_request_context(): login(self.app, u'*****@*****.**', u'test') response = self.app.get(path, follow_redirects=True) # Check GET APIs normally self.assertEqual(response.status_code, 200) for string in strings: self.assertIn(string, response.data) headers_keys = [key.lower() for key in response.headers.keys()] # Check if ETag header was returned self.assertIn('etag', headers_keys) # Check if ETag value is not empty etag = response.headers.get('etag') self.assertNotEqual(etag, '') # Send new request with If-None-Match header set response = self.app.get(path, headers={'If-None-Match': etag}, follow_redirects=True) # Check if response was 304 Not Modified self.assertEqual(response.status_code, 304) self.assertEqual(response.data, '')
def test_admin_dashboard_attempt(self): with app.test_request_context(): logout(self.app) register(self.app, "*****@*****.**", "SomeRandomPassword") login(self.app, "*****@*****.**", "SomeRandomPassword") rv = self.app.get(url_for('sadmin.index_view'), follow_redirects=True) self.assertEqual(rv.status_code, 403)
def _test_path(self, path): """Test response for 400 status code. Also test if response body contains 'does not belong to event' string. """ with app.test_request_context(): login(self.app, u'*****@*****.**', u'test') response = self.app.get(path) self.assertEqual(response.status_code, 400) self.assertIn('does not belong to event', response.data)
def _test_path(self, path): """Test response for 400 status code. Also test if response body contains 'does not belong to event' string. """ with app.test_request_context(): login(self.app, u'*****@*****.**', u'test') response = self.app.get(path) self.assertEqual(response.status_code, 400) self.assertIn('does not belong to event', response.data)
def test_user_already_logged_in(self): """If the user is already logged in then on clicking 'Login with Google' he should be redirected directly to the admin page""" with app.test_request_context(): register(self.app, '*****@*****.**', 'test') logout(self.app) login(self.app, '*****@*****.**', 'test') self.assertTrue('Open Event' in self.app.get('/gCallback/?state=dummy_state&code=dummy_code', follow_redirects=True).data) self.assertEqual(self.app.get('/gCallback/?state=dummy_state&code=dummy_code').status_code, 302)
def test_api(self): login(self.app, u'*****@*****.**', u'test') path = get_path('page') response = self.app.get(path) self.assertEqual(response.status_code, 404, msg=response.data) with app.test_request_context(): create_event() response = self.app.get(path) self.assertEqual(response.status_code, 200) self.assertIn('TestEvent', response.data)
def test_api(self): login(self.app, u'*****@*****.**', u'test') path = get_path('page') response = self.app.get(path) self.assertEqual(response.status_code, 404, msg=response.data) with app.test_request_context(): create_event() response = self.app.get(path) self.assertEqual(response.status_code, 200) self.assertIn('TestEvent', response.data)
def _test_path(self, path): """Helper function. Test response for 404 status code. Also test if response body contains 'does no exist' string. """ with app.test_request_context(): login(self.app, u'*****@*****.**', u'test') response = self.app.get(path) self.assertEqual(response.status_code, 404) self.assertIn('does not exist', response.data)
def test_user_already_logged_in(self): """If the user is already logged in then on clicking 'Login with Facebook' he should be redirected directly to the admin page""" with app.test_request_context(): register(self.app, '*****@*****.**', 'test') logout(self.app) login(self.app, '*****@*****.**', 'test') self.assertTrue('Open Event' in self.app.get('/fCallback/?code=dummy_code&state=dummy_state', follow_redirects=True).data) self.assertEqual(self.app.get('/fCallback/?code=dummy_code&state=dummy_state').status_code, 302)
def _test_path(self, path, service1, service2): """Helper function. Test response for 200 status code. Also test if response body contains event/service name. """ with app.test_request_context(): login(self.app, u'*****@*****.**', u'test') response = self.app.get(path, follow_redirects=True) self.assertEqual(response.status_code, 200) self.assertIn(service1, response.data) self.assertIn(service2, response.data)
def test_event_api(self): self.app = Setup.create_app() with app.test_request_context(): register(self.app, u'*****@*****.**', u'test') login(self.app, u'*****@*****.**', u'test') # Non existing event event_id = 1 path = get_path(event_id) response = self.app.get(path) self.assertEqual(response.status_code, 404) self.assertIn('does not exist', response.data)
def test_user_already_logged_in(self): """If the user is already logged in then on clicking 'Login with Google' he should be redirected directly to the admin page""" with app.test_request_context(): register(self.app, '*****@*****.**', 'test') logout(self.app) login(self.app, '*****@*****.**', 'test') with HTTMock(google_auth_mock, google_profile_mock): self.assertTrue('Open Event' in self.app.get('/gCallback/?state=dummy_state&code=dummy_code', follow_redirects=True).data) self.assertEqual(self.app.get('/gCallback/?state=dummy_state&code=dummy_code').status_code, 302)
def _test_path(self, path, service1, service2): """Helper function. Test response for 200 status code. Also test if response body contains event/service name. """ with app.test_request_context(): login(self.app, u'*****@*****.**', u'test') response = self.app.get(path, follow_redirects=True) self.assertEqual(response.status_code, 200) self.assertIn(service1, response.data) self.assertIn(service2, response.data)
def test_event_queries(self): with app.test_request_context(): login(self.app, u'*****@*****.**', u'test') path = get_path() resp = self._post(path, POST_EVENT_DATA) # check no return resp = self.app.get(path + '?state=r@nd0m') self.assertEqual(len(resp.data), 3, msg=resp.data) # check case-insensitive search resp = self.app.get(path + '?contains=test') self.assertEqual(resp.status_code, 200) self.assertEqual(len(json.loads(resp.data)), 2) # check queryset forwarding resp = self.app.get(path + '?contains=test&state=r@nd0m') self.assertEqual(len(resp.data), 3)
def test_event_queries(self): with app.test_request_context(): login(self.app, u'*****@*****.**', u'test') path = get_path() resp = self._post(path, POST_EVENT_DATA) # check no return resp = self.app.get(path + '?state=r@nd0m') self.assertEqual(len(resp.data), 3, msg=resp.data) # check case-insensitive search resp = self.app.get(path + '?contains=test') self.assertEqual(resp.status_code, 200) self.assertEqual(len(json.loads(resp.data)), 2) # check queryset forwarding resp = self.app.get(path + '?contains=test&state=r@nd0m') self.assertEqual(len(resp.data), 3)
def _test_model(self, name): """ Tests the 404 response, then add item and test the success response """ login(self.app, u'*****@*****.**', u'test') path = get_path(1, name + 's', 'page') response = self.app.get(path, follow_redirects=True) # check for 404 in no data self.assertEqual(response.status_code, 404) # add single data with app.test_request_context(): create_services(1) response = self.app.get(path, follow_redirects=True) self.assertEqual(response.status_code, 200) self.assertIn('Test' + str(name).title(), response.data)
def _test_model(self, name): """ Tests the 404 response, then add item and test the success response """ login(self.app, u'*****@*****.**', u'test') path = get_path(1, name + 's', 'page') response = self.app.get(path, follow_redirects=True) # check for 404 in no data self.assertEqual(response.status_code, 404) # add single data with app.test_request_context(): create_services(1) response = self.app.get(path, follow_redirects=True) self.assertEqual(response.status_code, 200) self.assertIn('Test' + str(name).title(), response.data)
def test_event_time_queries(self): with app.test_request_context(): login(self.app, u'*****@*****.**', u'test') path = get_path() # Event is of Apr 16 resp = self.app.get(path + '?end_time_lt=2015-12-31T23:59:59') self.assertEqual(len(resp.data), 3, msg=resp.data) resp = self.app.get(path + '?start_time_gt=2015-12-31T23:59:59') self.assertIn('TestEvent0', resp.data) # add one more event of May 16 resp = self._post(path, POST_EVENT_DATA) # test resp = self.app.get(path + '?start_time_lt=2016-05-31T23:59:59') self.assertEqual(len(json.loads(resp.data)), 2, msg=resp.data) resp = self.app.get(path + '?end_time_gt=2016-05-01T00:00:00') self.assertIn('"TestEvent"', resp.data) self.assertNotIn('TestEvent0', resp.data)
def test_event_time_queries(self): with app.test_request_context(): login(self.app, u'*****@*****.**', u'test') path = get_path() # Event is of Apr 16 resp = self.app.get(path + '?end_time_lt=2015-12-31T23:59:59') self.assertEqual(len(resp.data), 3, msg=resp.data) resp = self.app.get(path + '?start_time_gt=2015-12-31T23:59:59') self.assertIn('TestEvent0', resp.data) # add one more event of May 16 resp = self._post(path, POST_EVENT_DATA) # test resp = self.app.get(path + '?start_time_lt=2016-05-31T23:59:59') self.assertEqual(len(json.loads(resp.data)), 2, msg=resp.data) resp = self.app.get(path + '?end_time_gt=2016-05-01T00:00:00') self.assertIn('"TestEvent"', resp.data) self.assertNotIn('TestEvent0', resp.data)
def test_event_location_queries(self): with app.test_request_context(): login(self.app, u'*****@*****.**', u'test') path = get_path() resp = self._post(path, POST_EVENT_DATA) # check location smart queries resp = self.app.get(path + '?location=SomeBuilding,Berlin') self.assertIn('Berlin', resp.data) # add another event data = POST_EVENT_DATA.copy() data['location_name'] = 'SomeBuilding' data['searchable_location_name'] = 'SomeBuilding' self._post(path, data) # get resp = self.app.get(path + '?location=SomeBuilding,Berlin') self.assertEqual(resp.status_code, 200) self.assertIn('SomeBuilding', resp.data) self.assertIn('Berlin', resp.data)
def test_event_location_queries(self): with app.test_request_context(): login(self.app, u'*****@*****.**', u'test') path = get_path() resp = self._post(path, POST_EVENT_DATA) # check location smart queries resp = self.app.get(path + '?location=SomeBuilding,Berlin') self.assertIn('Berlin', resp.data) # add another event data = POST_EVENT_DATA.copy() data['location_name'] = 'SomeBuilding' data['searchable_location_name'] = 'SomeBuilding' self._post(path, data) # get resp = self.app.get(path + '?location=SomeBuilding,Berlin') self.assertEqual(resp.status_code, 200) self.assertIn('SomeBuilding', resp.data) self.assertIn('Berlin', resp.data)
def _login_user(self): """ Registers an email and logs in. """ with app.test_request_context(): login(self.app, u'*****@*****.**', u'test')
def _login_user(self): with app.test_request_context(): login(self.app, '*****@*****.**', 'test')
def test_incorrect_login(self): with app.test_request_context(): register(self.app, u'*****@*****.**', u'test') logout(self.app) rv = login(self.app, '*****@*****.**', 'other_test') self.assertTrue("Login Form" in rv.data)
def setUp(self): self.app = Setup.create_app() with app.test_request_context(): self.super_admin = get_or_create_super_admin() login(self.app, "*****@*****.**", "test_super_admin")
def test_logout(self): with app.test_request_context(): register(self.app, u'*****@*****.**', u'test') login(self.app, '*****@*****.**', 'test') rv = logout(self.app) self.assertTrue("Login" in rv.data)
def _login_user(self): """ Registers an email and logs in. """ with app.test_request_context(): login(self.app, u'*****@*****.**', u'test')
def setUp(self): self.app = Setup.create_app() with app.test_request_context(): self.super_admin = get_or_create_super_admin() login(self.app, "*****@*****.**", "test_super_admin")
def _login_user(self): with app.test_request_context(): login(self.app, '*****@*****.**', 'test')
def test_correct_login(self): with app.test_request_context(): register(self.app, u'*****@*****.**', u'test') logout(self.app) rv = login(self.app, '*****@*****.**', 'test') self.assertTrue("Open Event" in rv.data, msg=rv.data)