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_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)
Пример #5
0
 def test_event_copy(self):
     with app.test_request_context():
         event = ObjectMother.get_event()
         register(self.app, u'*****@*****.**', u'test2')
         login(self.app, '*****@*****.**', 'test2')
         save_to_db(event, "Event saved")
         url = url_for('events.copy_event', event_id=event.id)
         rv = self.app.get(url, follow_redirects=True)
         self.assertTrue("Copy of event1" in rv.data, msg=rv.data)
 def test_event_copy(self):
     with app.test_request_context():
         event = ObjectMother.get_event()
         register(self.app, u'*****@*****.**', u'test2')
         login(self.app, '*****@*****.**', 'test2')
         save_to_db(event, "Event saved")
         url = url_for('events.copy_event', event_id=event.id)
         rv = self.app.get(url, follow_redirects=True)
         self.assertTrue("Copy of event1" in rv.data, msg=rv.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', '*****@*****.**', 'test')
         login(self.app, 'test', 'test')
         self.assertTrue('Create New 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)
Пример #8
0
 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_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_event_publish(self):
     with app.test_request_context():
         event = ObjectMother.get_event()
         register(self.app, u'*****@*****.**', u'test2')
         login(self.app, '*****@*****.**', 'test2')
         save_to_db(event, "Event saved")
         url = url_for('events.publish_event', event_id=event.id)
         rv = self.app.get(url, follow_redirects=True)
         event = DataGetter.get_event(event.id)
         self.assertEqual("Published", event.state, msg=event.state)
Пример #11
0
 def test_event_publish(self):
     with app.test_request_context():
         event = ObjectMother.get_event()
         register(self.app, u'*****@*****.**', u'test2')
         login(self.app, '*****@*****.**', 'test2')
         save_to_db(event, "Event saved")
         url = url_for('events.publish_event', event_id=event.id)
         rv = self.app.get(url, follow_redirects=True)
         event = DataGetter.get_event(event.id)
         self.assertEqual("Published", event.state, msg=event.state)
 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_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_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)
Пример #17
0
 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)
Пример #18
0
 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)
Пример #19
0
 def test_logout(self):
     login(self.app, '*****@*****.**', 'test')
     rv = logout(self.app)
     self.assertTrue("Login" in rv.data)
 def login(self):
     register(self.app, u'*****@*****.**', u'test2')
     login(self.app, '*****@*****.**', 'test2')
Пример #21
0
 def test_correct_login(self):
     register(self.app, 'test', '*****@*****.**', 'test')
     logout(self.app)
     rv = login(self.app, 'test', 'test')
     self.assertTrue("Create New Event" 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")
Пример #23
0
 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')
Пример #25
0
 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)
Пример #26
0
 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)
Пример #27
0
 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 test_login(self):
     register(self.app, "test", "*****@*****.**", "test")
     logout(self.app)
     rv = login(self.app, "test", "test")
     self.assertTrue("The FOSSASIA Open Event" in rv.data)
Пример #29
0
 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)
Пример #30
0
 def test_logout(self):
     login(self.app, 'test', 'test')
     rv = logout(self.app)
     self.assertTrue("Login" in rv.data)
Пример #31
0
 def test_login(self):
     register(self.app,'test', '*****@*****.**', 'test')
     logout(self.app)
     rv = login(self.app, 'test', 'test')
     self.assertTrue("The FOSSASIA Open Event" in rv.data)
Пример #32
0
 def test_incorrect_login(self):
     register(self.app, 'test', '*****@*****.**', 'test')
     logout(self.app)
     rv = login(self.app, 'other_test', 'other_test')
     self.assertTrue("Login Form" in rv.data)
 def _login_user(self):
     """
     Registers an email and logs in.
     """
     with app.test_request_context():
         login(self.app, u'*****@*****.**', u'test')
Пример #34
0
 def login(self):
     register(self.app, u'*****@*****.**', u'test2')
     login(self.app, '*****@*****.**', 'test2')