From 3c32fb5c524d3d6c83cb16c1f7f053d2ea498dff Mon Sep 17 00:00:00 2001 From: Rishav Chakraborty Date: Thu, 8 Nov 2018 20:39:06 +0530 Subject: [PATCH 01/11] Replaced testapp.get with appropriate functions --- core/controllers/admin_test.py | 26 +++--- core/controllers/base_test.py | 33 ++++--- core/controllers/collection_editor_test.py | 22 ++--- core/controllers/collection_viewer_test.py | 20 ++--- core/controllers/concept_card_viewer_test.py | 4 +- core/controllers/creator_dashboard_test.py | 13 +-- core/controllers/editor_test.py | 87 ++++++++++--------- core/controllers/email_dashboard_test.py | 42 ++++----- core/controllers/feedback_test.py | 24 ++--- core/controllers/learner_dashboard_test.py | 2 +- core/controllers/learner_playlist_test.py | 4 +- core/controllers/library_test.py | 6 +- core/controllers/moderator_test.py | 12 +-- core/controllers/pages_test.py | 2 +- core/controllers/profile_test.py | 44 +++++----- core/controllers/question_editor_test.py | 20 ++--- core/controllers/reader_test.py | 50 +++++------ core/controllers/resources_test.py | 30 +++---- core/controllers/skill_editor_test.py | 23 +++-- core/controllers/story_editor_test.py | 12 +-- core/controllers/subscriptions_test.py | 10 +-- core/controllers/suggestion_test.py | 26 +++--- core/controllers/topic_editor_test.py | 36 ++++---- core/controllers/topic_viewer_test.py | 14 +-- .../topics_and_skills_dashboard_test.py | 12 +-- core/controllers/translator_test.py | 4 +- core/domain/dependency_registry_test.py | 10 +-- core/domain/email_manager_test.py | 18 ++-- core/domain/feedback_services_test.py | 2 +- core/domain/summary_services_test.py | 2 +- core/domain/user_services_test.py | 6 +- core/tests/test_utils.py | 28 +++++- 32 files changed, 349 insertions(+), 295 deletions(-) diff --git a/core/controllers/admin_test.py b/core/controllers/admin_test.py index b3468bd55119..f72522547a85 100644 --- a/core/controllers/admin_test.py +++ b/core/controllers/admin_test.py @@ -38,18 +38,20 @@ def setUp(self): def test_admin_page_rights(self): """Test access rights to the admin page.""" - response = self.testapp.get('/admin') + response = self.get_html('/admin', expect_errors=True, + expected_status_int=302) self.assertEqual(response.status_int, 302) # Login as a non-admin. self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/admin', expect_errors=True) + response = self.get_html('/admin', expect_errors=True, + expected_status_int=401) self.assertEqual(response.status_int, 401) self.logout() # Login as an admin. self.login(self.ADMIN_EMAIL, is_super_admin=True) - response = self.testapp.get('/admin') + response = self.get_html('/admin') self.assertEqual(response.status_int, 200) self.logout() @@ -57,7 +59,7 @@ def test_change_configuration_property(self): """Test that configuration properties can be changed.""" self.login(self.ADMIN_EMAIL, is_super_admin=True) - response = self.testapp.get('/admin') + response = self.get_html('/admin') csrf_token = self.get_csrf_token_from_response(response) response_dict = self.get_json('/adminhandler') @@ -87,11 +89,11 @@ def test_change_about_page_config_property(self): """Test that config property values are changed correctly.""" new_config_value = 'new_config_value' - response = self.testapp.get('/about') + response = self.get_html('/about') self.assertNotIn(new_config_value, response.body) self.login(self.ADMIN_EMAIL, is_super_admin=True) - response = self.testapp.get('/admin') + response = self.get_html('/admin') csrf_token = self.get_csrf_token_from_response(response) self.post_json( '/adminhandler', { @@ -101,7 +103,7 @@ def test_change_about_page_config_property(self): } }, csrf_token=csrf_token) - response = self.testapp.get('/about') + response = self.get_html('/about') self.assertIn(new_config_value, response.body) @@ -111,7 +113,7 @@ class GenerateDummyExplorationsTest(test_utils.GenericTestBase): def test_generate_count_greater_than_publish_count(self): self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.login(self.ADMIN_EMAIL, is_super_admin=True) - response = self.testapp.get('/admin') + response = self.get_html('/admin') csrf_token = self.get_csrf_token_from_response(response) self.post_json( '/adminhandler', { @@ -127,7 +129,7 @@ def test_generate_count_greater_than_publish_count(self): def test_generate_count_equal_to_publish_count(self): self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.login(self.ADMIN_EMAIL, is_super_admin=True) - response = self.testapp.get('/admin') + response = self.get_html('/admin') csrf_token = self.get_csrf_token_from_response(response) self.post_json( '/adminhandler', { @@ -143,7 +145,7 @@ def test_generate_count_equal_to_publish_count(self): def test_generate_count_less_than_publish_count(self): self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.login(self.ADMIN_EMAIL, is_super_admin=True) - response = self.testapp.get('/admin') + response = self.get_html('/admin') csrf_token = self.get_csrf_token_from_response(response) generated_exps_response = self.post_json( '/adminhandler', { @@ -185,7 +187,7 @@ def test_view_and_update_role(self): response_dict, {'user1': feconf.ROLE_ID_EXPLORATION_EDITOR}) # Check role correctly gets updated. - response = self.testapp.get(feconf.ADMIN_URL) + response = self.get_html(feconf.ADMIN_URL) csrf_token = self.get_csrf_token_from_response(response) response_dict = self.post_json( feconf.ADMIN_ROLE_HANDLER_URL, @@ -213,7 +215,7 @@ def test_invalid_username_in_view_and_update_role(self): expected_status_int=400, expect_errors=True) # Trying to update role of non-existent user. - response = self.testapp.get(feconf.ADMIN_URL) + response = self.get_html(feconf.ADMIN_URL) csrf_token = self.get_csrf_token_from_response(response) response = self.post_json( feconf.ADMIN_ROLE_HANDLER_URL, diff --git a/core/controllers/base_test.py b/core/controllers/base_test.py index 26bf196804d7..2e365771a2b9 100644 --- a/core/controllers/base_test.py +++ b/core/controllers/base_test.py @@ -72,12 +72,12 @@ def test_dev_indicator_appears_in_dev_and_not_in_production(self): """Test dev indicator appears in dev and not in production.""" with self.swap(constants, 'DEV_MODE', True): - response = self.testapp.get(feconf.LIBRARY_INDEX_URL) + response = self.get_html(feconf.LIBRARY_INDEX_URL) self.assertIn('
', response.body) with self.swap(constants, 'DEV_MODE', False): - response = self.testapp.get(feconf.LIBRARY_INDEX_URL) + response = self.get_html(feconf.LIBRARY_INDEX_URL) self.assertIn('
', response.body) @@ -106,10 +106,12 @@ def test_that_no_get_results_in_500_error(self): def test_requests_for_invalid_paths(self): """Test that requests for invalid paths result in a 404 error.""" - response = self.testapp.get('/library/extra', expect_errors=True) + response = self.get_html('/library/extra', expect_errors=True, + expected_status_int=404) self.assertEqual(response.status_int, 404) - response = self.testapp.get('/library/data/extra', expect_errors=True) + response = self.get_html('/library/data/extra', expect_errors=True, + expected_status_int=404) self.assertEqual(response.status_int, 404) response = self.testapp.post( @@ -123,7 +125,8 @@ def test_requests_for_invalid_paths(self): def test_redirect_in_logged_out_states(self): """Test for a redirect in logged out state on '/'.""" - response = self.testapp.get('/') + response = self.get_html('/', expect_errors=True, + expected_status_int=302) self.assertEqual(response.status_int, 302) self.assertIn('splash', response.headers['location']) @@ -133,7 +136,8 @@ def test_root_redirect_rules_for_logged_in_learners(self): # Since by default the homepage for all logged in users is the # learner dashboard, going to '/' should redirect to the learner # dashboard page. - response = self.testapp.get('/') + response = self.get_html('/', expect_errors=True, + expected_status_int=302) self.assertEqual(response.status_int, 302) self.assertIn('learner_dashboard', response.headers['location']) self.logout() @@ -151,7 +155,8 @@ def test_root_redirect_rules_for_users_with_no_user_contribution_model( # Since by default the homepage for all logged in users is the # learner dashboard, going to '/' should redirect to the learner # dashboard page. - response = self.testapp.get('/') + response = self.get_html('/', expect_errors=True, + expected_status_int=302) self.assertEqual(response.status_int, 302) self.assertIn('learner_dashboard', response.headers['location']) self.logout() @@ -165,7 +170,8 @@ def test_root_redirect_rules_for_logged_in_creators(self): # Since the default dashboard has been set as creator dashboard, going # to '/' should redirect to the creator dashboard. - response = self.testapp.get('/') + response = self.get_html('/', expect_errors=True, + expected_status_int=302) self.assertIn('creator_dashboard', response.headers['location']) def test_root_redirect_rules_for_logged_in_editors(self): @@ -195,7 +201,8 @@ def test_root_redirect_rules_for_logged_in_editors(self): # Since user has edited one exploration created by another user, # going to '/' should redirect to the dashboard page. - response = self.testapp.get('/') + response = self.get_html('/', expect_errors=True, + expected_status_int=302) self.assertEqual(response.status_int, 302) self.assertIn('dashboard', response.headers['location']) self.logout() @@ -279,7 +286,7 @@ def setUp(self): def test_jinja_autoescaping(self): form_url = '<[angular_tag]> x{{51 * 3}}y' with self.swap(feconf, 'SITE_FEEDBACK_FORM_URL', form_url): - response = self.testapp.get('/fake') + response = self.get_html('/fake') self.assertEqual(response.status_int, 200) self.assertIn('<[angular_tag]>', response.body) @@ -306,10 +313,10 @@ def test_logout_page(self): # Logout with valid query arg. This test only validates that the login # cookies have expired after hitting the logout url. current_page = '/explore/0' - response = self.testapp.get(current_page) + response = self.get_html(current_page) self.assertEqual(response.status_int, 200) - response = self.testapp.get(current_user_services.create_logout_url( - current_page)) + response = self.get_html(current_user_services.create_logout_url( + current_page), expect_errors=True, expected_status_int=302) expiry_date = response.headers['Set-Cookie'].rsplit('=', 1) self.assertTrue( diff --git a/core/controllers/collection_editor_test.py b/core/controllers/collection_editor_test.py index eeb12de5186e..789a6553b2e8 100644 --- a/core/controllers/collection_editor_test.py +++ b/core/controllers/collection_editor_test.py @@ -75,19 +75,20 @@ def test_access_collection_editor_page(self): '%s/%s?v=1' % ( feconf.COLLECTION_DATA_URL_PREFIX, self.COLLECTION_ID)) - self.assertEqual(response.status_int, 200) + self.assertEqual(response.status_code, 200) # Check that non-editors cannot access the editor page. This is due # to them not being whitelisted. - response = self.testapp.get( + response = self.get_html( '%s/%s' % ( feconf.COLLECTION_EDITOR_URL_PREFIX, - self.COLLECTION_ID)) + self.COLLECTION_ID), expect_errors=True, + expected_status_int=302) self.assertEqual(response.status_int, 302) # Check that whitelisted users can access and edit in the editor page. self.login(self.EDITOR_EMAIL) - response = self.testapp.get( + response = self.get_html( '%s/%s' % ( feconf.COLLECTION_EDITOR_URL_PREFIX, self.COLLECTION_ID)) @@ -104,10 +105,11 @@ def test_editable_collection_handler_get(self): # Check that non-editors cannot access the editor data handler. # This is due to them not being whitelisted. - response = self.testapp.get( + response = self.get_html( '%s/%s' % ( feconf.COLLECTION_EDITOR_DATA_URL_PREFIX, - self.COLLECTION_ID)) + self.COLLECTION_ID), expect_errors=True, + expected_status_int=302) self.assertEqual(response.status_int, 302) # Check that whitelisted users can access the data @@ -137,7 +139,7 @@ def test_editable_collection_handler_put_cannot_access(self): self.login(self.VIEWER_EMAIL) # Call get handler to return the csrf token. - response = self.testapp.get( + response = self.get_html( '%s/%s' % ( feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID)) @@ -169,7 +171,7 @@ def test_editable_collection_handler_put_can_access(self): self.login(self.EDITOR_EMAIL) # Call get handler to return the csrf token. - response = self.testapp.get( + response = self.get_html( '%s/%s' % ( feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID)) @@ -251,7 +253,7 @@ def test_publish_unpublish_collection(self): collection_id, self.owner_id, exploration_id=exploration_id) rights_manager.publish_exploration(self.owner, exploration_id) collection = collection_services.get_collection_by_id(collection_id) - response = self.testapp.get( + response = self.get_html( '%s/%s' % ( feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID)) csrf_token = self.get_csrf_token_from_response(response) @@ -264,7 +266,7 @@ def test_publish_unpublish_collection(self): # Login as admin and unpublish the collection. self.login(self.ADMIN_EMAIL) - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID)) csrf_token = self.get_csrf_token_from_response(response) response_dict = self.put_json( diff --git a/core/controllers/collection_viewer_test.py b/core/controllers/collection_viewer_test.py index 64255c5bd266..6850b18d5519 100644 --- a/core/controllers/collection_viewer_test.py +++ b/core/controllers/collection_viewer_test.py @@ -41,16 +41,16 @@ def setUp(self): self.save_new_valid_collection(self.COLLECTION_ID, self.editor_id) def test_unpublished_collections_are_invisible_to_logged_out_users(self): - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID), - expect_errors=True) + expect_errors=True, expected_status_int=404) self.assertEqual(response.status_int, 404) def test_unpublished_collections_are_invisible_to_unconnected_users(self): self.login(self.NEW_USER_EMAIL) - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID), - expect_errors=True) + expect_errors=True, expected_status_int=404) self.assertEqual(response.status_int, 404) self.logout() @@ -60,15 +60,15 @@ def test_unpublished_collections_are_invisible_to_other_editors(self): self.save_new_valid_collection('cid2', self.OTHER_EDITOR_EMAIL) self.login(self.OTHER_EDITOR_EMAIL) - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID), - expect_errors=True) + expect_errors=True, expected_status_int=404) self.assertEqual(response.status_int, 404) self.logout() def test_unpublished_collections_are_visible_to_their_editors(self): self.login(self.EDITOR_EMAIL) - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID)) self.assertEqual(response.status_int, 200) self.logout() @@ -77,7 +77,7 @@ def test_unpublished_collections_are_visible_to_admins(self): self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.set_admins([self.ADMIN_USERNAME]) self.login(self.ADMIN_EMAIL) - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID)) self.assertEqual(response.status_int, 200) self.logout() @@ -85,7 +85,7 @@ def test_unpublished_collections_are_visible_to_admins(self): def test_published_collections_are_visible_to_logged_out_users(self): rights_manager.publish_collection(self.editor, self.COLLECTION_ID) - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID), expect_errors=True) self.assertEqual(response.status_int, 200) @@ -94,7 +94,7 @@ def test_published_collections_are_visible_to_logged_in_users(self): rights_manager.publish_collection(self.editor, self.COLLECTION_ID) self.login(self.NEW_USER_EMAIL) - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID), expect_errors=True) self.assertEqual(response.status_int, 200) diff --git a/core/controllers/concept_card_viewer_test.py b/core/controllers/concept_card_viewer_test.py index b7a1bfffb138..e1c16b906b27 100644 --- a/core/controllers/concept_card_viewer_test.py +++ b/core/controllers/concept_card_viewer_test.py @@ -65,7 +65,7 @@ def test_get_concept_card(self): def test_get_concept_card_fails_when_new_structures_not_enabled(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', False): - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.CONCEPT_CARD_DATA_URL_PREFIX, self.skill_id), - expect_errors=True) + expect_errors=True, expected_status_int=404) self.assertEqual(response.status_int, 404) diff --git a/core/controllers/creator_dashboard_test.py b/core/controllers/creator_dashboard_test.py index edb94785e6a1..242549db4eec 100644 --- a/core/controllers/creator_dashboard_test.py +++ b/core/controllers/creator_dashboard_test.py @@ -38,21 +38,24 @@ class HomePageTest(test_utils.GenericTestBase): def test_logged_out_homepage(self): """Test the logged-out version of the home page.""" - response = self.testapp.get('/') + response = self.get_html('/', expect_errors=True, + expected_status_int=302) self.assertEqual(response.status_int, 302) self.assertIn('splash', response.headers['location']) def test_notifications_dashboard_redirects_for_logged_out_users(self): """Test the logged-out view of the notifications dashboard.""" - response = self.testapp.get('/notifications_dashboard') + response = self.get_html('/notifications_dashboard', expect_errors=True, + expected_status_int=302) self.assertEqual(response.status_int, 302) # This should redirect to the login page. self.assertIn('signup', response.headers['location']) self.assertIn('notifications_dashboard', response.headers['location']) self.login('reader@example.com') - response = self.testapp.get('/notifications_dashboard') + response = self.get_html('/notifications_dashboard', expect_errors=True, + expected_status_int=302) # This should redirect the user to complete signup. self.assertEqual(response.status_int, 302) self.logout() @@ -62,7 +65,7 @@ def test_logged_in_notifications_dashboard(self): self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME) self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/notifications_dashboard') + response = self.get_html('/notifications_dashboard') self.assertEqual(response.status_int, 200) self.logout() @@ -699,7 +702,7 @@ def test_new_exploration_ids(self): """Test generation of exploration ids.""" self.login(self.EDITOR_EMAIL) - response = self.testapp.get(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html(feconf.CREATOR_DASHBOARD_URL) self.assertEqual(response.status_int, 200) csrf_token = self.get_csrf_token_from_response(response) exp_a_id = self.post_json( diff --git a/core/controllers/editor_test.py b/core/controllers/editor_test.py index 0e22eb37e7e6..bd6e266c9cc8 100644 --- a/core/controllers/editor_test.py +++ b/core/controllers/editor_test.py @@ -114,7 +114,7 @@ def test_editor_page(self): """Test access to editor pages for the sample exploration.""" # Check that non-editors can access, but not edit, the editor page. - response = self.testapp.get('/create/0') + response = self.get_html('/create/0') self.assertEqual(response.status_int, 200) self.assertIn('Help others learn new things.', response.body) self.assert_cannot_edit(response.body) @@ -123,7 +123,7 @@ def test_editor_page(self): self.login(self.EDITOR_EMAIL) # Check that it is now possible to access and edit the editor page. - response = self.testapp.get('/create/0') + response = self.get_html('/create/0') self.assertIn('Help others learn new things.', response.body) self.assertEqual(response.status_int, 200) self.assert_can_edit(response.body) @@ -154,14 +154,14 @@ def test_that_default_exploration_cannot_be_published(self): """ self.login(self.EDITOR_EMAIL) - response = self.testapp.get(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html(feconf.CREATOR_DASHBOARD_URL) self.assertEqual(response.status_int, 200) csrf_token = self.get_csrf_token_from_response(response) exp_id = self.post_json( feconf.NEW_EXPLORATION_URL, {}, csrf_token=csrf_token )[creator_dashboard.EXPLORATION_ID_KEY] - response = self.testapp.get('/create/%s' % exp_id) + response = self.get_html('/create/%s' % exp_id) csrf_token = self.get_csrf_token_from_response(response) publish_url = '%s/%s' % (feconf.EXPLORATION_STATUS_PREFIX, exp_id) self.put_json( @@ -177,7 +177,7 @@ def test_add_new_state_error_cases(self): current_version = 1 self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/create/0') + response = self.get_html('/create/0') csrf_token = self.get_csrf_token_from_response(response) def _get_payload(new_state_name, version=None): @@ -264,7 +264,8 @@ def test_logout_from_invalid_url(self): invalid_current_page)) self.login(self.OWNER_EMAIL) - response = self.testapp.get(invalid_logout_url, expect_errors=False) + response = self.get_html(invalid_logout_url, expect_errors=True, + expected_status_int=302) self.assertEqual(response.status_int, 302) response.follow() self.assertEqual(response.status_int, 302) @@ -288,7 +289,8 @@ def test_logout_from_invalid_extra_url(self): invalid_current_page)) self.login(self.OWNER_EMAIL) - response = self.testapp.get(invalid_logout_url, expect_errors=False) + response = self.get_html(invalid_logout_url, expect_errors=True, + expected_status_int=302) self.assertEqual(response.status_int, 302) response.follow() self.assertEqual(response.status_int, 302) @@ -312,7 +314,8 @@ def test_logout_from_invalid_regex_exp_id(self): invalid_current_page)) self.login(self.OWNER_EMAIL) - response = self.testapp.get(invalid_logout_url, expect_errors=False) + response = self.get_html(invalid_logout_url, expect_errors=True, + expected_status_int=302) self.assertEqual(response.status_int, 302) response.follow() self.assertEqual(response.status_int, 302) @@ -326,7 +329,8 @@ def test_logout_from_empty_url(self): empty_redirect_logout_url = '/exploration_editor_logout?return_url=' self.login(self.OWNER_EMAIL) - response = self.testapp.get(empty_redirect_logout_url) + response = self.get_html(empty_redirect_logout_url, expect_errors=True, + expected_status_int=302) self.assertEqual(response.status_int, 302) response.follow() @@ -345,7 +349,8 @@ def test_logout_from_invalid_exploration_id(self): '/exploration_editor_logout?return_url=%s' % invalid_current_page) self.login(self.OWNER_EMAIL) - response = self.testapp.get(invalid_logout_url, expect_errors=False) + response = self.get_html(invalid_logout_url, expect_errors=True, + expected_status_int=302) self.assertEqual(response.status_int, 302) response.follow() self.assertEqual(response.status_int, 302) @@ -365,11 +370,12 @@ def test_logout_from_unpublished_exploration_editor(self): current_page_url = '%s/%s' % ( feconf.EDITOR_URL_PREFIX, unpublished_exp_id) self.login(self.OWNER_EMAIL) - response = self.testapp.get(current_page_url, expect_errors=False) + response = self.get_html(current_page_url, expect_errors=False) self.assertEqual(response.status_int, 200) - response = self.testapp.get( - '/exploration_editor_logout?return_url=%s' % current_page_url) + response = self.get_html( + '/exploration_editor_logout?return_url=%s' % current_page_url, + expect_errors=True, expected_status_int=302) self.assertEqual(response.status_int, 302) response = response.follow() self.assertEqual(response.status_int, 302) @@ -389,13 +395,14 @@ def test_logout_from_published_exploration_editor(self): current_page_url = '%s/%s' % ( feconf.EDITOR_URL_PREFIX, published_exp_id) self.login(self.OWNER_EMAIL) - response = self.testapp.get(current_page_url, expect_errors=False) + response = self.get_html(current_page_url, expect_errors=False) self.assertEqual(response.status_int, 200) rights_manager.publish_exploration(self.owner, published_exp_id) - response = self.testapp.get( - '/exploration_editor_logout?return_url=%s' % current_page_url) + response = self.get_html( + '/exploration_editor_logout?return_url=%s' % current_page_url, + expect_errors=True, expected_status_int=302) self.assertEqual(response.status_int, 302) response = response.follow() self.assertEqual(response.status_int, 302) @@ -584,7 +591,7 @@ def test_exploration_download_handler_for_default_exploration(self): 'state_name': 'State 3', })], 'changes') exploration = exp_services.get_exploration_by_id(exp_id) - response = self.testapp.get('/create/%s' % exp_id) + response = self.get_html('/create/%s' % exp_id) # Check download to zip file. # Download to zip file using download handler. @@ -647,7 +654,7 @@ def test_state_yaml_handler(self): exploration.add_states(['State A', 'State 2', 'State 3']) exploration.states['State A'].update_interaction_id('TextInput') - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.EDITOR_URL_PREFIX, exp_id)) csrf_token = self.get_csrf_token_from_response(response) response = self.post_json('/createhandler/state_yaml/%s' % exp_id, { @@ -867,7 +874,7 @@ def setUp(self): def test_reverting_to_old_exploration(self): """Test reverting to old exploration versions.""" # Open editor page. - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.EDITOR_URL_PREFIX, self.EXP_ID)) csrf_token = self.get_csrf_token_from_response(response) @@ -949,10 +956,10 @@ def test_versioning_for_default_exploration(self): self.assertNotIn('Hi, welcome to Oppia!', init_content) # v3 does not exist. - response = self.testapp.get( + response = self.get_json( '%s/%s?v=3' % (feconf.EXPLORATION_INIT_URL_PREFIX, self.EXP_ID), - expect_errors=True) - self.assertEqual(response.status_int, 404) + expect_errors=True, expected_status_int=404) + self.assertEqual(response['status_code'], 404) class ExplorationEditRightsTest(BaseEditorControllerTest): @@ -973,9 +980,9 @@ def test_user_banning(self): # Joe logs in. self.login('joe@example.com') - response = self.testapp.get(feconf.LIBRARY_INDEX_URL) + response = self.get_html(feconf.LIBRARY_INDEX_URL) self.assertEqual(response.status_int, 200) - response = self.testapp.get('/create/%s' % exp_id) + response = self.get_html('/create/%s' % exp_id) self.assertEqual(response.status_int, 200) self.assert_can_edit(response.body) @@ -983,10 +990,10 @@ def test_user_banning(self): self.set_banned_users(['joe']) # Test that Joe is banned (He can still access the library page). - response = self.testapp.get( + response = self.get_html( feconf.LIBRARY_INDEX_URL, expect_errors=True) self.assertEqual(response.status_int, 200) - response = self.testapp.get('/create/%s' % exp_id, expect_errors=True) + response = self.get_html('/create/%s' % exp_id, expect_errors=True) self.assertEqual(response.status_int, 200) self.assert_cannot_edit(response.body) @@ -995,7 +1002,7 @@ def test_user_banning(self): # Sandra logs in and is unaffected. self.login('sandra@example.com') - response = self.testapp.get('/create/%s' % exp_id) + response = self.get_html('/create/%s' % exp_id) self.assertEqual(response.status_int, 200) self.assert_can_edit(response.body) self.logout() @@ -1036,7 +1043,7 @@ def test_for_assign_role_for_exploration(self): exploration.states['State 2'].update_interaction_id('TextInput') exploration.states['State 3'].update_interaction_id('TextInput') - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.EDITOR_URL_PREFIX, exp_id)) csrf_token = self.get_csrf_token_from_response(response) @@ -1071,7 +1078,7 @@ def test_for_assign_role_for_exploration(self): # Check that viewer can access editor page but cannot edit. self.login(self.VIEWER_EMAIL) - response = self.testapp.get('/create/%s' % exp_id, expect_errors=True) + response = self.get_html('/create/%s' % exp_id, expect_errors=True) self.assertEqual(response.status_int, 200) self.assert_cannot_edit(response.body) self.assert_cannot_translate(response.body) @@ -1079,7 +1086,7 @@ def test_for_assign_role_for_exploration(self): # Check that collaborator can access editor page and can edit. self.login(self.COLLABORATOR_EMAIL) - response = self.testapp.get('/create/%s' % exp_id) + response = self.get_html('/create/%s' % exp_id) self.assertEqual(response.status_int, 200) self.assert_can_edit(response.body) self.assert_can_translate(response.body) @@ -1123,7 +1130,7 @@ def test_for_assign_role_for_exploration(self): # Check that collaborator2 can access editor page and can edit. self.login(self.COLLABORATOR2_EMAIL) - response = self.testapp.get('/create/%s' % exp_id) + response = self.get_html('/create/%s' % exp_id) self.assertEqual(response.status_int, 200) self.assert_can_edit(response.body) csrf_token = self.get_csrf_token_from_response(response) @@ -1166,7 +1173,7 @@ def test_for_assign_role_for_exploration(self): # Check that translator can access editor page and can only translate. self.login(self.TRANSLATOR_EMAIL) - response = self.testapp.get('/create/%s' % exp_id) + response = self.get_html('/create/%s' % exp_id) self.assertEqual(response.status_int, 200) self.assert_cannot_edit(response.body) self.assert_can_translate(response.body) @@ -1196,7 +1203,7 @@ def test_transfering_ownership_to_the_community(self): self.save_new_valid_exploration( exp_id, self.owner_id, title='My Exploration', end_state_name='END') - response = self.testapp.get('/create/%s' % exp_id) + response = self.get_html('/create/%s' % exp_id) csrf_token = self.get_csrf_token_from_response(response) rights_manager.publish_exploration(self.owner, exp_id) @@ -1222,7 +1229,7 @@ def test_transfering_ownership_to_the_community(self): # Check that any random user can access editor page and can edit. self.login(self.RANDOM_USER_EMAIL) - response = self.testapp.get('/create/%s' % exp_id) + response = self.get_html('/create/%s' % exp_id) self.assertEqual(response.status_int, 200) self.assert_can_edit(response.body) @@ -1244,7 +1251,7 @@ def test_user_exploration_emails_handler(self): exploration = exp_services.get_exploration_by_id(exp_id) - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.EDITOR_URL_PREFIX, exp_id)) csrf_token = self.get_csrf_token_from_response(response) @@ -1327,7 +1334,7 @@ def test_error_cases_for_email_sending(self): self.login(self.MODERATOR_EMAIL) # Go to the exploration editor page. - response = self.testapp.get('/create/%s' % self.EXP_ID) + response = self.get_html('/create/%s' % self.EXP_ID) self.assertEqual(response.status_int, 200) csrf_token = self.get_csrf_token_from_response(response) @@ -1383,7 +1390,7 @@ def test_email_is_sent_correctly_when_unpublishing(self): self.login(self.MODERATOR_EMAIL) # Go to the exploration editor page. - response = self.testapp.get('/create/%s' % self.EXP_ID) + response = self.get_html('/create/%s' % self.EXP_ID) self.assertEqual(response.status_int, 200) csrf_token = self.get_csrf_token_from_response(response) @@ -1445,7 +1452,7 @@ def test_email_functionality_cannot_be_used_by_non_moderators(self): self.login(self.EDITOR_EMAIL) # Go to the exploration editor page. - response = self.testapp.get('/create/%s' % self.EXP_ID) + response = self.get_html('/create/%s' % self.EXP_ID) self.assertEqual(response.status_int, 200) csrf_token = self.get_csrf_token_from_response(response) @@ -1699,7 +1706,7 @@ def setUp(self): 'is_valid': True } - response = self.testapp.get('/create/%s' % self.EXP_ID) + response = self.get_html('/create/%s' % self.EXP_ID) self.csrf_token = self.get_csrf_token_from_response(response) def test_resolve_issue_handler(self): @@ -1811,7 +1818,7 @@ def setUp(self): self._create_exp_user_data_model_objects_for_tests() # Generate CSRF token. - response = self.testapp.get('/create/%s' % self.EXP_ID1) + response = self.get_html('/create/%s' % self.EXP_ID1) self.csrf_token = self.get_csrf_token_from_response(response) def test_exploration_loaded_with_draft_applied(self): diff --git a/core/controllers/email_dashboard_test.py b/core/controllers/email_dashboard_test.py index b7abb6118c30..33f145c57189 100644 --- a/core/controllers/email_dashboard_test.py +++ b/core/controllers/email_dashboard_test.py @@ -44,7 +44,7 @@ def setUp(self): def test_that_handler_works_correctly(self): self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.testapp.get('/emaildashboard')) + self.get_html('/emaildashboard')) self.post_json( '/emaildashboarddatahandler', { 'data': { @@ -83,15 +83,15 @@ def test_that_page_is_accessible_to_authorised_users_only(self): # Make sure that only authorised users can access query pages. self.login(self.USER_A_EMAIL) with self.assertRaisesRegexp(Exception, '401 Unauthorized'): - self.testapp.get('/emaildashboard') + self.get_html('/emaildashboard') with self.assertRaisesRegexp(Exception, '401 Unauthorized'): - self.testapp.get('/querystatuscheck') + self.get_html('/querystatuscheck') self.logout() def test_that_exception_is_raised_for_invalid_input(self): self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.testapp.get('/emaildashboard')) + self.get_html('/emaildashboard')) self.post_json( '/emaildashboarddatahandler', { 'data': { @@ -157,7 +157,7 @@ def setUp(self): def test_that_correct_emails_are_sent_to_all_users(self): self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.testapp.get('/emaildashboard')) + self.get_html('/emaildashboard')) self.post_json( '/emaildashboarddatahandler', { 'data': { @@ -195,7 +195,7 @@ def test_that_correct_emails_are_sent_to_all_users(self): # Send email from email dashboard result page. self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.testapp.get('/emaildashboardresult/%s' % query_model.id)) + self.get_html('/emaildashboardresult/%s' % query_model.id)) self.post_json( '/emaildashboardresult/%s' % query_model.id, { 'data': { @@ -256,10 +256,10 @@ def test_that_valid_exceptions_are_raised(self): # Check that exception is raised for incorrect query id. self.login(self.SUBMITTER_EMAIL) with self.assertRaisesRegexp(Exception, '400 Bad Request'): - self.testapp.get('/emaildashboardresult/%s' % 'q123') + self.get_html('/emaildashboardresult/%s' % 'q123') csrf_token = self.get_csrf_token_from_response( - self.testapp.get('/emaildashboard')) + self.get_html('/emaildashboard')) self.post_json( '/emaildashboarddatahandler', { 'data': { @@ -276,7 +276,7 @@ def test_that_valid_exceptions_are_raised(self): self.assertEqual( query_models[0].query_status, feconf.USER_QUERY_STATUS_PROCESSING) with self.assertRaisesRegexp(Exception, '400 Bad Request'): - self.testapp.get('/emaildashboardresult/%s' % query_models[0].id) + self.get_html('/emaildashboardresult/%s' % query_models[0].id) self.logout() # Complete execution of query. @@ -293,14 +293,14 @@ def test_that_valid_exceptions_are_raised(self): # Check that exception is raised for unauthorized user. self.login(self.USER_A_EMAIL) with self.assertRaisesRegexp(Exception, '401 Unauthorized'): - self.testapp.get('/emaildashboardresult/%s' % query_models[0].id) + self.get_html('/emaildashboardresult/%s' % query_models[0].id) self.logout() # Check that exception is raised if current user is not submitter of # that query. self.login(self.NEW_SUBMITTER_EMAIL) with self.assertRaisesRegexp(Exception, '401 Unauthorized'): - self.testapp.get('/emaildashboardresult/%s' % query_models[0].id) + self.get_html('/emaildashboardresult/%s' % query_models[0].id) self.logout() # Check that exception is raised for accessing query result after @@ -309,7 +309,7 @@ def test_that_valid_exceptions_are_raised(self): # Send email from email dashboard result page. self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.testapp.get( + self.get_html( '/emaildashboardresult/%s' % query_models[0].id)) self.post_json( '/emaildashboardresult/%s' % query_models[0].id, { @@ -326,13 +326,13 @@ def test_that_valid_exceptions_are_raised(self): query_models[0].query_status, feconf.USER_QUERY_STATUS_ARCHIVED) self.login(self.SUBMITTER_EMAIL) with self.assertRaisesRegexp(Exception, '400 Bad Request'): - self.testapp.get('/emaildashboardresult/%s' % query_models[0].id) + self.get_html('/emaildashboardresult/%s' % query_models[0].id) self.logout() def test_that_correct_emails_are_sent_to_max_n_recipients(self): self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.testapp.get('/emaildashboard')) + self.get_html('/emaildashboard')) self.post_json( '/emaildashboarddatahandler', { 'data': { @@ -356,7 +356,7 @@ def test_that_correct_emails_are_sent_to_max_n_recipients(self): # Send email from email dashboard result page. self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.testapp.get( + self.get_html( '/emaildashboardresult/%s' % query_models[0].id)) self.post_json( '/emaildashboardresult/%s' % query_models[0].id, { @@ -380,7 +380,7 @@ def test_that_correct_emails_are_sent_to_max_n_recipients(self): def test_that_no_emails_are_sent_if_query_is_canceled(self): self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.testapp.get('/emaildashboard')) + self.get_html('/emaildashboard')) self.post_json( '/emaildashboarddatahandler', { 'data': { @@ -404,7 +404,7 @@ def test_that_no_emails_are_sent_if_query_is_canceled(self): # Send email from email dashboard result page. self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.testapp.get( + self.get_html( '/emaildashboardresult/%s' % query_models[0].id)) self.post_json( '/emaildashboardcancelresult/%s' % query_models[0].id, {}, @@ -420,7 +420,7 @@ def test_that_no_emails_are_sent_if_query_is_canceled(self): def test_that_test_email_for_bulk_emails_is_sent(self): self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.testapp.get('/emaildashboard')) + self.get_html('/emaildashboard')) self.post_json( '/emaildashboarddatahandler', { 'data': { @@ -444,7 +444,7 @@ def test_that_test_email_for_bulk_emails_is_sent(self): # Check that correct test email is sent. self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.testapp.get( + self.get_html( '/emaildashboardresult/%s' % query_models[0].id)) self.post_json( '/emaildashboardtestbulkemailhandler/%s' % query_models[0].id, { @@ -484,7 +484,7 @@ def test_that_test_email_for_bulk_emails_is_sent(self): def test_that_test_email_is_not_sent_to_query_recipients(self): self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.testapp.get('/emaildashboard')) + self.get_html('/emaildashboard')) self.post_json( '/emaildashboarddatahandler', { 'data': { @@ -504,7 +504,7 @@ def test_that_test_email_is_not_sent_to_query_recipients(self): self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.testapp.get( + self.get_html( '/emaildashboardresult/%s' % query_models[0].id)) self.post_json( '/emaildashboardtestbulkemailhandler/%s' % query_models[0].id, { diff --git a/core/controllers/feedback_test.py b/core/controllers/feedback_test.py index 7c8c1cb9e795..7533397adfa4 100644 --- a/core/controllers/feedback_test.py +++ b/core/controllers/feedback_test.py @@ -54,7 +54,7 @@ def setUp(self): # The corresponding user has already registered as an editor, and has a # username. self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/create/%s' % self.EXP_ID) + response = self.get_html('/create/%s' % self.EXP_ID) self.csrf_token = self.get_csrf_token_from_response(response) self.post_json('%s/%s' % ( feconf.FEEDBACK_THREADLIST_URL_PREFIX, self.EXP_ID @@ -133,7 +133,7 @@ def setUp(self): def test_create_thread(self): self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/create/%s' % self.EXP_ID) + response = self.get_html('/create/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.post_json( '%s/%s' % (feconf.FEEDBACK_THREADLIST_URL_PREFIX, self.EXP_ID), { @@ -166,7 +166,7 @@ def test_create_thread(self): def test_missing_thread_subject_raises_400_error(self): self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/create/%s' % self.EXP_ID) + response = self.get_html('/create/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) response_dict = self.post_json( '%s/%s' % (feconf.FEEDBACK_THREADLIST_URL_PREFIX, self.EXP_ID), { @@ -180,7 +180,7 @@ def test_missing_thread_subject_raises_400_error(self): def test_missing_thread_text_raises_400_error(self): self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/create/%s' % self.EXP_ID) + response = self.get_html('/create/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) response_dict = self.post_json( '%s/%s' % (feconf.FEEDBACK_THREADLIST_URL_PREFIX, self.EXP_ID), @@ -196,7 +196,7 @@ def test_missing_thread_text_raises_400_error(self): def test_post_message_to_existing_thread(self): self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/create/%s' % self.EXP_ID) + response = self.get_html('/create/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) # First, create a thread. @@ -256,7 +256,7 @@ def test_no_username_shown_for_logged_out_learners(self): exp_services.save_new_exploration(self.editor_id, exploration) rights_manager.publish_exploration(self.editor, new_exp_id) - response = self.testapp.get('/create/%s' % new_exp_id) + response = self.get_html('/create/%s' % new_exp_id) csrf_token = self.get_csrf_token_from_response(response) self.post_json( '/explorehandler/give_feedback/%s' % new_exp_id, @@ -279,7 +279,7 @@ def test_no_username_shown_for_logged_out_learners(self): def test_message_id_assignment_for_multiple_posts_to_same_thread(self): # Create a thread for others to post to. self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/create/%s' % self.EXP_ID) + response = self.get_html('/create/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.post_json( '%s/%s' % (feconf.FEEDBACK_THREADLIST_URL_PREFIX, self.EXP_ID), { @@ -311,7 +311,7 @@ def _get_email(index): # Each of these users posts a new message to the same thread. for num in range(num_users): self.login(_get_email(num)) - response = self.testapp.get('/create/%s' % self.EXP_ID) + response = self.get_html('/create/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.post_json( thread_url, { @@ -393,7 +393,7 @@ def _get_message_ids_in_a_thread(self, thread_id): def test_feedback_threads(self): self.login(self.USER_EMAIL) - response = self.testapp.get(feconf.LIBRARY_INDEX_URL) + response = self.get_html(feconf.LIBRARY_INDEX_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json('%s/%s' % ( @@ -420,7 +420,7 @@ def test_feedback_threads(self): self.logout() self.login(self.OWNER_EMAIL_1) - response = self.testapp.get(feconf.LIBRARY_INDEX_URL) + response = self.get_html(feconf.LIBRARY_INDEX_URL) csrf_token = self.get_csrf_token_from_response(response) # The owner opens the feedback thread. @@ -450,7 +450,7 @@ def test_feedback_threads(self): self.logout() self.login(self.USER_EMAIL) - response = self.testapp.get(feconf.LIBRARY_INDEX_URL) + response = self.get_html(feconf.LIBRARY_INDEX_URL) csrf_token = self.get_csrf_token_from_response(response) # The user opens the feedback thread. @@ -480,7 +480,7 @@ def test_feedback_threads(self): # Another owner logs in. self.login(self.OWNER_EMAIL_2) - response = self.testapp.get(feconf.LIBRARY_INDEX_URL) + response = self.get_html(feconf.LIBRARY_INDEX_URL) csrf_token = self.get_csrf_token_from_response(response) # The second owner opens the feedback thread. diff --git a/core/controllers/learner_dashboard_test.py b/core/controllers/learner_dashboard_test.py index 9c2f411ce332..7445655e0f60 100644 --- a/core/controllers/learner_dashboard_test.py +++ b/core/controllers/learner_dashboard_test.py @@ -252,7 +252,7 @@ def setUp(self): # Get the CSRF token and create a single thread with a single message. self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/create/%s' % self.EXP_ID_1) + response = self.get_html('/create/%s' % self.EXP_ID_1) self.csrf_token = self.get_csrf_token_from_response(response) self.post_json('%s/%s' % ( feconf.FEEDBACK_THREADLIST_URL_PREFIX, self.EXP_ID_1 diff --git a/core/controllers/learner_playlist_test.py b/core/controllers/learner_playlist_test.py index aa7f35c1fa88..6137bcd17add 100644 --- a/core/controllers/learner_playlist_test.py +++ b/core/controllers/learner_playlist_test.py @@ -71,7 +71,7 @@ def setUp(self): def test_add_exploration_to_learner_playlist(self): self.login(self.VIEWER_EMAIL) - response = self.testapp.get(feconf.LEARNER_DASHBOARD_URL) + response = self.get_html(feconf.LEARNER_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) # Add one exploration to the playlist. @@ -169,7 +169,7 @@ def test_add_exploration_to_learner_playlist(self): def test_add_collection_to_learner_playlist(self): self.login(self.VIEWER_EMAIL) - response = self.testapp.get(feconf.LEARNER_DASHBOARD_URL) + response = self.get_html(feconf.LEARNER_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) # Add one collection to the playlist. diff --git a/core/controllers/library_test.py b/core/controllers/library_test.py index 3fadb4ab69d7..9d94e0a8c0f0 100644 --- a/core/controllers/library_test.py +++ b/core/controllers/library_test.py @@ -45,7 +45,7 @@ def setUp(self): def test_library_page(self): """Test access to the library page.""" - response = self.testapp.get(feconf.LIBRARY_INDEX_URL) + response = self.get_html(feconf.LIBRARY_INDEX_URL) self.assertEqual(response.status_int, 200) response.mustcontain('Library - Oppia') @@ -199,10 +199,10 @@ class LibraryGroupPageTest(test_utils.GenericTestBase): def test_library_group_pages(self): """Test access to the top rated and recently published pages.""" - response = self.testapp.get(feconf.LIBRARY_TOP_RATED_URL) + response = self.get_html(feconf.LIBRARY_TOP_RATED_URL) self.assertEqual(response.status_int, 200) - response = self.testapp.get(feconf.LIBRARY_RECENTLY_PUBLISHED_URL) + response = self.get_html(feconf.LIBRARY_RECENTLY_PUBLISHED_URL) self.assertEqual(response.status_int, 200) def test_handler_for_recently_published_library_group_page(self): diff --git a/core/controllers/moderator_test.py b/core/controllers/moderator_test.py index 320c1997a282..b59fe9d35610 100644 --- a/core/controllers/moderator_test.py +++ b/core/controllers/moderator_test.py @@ -24,13 +24,15 @@ class ModeratorTest(test_utils.GenericTestBase): def test_moderator_page(self): """Tests access to the Moderator page.""" # Try accessing the moderator page without logging in. - response = self.testapp.get('/moderator') + response = self.get_html('/moderator', expect_errors=True, + expected_status_int=302) self.assertEqual(response.status_int, 302) # Try accessing the moderator page without being a moderator or admin. self.signup(self.VIEWER_EMAIL, self.VIEWER_USERNAME) self.login(self.VIEWER_EMAIL) - response = self.testapp.get('/moderator', expect_errors=True) + response = self.get_html('/moderator', expect_errors=True, + expected_status_int=401) self.assertEqual(response.status_int, 401) self.logout() @@ -38,7 +40,7 @@ def test_moderator_page(self): self.signup(self.MODERATOR_EMAIL, self.MODERATOR_USERNAME) self.set_moderators([self.MODERATOR_USERNAME]) self.login(self.MODERATOR_EMAIL) - response = self.testapp.get('/moderator') + response = self.get_html('/moderator') self.assertEqual(response.status_int, 200) self.logout() @@ -46,7 +48,7 @@ def test_moderator_page(self): self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.set_admins([self.ADMIN_USERNAME]) self.login(self.ADMIN_EMAIL) - response = self.testapp.get('/moderator') + response = self.get_html('/moderator') self.assertEqual(response.status_int, 200) self.logout() @@ -72,7 +74,7 @@ def setUp(self): def test_unpublished_activities_cannot_be_added_to_featured_list(self): self.login(self.MODERATOR_EMAIL) - response = self.testapp.get('/moderator') + response = self.get_html('/moderator') self.assertEqual(response.status_int, 200) csrf_token = self.get_csrf_token_from_response(response) diff --git a/core/controllers/pages_test.py b/core/controllers/pages_test.py index dd11211e3c47..a1899fa6bc8a 100644 --- a/core/controllers/pages_test.py +++ b/core/controllers/pages_test.py @@ -21,7 +21,7 @@ class NoninteractivePagesTest(test_utils.GenericTestBase): def test_about_page(self): """Test the About page.""" - response = self.testapp.get('/about') + response = self.get_html('/about') self.assertEqual(response.status_int, 200) self.assertEqual(response.content_type, 'text/html') response.mustcontain( diff --git a/core/controllers/profile_test.py b/core/controllers/profile_test.py index d2460d82594b..ea9e4cfa34dd 100644 --- a/core/controllers/profile_test.py +++ b/core/controllers/profile_test.py @@ -29,7 +29,7 @@ class SignupTest(test_utils.GenericTestBase): def test_signup_page_does_not_have_top_right_menu(self): self.login(self.EDITOR_EMAIL) - response = self.testapp.get(feconf.SIGNUP_URL) + response = self.get_html(feconf.SIGNUP_URL) self.assertEqual(response.status_int, 200) # Sign in can't be inside an html tag, but can appear inside js code. response.mustcontain(no=['Logout']) @@ -39,9 +39,10 @@ def test_going_somewhere_else_while_signing_in_logs_user_out(self): exp_services.load_demo('0') self.login(self.EDITOR_EMAIL) - response = self.testapp.get(feconf.SIGNUP_URL) + response = self.get_html(feconf.SIGNUP_URL) self.assertEqual(response.status_int, 200) - response = self.testapp.get('/create/0') + response = self.get_html('/create/0', expect_errors=True, + expected_status_int=302) self.assertEqual(response.status_int, 302) self.assertIn('Logout', response.headers['location']) self.assertIn('create', response.headers['location']) @@ -50,7 +51,7 @@ def test_going_somewhere_else_while_signing_in_logs_user_out(self): def test_accepting_terms_is_handled_correctly(self): self.login(self.EDITOR_EMAIL) - response = self.testapp.get(feconf.SIGNUP_URL) + response = self.get_html(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) response_dict = self.post_json( @@ -76,7 +77,7 @@ def test_accepting_terms_is_handled_correctly(self): def test_username_is_handled_correctly(self): self.login(self.EDITOR_EMAIL) - response = self.testapp.get(feconf.SIGNUP_URL) + response = self.get_html(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) response_dict = self.post_json( @@ -117,7 +118,7 @@ def test_username_is_handled_correctly(self): def test_default_dashboard_for_new_users(self): self.login(self.EDITOR_EMAIL) - response = self.testapp.get(feconf.SIGNUP_URL) + response = self.get_html(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) # This user should have the creator dashboard as default. @@ -136,7 +137,7 @@ def test_default_dashboard_for_new_users(self): self.logout() self.login(self.VIEWER_EMAIL) - response = self.testapp.get(feconf.SIGNUP_URL) + response = self.get_html(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) # This user should have the learner dashboard as default. @@ -161,7 +162,7 @@ def test_username_check(self): self.signup('abc@example.com', username='abc') self.login(self.EDITOR_EMAIL) - response = self.testapp.get(feconf.SIGNUP_URL) + response = self.get_html(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) response_dict = self.post_json( @@ -202,7 +203,7 @@ class EmailPreferencesTests(test_utils.GenericTestBase): def test_user_not_setting_email_prefs_on_signup(self): self.login(self.EDITOR_EMAIL) - response = self.testapp.get(feconf.SIGNUP_URL) + response = self.get_html(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( feconf.SIGNUP_DATA_URL, @@ -239,7 +240,7 @@ def test_user_not_setting_email_prefs_on_signup(self): def test_user_allowing_emails_on_signup(self): self.login(self.EDITOR_EMAIL) - response = self.testapp.get(feconf.SIGNUP_URL) + response = self.get_html(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( feconf.SIGNUP_DATA_URL, @@ -276,7 +277,7 @@ def test_user_allowing_emails_on_signup(self): def test_user_disallowing_emails_on_signup(self): self.login(self.EDITOR_EMAIL) - response = self.testapp.get(feconf.SIGNUP_URL) + response = self.get_html(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( feconf.SIGNUP_DATA_URL, @@ -320,7 +321,7 @@ def test_email_preferences_updates(self): self.signup(self.EDITOR_EMAIL, username=self.EDITOR_USERNAME) editor_id = self.get_user_id_from_email(self.EDITOR_EMAIL) self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/preferences') + response = self.get_html('/preferences') csrf_token = self.get_csrf_token_from_response(response) payload = { @@ -405,10 +406,11 @@ class ProfileLinkTests(test_utils.GenericTestBase): PROFILE_PIC_URL = '/preferenceshandler/profile_picture_by_username/' def test_get_profile_picture_invalid_username(self): - response = self.testapp.get( - '%s%s' % (self.PROFILE_PIC_URL, self.USERNAME), expect_errors=True + response = self.get_json( + '%s%s' % (self.PROFILE_PIC_URL, self.USERNAME), expect_errors=True, + expected_status_int=404 ) - self.assertEqual(response.status_int, 404) + self.assertEqual(response['status_code'], 404) def test_get_profile_picture_valid_username(self): self.signup(self.EMAIL, self.USERNAME) @@ -426,7 +428,7 @@ class ProfileDataHandlerTests(test_utils.GenericTestBase): def test_preference_page_updates(self): self.signup(self.EDITOR_EMAIL, username=self.EDITOR_USERNAME) self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/preferences') + response = self.get_html('/preferences') csrf_token = self.get_csrf_token_from_response(response) original_preferences = self.get_json('/preferenceshandler/data') self.assertEqual( @@ -454,7 +456,7 @@ def test_preference_page_updates(self): def test_profile_data_is_independent_of_currently_logged_in_user(self): self.signup(self.EDITOR_EMAIL, username=self.EDITOR_USERNAME) self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/preferences') + response = self.get_html('/preferences') csrf_token = self.get_csrf_token_from_response(response) self.put_json( '/preferenceshandler/data', @@ -468,7 +470,7 @@ def test_profile_data_is_independent_of_currently_logged_in_user(self): self.signup(self.VIEWER_EMAIL, username=self.VIEWER_USERNAME) self.login(self.VIEWER_EMAIL) - response = self.testapp.get('/preferences') + response = self.get_html('/preferences') csrf_token = self.get_csrf_token_from_response(response) self.put_json( '/preferenceshandler/data', @@ -628,7 +630,7 @@ def test_save_site_language_handler(self): self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME) language_code = 'es' self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/preferences') + response = self.get_html('/preferences') self.assertEqual(response.status_int, 200) csrf_token = self.get_csrf_token_from_response(response) self.put_json( @@ -654,7 +656,7 @@ class LongUserBioHandlerTests(test_utils.GenericTestBase): def test_userbio_within_limit(self): self.signup(self.EMAIL_A, self.USERNAME_A) self.login(self.EMAIL_A) - response = self.testapp.get('/preferences') + response = self.get_html('/preferences') self.assertEqual(response.status_int, 200) csrf_token = self.get_csrf_token_from_response(response) self.put_json( @@ -671,7 +673,7 @@ def test_userbio_within_limit(self): def test_user_bio_exceeds_limit(self): self.signup(self.EMAIL_B, self.USERNAME_B) self.login(self.EMAIL_B) - response = self.testapp.get('/preferences') + response = self.get_html('/preferences') self.assertEqual(response.status_int, 200) csrf_token = self.get_csrf_token_from_response(response) user_bio_response = self.put_json( diff --git a/core/controllers/question_editor_test.py b/core/controllers/question_editor_test.py index 801e7c52539e..6fd1d3ba7b36 100644 --- a/core/controllers/question_editor_test.py +++ b/core/controllers/question_editor_test.py @@ -78,7 +78,7 @@ def test_post(self): self.logout() self.login(self.ADMIN_EMAIL) - response = self.testapp.get(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) question_dict = self.question.to_dict() question_dict['id'] = None @@ -96,7 +96,7 @@ def test_post(self): self.logout() self.login(self.TOPIC_MANAGER_EMAIL) - response = self.testapp.get(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) question_dict = self.question.to_dict() question_dict['id'] = None @@ -131,7 +131,7 @@ def setUp(self): def test_post(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): self.login(self.NEW_USER_EMAIL) - response = self.testapp.get(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) response = self.testapp.post( '%s/%s/%s' % ( @@ -142,7 +142,7 @@ def test_post(self): self.logout() self.login(self.ADMIN_EMAIL) - response = self.testapp.get(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( '%s/%s/%s' % ( @@ -158,7 +158,7 @@ def test_post(self): self.logout() self.login(self.TOPIC_MANAGER_EMAIL) - response = self.testapp.get(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( '%s/%s/%s' % ( @@ -225,10 +225,10 @@ def test_get(self): # Check that non-admin and topic_manager cannot access the editor # data. self.login(self.NEW_USER_EMAIL) - response = self.testapp.get( + response = self.get_html( '%s/%s' % ( feconf.QUESTION_EDITOR_DATA_URL_PREFIX, self.question_id), - expect_errors=True) + expect_errors=True, expected_status_int=401) self.assertEqual(response.status_int, 401) self.logout() @@ -292,7 +292,7 @@ def test_put(self): payload['commit_message'] = 'update question data' self.login(self.ADMIN_EMAIL) - response = self.testapp.get(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) response_json = self.put_json( '%s/%s' % ( @@ -333,7 +333,7 @@ def test_put(self): self.logout() self.login(self.TOPIC_MANAGER_EMAIL) - response = self.testapp.get(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) payload = {} new_question_data = self._create_valid_question_data('GHI') @@ -363,7 +363,7 @@ def test_put(self): # Check that the question creator can edit the question. self.login(self.EDITOR_EMAIL) - response = self.testapp.get(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) payload = {} new_question_data = self._create_valid_question_data('GHI') diff --git a/core/controllers/reader_test.py b/core/controllers/reader_test.py index 8cb1a3fc9591..9a11502b1336 100644 --- a/core/controllers/reader_test.py +++ b/core/controllers/reader_test.py @@ -58,17 +58,17 @@ def setUp(self): category=self.UNICODE_TEST_STRING) def test_unpublished_explorations_are_invisible_to_logged_out_users(self): - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID), - expect_errors=True) + expect_errors=True, expected_status_int=404) self.assertEqual(response.status_int, 404) def test_unpublished_explorations_are_invisible_to_unconnected_users(self): self.signup(self.VIEWER_EMAIL, self.VIEWER_USERNAME) self.login(self.VIEWER_EMAIL) - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID), - expect_errors=True) + expect_errors=True, expected_status_int=404) self.assertEqual(response.status_int, 404) self.logout() @@ -82,15 +82,15 @@ def test_unpublished_explorations_are_invisible_to_other_editors(self): other_editor_email, other_exploration) self.login(other_editor_email) - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID), - expect_errors=True) + expect_errors=True, expected_status_int=404) self.assertEqual(response.status_int, 404) self.logout() def test_unpublished_explorations_are_visible_to_their_editors(self): self.login(self.EDITOR_EMAIL) - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID)) self.assertEqual(response.status_int, 200) self.logout() @@ -99,7 +99,7 @@ def test_unpublished_explorations_are_visible_to_admins(self): self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.set_admins([self.ADMIN_USERNAME]) self.login(self.ADMIN_EMAIL) - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID)) self.assertEqual(response.status_int, 200) self.logout() @@ -107,7 +107,7 @@ def test_unpublished_explorations_are_visible_to_admins(self): def test_published_explorations_are_visible_to_logged_out_users(self): rights_manager.publish_exploration(self.editor, self.EXP_ID) - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID), expect_errors=True) self.assertEqual(response.status_int, 200) @@ -117,7 +117,7 @@ def test_published_explorations_are_visible_to_logged_in_users(self): self.signup(self.VIEWER_EMAIL, self.VIEWER_USERNAME) self.login(self.VIEWER_EMAIL) - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID), expect_errors=True) self.assertEqual(response.status_int, 200) @@ -270,16 +270,16 @@ def test_get_exploration_pretests(self): json_response_1['pretest_question_dicts'][0]['id'], json_response_2['pretest_question_dicts'][0]['id']) - response = self.testapp.get( + response = self.get_html( '%s/%s?story_id=%s' % ( feconf.EXPLORATION_PRETESTS_URL_PREFIX, exp_id_2, STORY_ID), - expect_errors=True) + expect_errors=True, expected_status_int=400) self.assertEqual(response.status_int, 400) - response = self.testapp.get( + response = self.get_html( '%s/%s?story_id=%s' % ( feconf.EXPLORATION_PRETESTS_URL_PREFIX, exp_id_2, 'story'), - expect_errors=True) + expect_errors=True, expected_status_int=400) self.assertEqual(response.status_int, 400) @@ -355,7 +355,7 @@ def test_assign_and_read_ratings(self): self.signup('user@example.com', 'user') self.login('user@example.com') csrf_token = self.get_csrf_token_from_response( - self.testapp.get('/explore/%s' % self.EXP_ID)) + self.get_html('/explore/%s' % self.EXP_ID)) # User checks rating. ratings = self.get_json('/explorehandler/rating/%s' % self.EXP_ID) @@ -397,7 +397,7 @@ def test_non_logged_in_users_cannot_rate(self): self.signup('user@example.com', 'user') self.login('user@example.com') csrf_token = self.get_csrf_token_from_response( - self.testapp.get('/explore/%s' % self.EXP_ID)) + self.get_html('/explore/%s' % self.EXP_ID)) self.logout() ratings = self.get_json('/explorehandler/rating/%s' % self.EXP_ID) @@ -420,7 +420,7 @@ def test_ratings_by_different_users(self): self.login('a@example.com') csrf_token = self.get_csrf_token_from_response( - self.testapp.get('/explore/%s' % self.EXP_ID)) + self.get_html('/explore/%s' % self.EXP_ID)) self.put_json( '/explorehandler/rating/%s' % self.EXP_ID, { 'user_rating': 4 @@ -430,7 +430,7 @@ def test_ratings_by_different_users(self): self.login('b@example.com') csrf_token = self.get_csrf_token_from_response( - self.testapp.get('/explore/%s' % self.EXP_ID)) + self.get_html('/explore/%s' % self.EXP_ID)) ratings = self.get_json('/explorehandler/rating/%s' % self.EXP_ID) self.assertEqual(ratings['user_rating'], None) self.put_json( @@ -501,7 +501,7 @@ def _get_recommendation_ids( exploration_id, author_recommended_ids_str, collection_id_param, include_recommendations_param)) - response = self.testapp.get('/explore/%s' % exploration_id) + response = self.get_html('/explore/%s' % exploration_id) csrf_token = self.get_csrf_token_from_response(response) summaries = self.get_json( recommendations_url, params=csrf_token)['summaries'] @@ -927,7 +927,7 @@ def test_that_emails_are_sent(self): # Login and flag exploration. self.login(self.NEW_USER_EMAIL) - response = self.testapp.get('/explore/%s' % self.EXP_ID) + response = self.get_html('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.post_json( @@ -983,7 +983,7 @@ def test_non_logged_in_users_cannot_report(self): self.login(self.NEW_USER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.testapp.get('/explore/%s' % self.EXP_ID)) + self.get_html('/explore/%s' % self.EXP_ID)) self.logout() # Create report for exploration. @@ -1068,7 +1068,7 @@ def test_independent_exp_complete_event_handler(self): """ self.login(self.USER_EMAIL) - response = self.testapp.get(feconf.LIBRARY_INDEX_URL) + response = self.get_html(feconf.LIBRARY_INDEX_URL) csrf_token = self.get_csrf_token_from_response(response) payload = { @@ -1106,7 +1106,7 @@ def test_exp_complete_event_in_collection(self): """ self.login(self.USER_EMAIL) - response = self.testapp.get(feconf.LIBRARY_INDEX_URL) + response = self.get_html(feconf.LIBRARY_INDEX_URL) csrf_token = self.get_csrf_token_from_response(response) payload = { @@ -1151,7 +1151,7 @@ def test_exp_incomplete_event_handler(self): """Test handler for leaving an exploration incomplete.""" self.login(self.USER_EMAIL) - response = self.testapp.get(feconf.LIBRARY_INDEX_URL) + response = self.get_html(feconf.LIBRARY_INDEX_URL) csrf_token = self.get_csrf_token_from_response(response) payload = { @@ -1345,7 +1345,7 @@ def setUp(self): }] } - response = self.testapp.get('/explore/%s' % self.exp_id) + response = self.get_html('/explore/%s' % self.exp_id) self.csrf_token = self.get_csrf_token_from_response(response) def test_new_playthrough_gets_stored(self): diff --git a/core/controllers/resources_test.py b/core/controllers/resources_test.py index 94124cb32886..7f1a3f50f35c 100644 --- a/core/controllers/resources_test.py +++ b/core/controllers/resources_test.py @@ -49,7 +49,7 @@ def test_image_upload_and_download(self): """Test image uploading and downloading.""" self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/create/0') + response = self.get_html('/create/0') csrf_token = self.get_csrf_token_from_response(response) with open(os.path.join(feconf.TESTS_DATA_DIR, 'img.png'), @@ -71,7 +71,7 @@ def test_image_upload_and_download(self): def test_non_matching_extensions_are_detected(self): self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/create/0') + response = self.get_html('/create/0') csrf_token = self.get_csrf_token_from_response(response) filename_without_extension = 'test' @@ -113,7 +113,7 @@ def test_upload_empty_image(self): """Test upload of an empty image.""" self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/create/0') + response = self.get_html('/create/0') csrf_token = self.get_csrf_token_from_response(response) # Upload an empty image. @@ -134,7 +134,7 @@ def test_upload_bad_image(self): """Test upload of a malformed image.""" self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/create/0') + response = self.get_html('/create/0') csrf_token = self.get_csrf_token_from_response(response) # Upload an invalid image. @@ -163,7 +163,7 @@ def test_bad_filenames_are_detected(self): # TODO(sll): Add more tests here. self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/create/0') + response = self.get_html('/create/0') csrf_token = self.get_csrf_token_from_response(response) with open(os.path.join(feconf.TESTS_DATA_DIR, 'img.png'), @@ -183,7 +183,7 @@ def test_bad_filenames_are_detected(self): def test_missing_extensions_are_detected(self): self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/create/0') + response = self.get_html('/create/0') csrf_token = self.get_csrf_token_from_response(response) with open(os.path.join(feconf.TESTS_DATA_DIR, 'img.png'), @@ -204,7 +204,7 @@ def test_missing_extensions_are_detected(self): def test_bad_extensions_are_detected(self): self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/create/0') + response = self.get_html('/create/0') csrf_token = self.get_csrf_token_from_response(response) with open(os.path.join(feconf.TESTS_DATA_DIR, 'img.png'), @@ -245,7 +245,7 @@ def setUp(self): def test_audio_upload(self): self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/create/0') + response = self.get_html('/create/0') csrf_token = self.get_csrf_token_from_response(response) with open(os.path.join(feconf.TESTS_DATA_DIR, self.TEST_AUDIO_FILE_MP3), @@ -261,7 +261,7 @@ def test_audio_upload(self): def test_audio_upload_mpeg_container(self): self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/create/0') + response = self.get_html('/create/0') csrf_token = self.get_csrf_token_from_response(response) with open(os.path.join( @@ -280,7 +280,7 @@ def test_invalid_extension_is_detected(self): """Test that invalid extensions are caught.""" self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/create/0') + response = self.get_html('/create/0') csrf_token = self.get_csrf_token_from_response(response) filename_without_extension = 'test' @@ -311,7 +311,7 @@ def test_upload_empty_audio(self): """Test upload of empty audio.""" self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/create/0') + response = self.get_html('/create/0') csrf_token = self.get_csrf_token_from_response(response) # Upload empty audio. @@ -331,7 +331,7 @@ def test_upload_bad_audio(self): """Test upload of malformed audio.""" self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/create/0') + response = self.get_html('/create/0') csrf_token = self.get_csrf_token_from_response(response) response_dict = self.post_json( '%s/0' % self.AUDIO_UPLOAD_URL_PREFIX, @@ -351,7 +351,7 @@ def test_missing_extensions_are_detected(self): """Test upload of filenames with no extensions are caught.""" self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/create/0') + response = self.get_html('/create/0') csrf_token = self.get_csrf_token_from_response(response) missing_extension_filename = 'test' @@ -378,7 +378,7 @@ def test_exceed_max_length_detected(self): """Test that audio file is less than max playback length.""" self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/create/0') + response = self.get_html('/create/0') csrf_token = self.get_csrf_token_from_response(response) with open(os.path.join(feconf.TESTS_DATA_DIR, @@ -405,7 +405,7 @@ def test_non_matching_extensions_are_detected(self): """ self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/create/0') + response = self.get_html('/create/0') csrf_token = self.get_csrf_token_from_response(response) # Use an accepted audio extension in mismatched_filename diff --git a/core/controllers/skill_editor_test.py b/core/controllers/skill_editor_test.py index a327a149efb3..162b81ded380 100644 --- a/core/controllers/skill_editor_test.py +++ b/core/controllers/skill_editor_test.py @@ -53,7 +53,7 @@ def _get_csrf_token_for_put(self): csrf_token = None url_prefix = feconf.SKILL_EDITOR_URL_PREFIX with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.testapp.get('%s/%s' % (url_prefix, self.skill_id)) + response = self.get_html('%s/%s' % (url_prefix, self.skill_id)) csrf_token = self.get_csrf_token_from_response(response) return csrf_token @@ -89,14 +89,14 @@ def test_access_skill_editor_page(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): # Check that non-admins cannot access the editor page. self.login(self.NEW_USER_EMAIL) - response = self.testapp.get( - self.url, expect_errors=True) + response = self.get_html( + self.url, expect_errors=True, expected_status_int=401) self.assertEqual(response.status_int, 401) self.logout() # Check that admins can access and edit in the editor page. self.login(self.ADMIN_EMAIL) - response = self.testapp.get(self.url) + response = self.get_html(self.url) self.assertEqual(response.status_int, 200) self.logout() @@ -104,13 +104,15 @@ def test_skill_editor_page_fails(self): self.login(self.ADMIN_EMAIL) # Check GET returns 404 when new strutures' pages are not enabled. with self.swap(constants, 'ENABLE_NEW_STRUCTURES', False): - response = self.testapp.get(self.url, expect_errors=True) + response = self.get_html(self.url, expect_errors=True, + expected_status_int=404) self.assertEqual(response.status_int, 404) # Check GET returns 404 when cannot get skill by id. self._delete_skill_model_and_memcache(self.admin_id, self.skill_id) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.testapp.get(self.url, expect_errors=True) + response = self.get_html(self.url, expect_errors=True, + expected_status_int=404) self.assertEqual(response.status_int, 404) self.logout() @@ -143,7 +145,8 @@ def test_skill_rights_handler_fails(self): skill_services_swap = self.swap( skill_services, 'get_skill_rights', self._mock_get_skill_rights) with skill_services_swap: - response = self.testapp.get(self.url, expect_errors=True) + response = self.get_html(self.url, expect_errors=True, + expected_status_int=404) self.assertEqual(response.status_int, 404) self.logout() @@ -178,12 +181,14 @@ def test_editable_skill_handler_get_fails(self): self.login(self.ADMIN_EMAIL) # Check GET returns 404 when new strutures' pages are not enabled. with self.swap(constants, 'ENABLE_NEW_STRUCTURES', False): - response = self.testapp.get(self.url, expect_errors=True) + response = self.get_html(self.url, expect_errors=True, + expected_status_int=404) self.assertEqual(response.status_int, 404) # Check GET returns 404 when cannot get skill by id. self._delete_skill_model_and_memcache(self.admin_id, self.skill_id) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.testapp.get(self.url, expect_errors=True) + response = self.get_html(self.url, expect_errors=True, + expected_status_int=404) self.assertEqual(response.status_int, 404) self.logout() diff --git a/core/controllers/story_editor_test.py b/core/controllers/story_editor_test.py index 83135aae1684..0d38620519c8 100644 --- a/core/controllers/story_editor_test.py +++ b/core/controllers/story_editor_test.py @@ -53,17 +53,17 @@ def test_access_story_editor_page(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): # Check that non-admins cannot access the editor page. self.login(self.NEW_USER_EMAIL) - response = self.testapp.get( + response = self.get_html( '%s/%s/%s' % ( feconf.STORY_EDITOR_URL_PREFIX, self.topic_id, - self.story_id), expect_errors=True) + self.story_id), expect_errors=True, expected_status_int=401) self.assertEqual(response.status_int, 401) self.logout() # Check that admins can access and edit in the editor # page. self.login(self.ADMIN_EMAIL) - response = self.testapp.get( + response = self.get_html( '%s/%s/%s' % ( feconf.STORY_EDITOR_URL_PREFIX, self.topic_id, self.story_id)) @@ -74,10 +74,10 @@ def test_editable_story_handler_get(self): # Check that non-admins cannot access the editable story data. with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): self.login(self.NEW_USER_EMAIL) - response = self.testapp.get( + response = self.get_html( '%s/%s/%s' % ( feconf.STORY_EDITOR_DATA_URL_PREFIX, self.topic_id, - self.story_id), expect_errors=True) + self.story_id), expect_errors=True, expected_status_int=401) self.assertEqual(response.status_int, 401) self.logout() @@ -106,7 +106,7 @@ def test_editable_story_handler_put(self): } self.login(self.ADMIN_EMAIL) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.testapp.get( + response = self.get_html( '%s/%s/%s' % ( feconf.STORY_EDITOR_URL_PREFIX, self.topic_id, self.story_id)) diff --git a/core/controllers/subscriptions_test.py b/core/controllers/subscriptions_test.py index 673c291b108f..6b619edd1a2e 100644 --- a/core/controllers/subscriptions_test.py +++ b/core/controllers/subscriptions_test.py @@ -44,7 +44,7 @@ def test_subscribe_handler(self): """Test handler for new subscriptions to creators.""" self.login(self.USER_EMAIL) - response = self.testapp.get(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) payload = { @@ -77,7 +77,7 @@ def test_subscribe_handler(self): # Test another user subscription. self.login(self.USER2_EMAIL) - response = self.testapp.get(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( @@ -99,7 +99,7 @@ def test_unsubscribe_handler(self): # Add one subscription to editor. self.login(self.USER_EMAIL) - response = self.testapp.get(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( feconf.SUBSCRIBE_URL_PREFIX, payload, @@ -108,7 +108,7 @@ def test_unsubscribe_handler(self): # Add another subscription. self.login(self.USER2_EMAIL) - response = self.testapp.get(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( feconf.SUBSCRIBE_URL_PREFIX, payload, @@ -140,7 +140,7 @@ def test_unsubscribe_handler(self): # Unsubscribing another user. self.login(self.USER_EMAIL) - response = self.testapp.get(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( feconf.UNSUBSCRIBE_URL_PREFIX, payload, diff --git a/core/controllers/suggestion_test.py b/core/controllers/suggestion_test.py index d6caa40993bb..87aed928fdba 100644 --- a/core/controllers/suggestion_test.py +++ b/core/controllers/suggestion_test.py @@ -89,7 +89,7 @@ def setUp(self): self.logout() self.login(self.AUTHOR_EMAIL) - response = self.testapp.get('/explore/%s' % self.EXP_ID) + response = self.get_html('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.post_json( @@ -114,7 +114,7 @@ def setUp(self): self.logout() self.login(self.AUTHOR_EMAIL_2) - response = self.testapp.get('/explore/%s' % self.EXP_ID) + response = self.get_html('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.post_json( @@ -160,7 +160,7 @@ def setUp(self): def test_create_suggestion(self): self.login(self.AUTHOR_EMAIL_2) - response = self.testapp.get('/explore/%s' % self.EXP_ID) + response = self.get_html('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) exploration = exp_services.get_exploration_by_id(self.EXP_ID) @@ -193,7 +193,7 @@ def test_accept_suggestion(self): # Test editor can accept successfully. self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/explore/%s' % self.EXP_ID) + response = self.get_html('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) suggestion_to_accept = self.get_json( @@ -201,7 +201,7 @@ def test_accept_suggestion(self): feconf.SUGGESTION_LIST_URL_PREFIX, self.author_id))['suggestions'][0] - response = self.testapp.get('/explore/%s' % self.EXP_ID) + response = self.get_html('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.put_json('%s/exploration/%s/%s' % ( feconf.SUGGESTION_ACTION_URL_PREFIX, @@ -232,7 +232,7 @@ def test_accept_suggestion(self): feconf.SUGGESTION_LIST_URL_PREFIX, self.author_id_2))['suggestions'][0] - response = self.testapp.get('/explore/%s' % self.EXP_ID) + response = self.get_html('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.put_json('%s/exploration/%s/%s' % ( feconf.SUGGESTION_ACTION_URL_PREFIX, @@ -252,7 +252,7 @@ def test_accept_suggestion(self): feconf.SUGGESTION_LIST_URL_PREFIX, self.author_id_2))['suggestions'][0] - response = self.testapp.get('/explore/%s' % self.EXP_ID) + response = self.get_html('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.put_json('%s/exploration/%s/%s' % ( feconf.SUGGESTION_ACTION_URL_PREFIX, @@ -269,7 +269,7 @@ def test_accept_suggestion(self): suggestion_services.increment_score_for_user( self.author_id, 'content.Algebra', 15) - response = self.testapp.get('/explore/%s' % self.EXP_ID) + response = self.get_html('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.put_json('%s/exploration/%s/%s' % ( feconf.SUGGESTION_ACTION_URL_PREFIX, @@ -291,7 +291,7 @@ def test_accept_suggestion(self): # Testing admins can accept suggestions. self.login(self.ADMIN_EMAIL) - response = self.testapp.get('/explore/%s' % self.EXP_ID) + response = self.get_html('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) suggestion_to_accept = self.get_json( '%s?author_id=%s' % ( @@ -325,7 +325,7 @@ def test_suggestion_list_handler(self): def test_resubmit_rejected_suggestion(self): self.login(self.EDITOR_EMAIL) - response = self.testapp.get('/explore/%s' % self.EXP_ID) + response = self.get_html('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) suggestion = suggestion_services.query_suggestions( @@ -335,7 +335,7 @@ def test_resubmit_rejected_suggestion(self): self.logout() self.login(self.AUTHOR_EMAIL) - response = self.testapp.get('/explore/%s' % self.EXP_ID) + response = self.get_html('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.put_json('%s/resubmit/%s' % ( @@ -395,7 +395,7 @@ def setUp(self): feconf.CURRENT_STATES_SCHEMA_VERSION) } self.login(self.AUTHOR_EMAIL) - response = self.testapp.get(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( @@ -442,7 +442,7 @@ def test_accept_question_suggestion(self): )['suggestions'][0] self.login(self.ADMIN_EMAIL) - response = self.testapp.get(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): self.put_json('%s/topic/%s/%s' % ( diff --git a/core/controllers/topic_editor_test.py b/core/controllers/topic_editor_test.py index b2217afd82c1..fb57d1c05d7c 100644 --- a/core/controllers/topic_editor_test.py +++ b/core/controllers/topic_editor_test.py @@ -67,7 +67,7 @@ class TopicEditorStoryHandlerTest(BaseTopicEditorControllerTest): def test_story_creation(self): self.login(self.ADMIN_EMAIL) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.TOPIC_EDITOR_URL_PREFIX, self.topic_id)) csrf_token = self.get_csrf_token_from_response(response) json_response = self.post_json( @@ -120,7 +120,7 @@ def test_get(self): response = self.testapp.get( '%s/%s?cursor=' % ( feconf.TOPIC_EDITOR_QUESTION_URL, self.topic_id)) - self.assertEqual(response.status_int, 200) + self.assertEqual(response.status_code, 200) self.logout() topic_services.assign_role( @@ -137,10 +137,10 @@ def test_get(self): self.logout() self.login(self.NEW_USER_EMAIL) - response = self.testapp.get( + response = self.get_html( '%s/%s?cursor=' % ( feconf.TOPIC_EDITOR_QUESTION_URL, self.topic_id - ), expect_errors=True) + ), expect_errors=True, expected_status_int=401) self.assertEqual(response.status_int, 401) self.logout() @@ -152,11 +152,11 @@ def test_editable_subtopic_page_get(self): # editable subtopic data. with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): self.login(self.NEW_USER_EMAIL) - response = self.testapp.get( + response = self.get_html( '%s/%s/%s' % ( feconf.SUBTOPIC_PAGE_EDITOR_DATA_URL_PREFIX, self.topic_id, 1), - expect_errors=True) + expect_errors=True, expected_status_int=401) self.assertEqual(response.status_int, 401) self.logout() @@ -202,23 +202,23 @@ def test_access_topic_editor_page(self): # Check that non-admin and topic_manager cannot access the editor # page. self.login(self.NEW_USER_EMAIL) - response = self.testapp.get( + response = self.get_html( '%s/%s' % ( feconf.TOPIC_EDITOR_URL_PREFIX, self.topic_id), - expect_errors=True) + expect_errors=True, expected_status_int=401) self.assertEqual(response.status_int, 401) self.logout() # Check that admins can access the editor page. self.login(self.ADMIN_EMAIL) - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.TOPIC_EDITOR_URL_PREFIX, self.topic_id)) self.assertEqual(response.status_int, 200) self.logout() # Check that any topic manager can access the editor page. self.login(self.TOPIC_MANAGER_EMAIL) - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.TOPIC_EDITOR_URL_PREFIX, self.topic_id)) self.assertEqual(response.status_int, 200) self.logout() @@ -228,10 +228,10 @@ def test_editable_topic_handler_get(self): # Check that non-admins cannot access the editable topic data. with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): self.login(self.NEW_USER_EMAIL) - response = self.testapp.get( + response = self.get_html( '%s/%s' % ( feconf.TOPIC_EDITOR_DATA_URL_PREFIX, self.topic_id), - expect_errors=True) + expect_errors=True, expected_status_int=401) self.assertEqual(response.status_int, 401) self.logout() @@ -281,7 +281,7 @@ def test_editable_topic_handler_put(self): } self.login(self.ADMIN_EMAIL) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.TOPIC_EDITOR_URL_PREFIX, self.topic_id)) csrf_token = self.get_csrf_token_from_response(response) @@ -367,7 +367,7 @@ def test_editable_topic_handler_put_for_assigned_topic_manager(self): self.login(self.TOPIC_MANAGER_EMAIL) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.TOPIC_EDITOR_URL_PREFIX, self.topic_id)) csrf_token = self.get_csrf_token_from_response(response) # Check that the topic manager can edit the topic now. @@ -406,7 +406,7 @@ def test_assign_topic_manager_role(self): """Test the assign topic manager role for a topic functionality.""" self.login(self.ADMIN_EMAIL) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.TOPIC_EDITOR_URL_PREFIX, self.topic_id)) csrf_token = self.get_csrf_token_from_response(response) @@ -456,10 +456,10 @@ def test_get_topic_rights(self): self.login(self.NEW_USER_EMAIL) # Test that other users cannot access topic rights. - response = self.testapp.get( + response = self.get_html( '%s/%s' % ( feconf.TOPIC_RIGHTS_URL_PREFIX, self.topic_id), - expect_errors=True) + expect_errors=True, expected_status_int=401) self.assertEqual(response.status_int, 401) self.logout() @@ -470,7 +470,7 @@ def test_publish_and_unpublish_topic(self): """Test the publish and unpublish functionality.""" self.login(self.ADMIN_EMAIL) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.TOPIC_EDITOR_URL_PREFIX, self.topic_id)) csrf_token = self.get_csrf_token_from_response(response) # Test whether admin can publish and unpublish a topic. diff --git a/core/controllers/topic_viewer_test.py b/core/controllers/topic_viewer_test.py index 42f2403a6cda..4cd3a53c0b43 100644 --- a/core/controllers/topic_viewer_test.py +++ b/core/controllers/topic_viewer_test.py @@ -59,25 +59,25 @@ class TopicViewerPage(BaseTopicViewerControllerTest): def test_any_user_can_access_topic_viewer_page(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.TOPIC_VIEWER_URL_PREFIX, 'public_topic_name')) self.assertEqual(response.status_int, 200) def test_no_user_can_access_unpublished_topic_viewer_page(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.testapp.get( + response = self.get_html( '%s/%s' % ( feconf.TOPIC_VIEWER_URL_PREFIX, 'private_topic_name'), - expect_errors=True) + expect_errors=True, expected_status_int=404) self.assertEqual(response.status_int, 404) def test_get_fails_when_new_structures_not_enabled(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', False): - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.TOPIC_VIEWER_URL_PREFIX, 'public_topic_name'), - expect_errors=True) + expect_errors=True, expected_status_int=404) self.assertEqual(response.status_int, 404) @@ -100,7 +100,7 @@ def test_get(self): def test_get_fails_when_new_structures_not_enabled(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', False): - response = self.testapp.get( + response = self.get_html( '%s/%s' % (feconf.TOPIC_DATA_HANDLER, 'public_topic_name'), - expect_errors=True) + expect_errors=True, expected_status_int=404) self.assertEqual(response.status_int, 404) diff --git a/core/controllers/topics_and_skills_dashboard_test.py b/core/controllers/topics_and_skills_dashboard_test.py index 6b5648a59b2d..5e9be8761afe 100644 --- a/core/controllers/topics_and_skills_dashboard_test.py +++ b/core/controllers/topics_and_skills_dashboard_test.py @@ -51,7 +51,7 @@ def _get_csrf_token_for_put(self): csrf_token = None url_prefix = feconf.TOPICS_AND_SKILLS_DASHBOARD_URL with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.testapp.get(url_prefix) + response = self.get_html(url_prefix) csrf_token = self.get_csrf_token_from_response(response) return csrf_token @@ -62,7 +62,8 @@ def test_get_fails_when_new_structures_not_enabled(self): self.login(self.ADMIN_EMAIL) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', False): url = feconf.TOPICS_AND_SKILLS_DASHBOARD_URL - response = self.testapp.get(url, expect_errors=True) + response = self.get_html(url, expect_errors=True, + expected_status_int=404) self.assertEqual(response.status_int, 404) self.logout() @@ -80,9 +81,10 @@ def test_get(self): self.save_new_skill(skill_id_2, self.admin_id, 'Description 2') with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): self.login(self.NEW_USER_EMAIL) - response = self.testapp.get( - feconf.TOPICS_AND_SKILLS_DASHBOARD_DATA_URL, expect_errors=True) - self.assertEqual(response.status_int, 401) + response = self.get_json( + feconf.TOPICS_AND_SKILLS_DASHBOARD_DATA_URL, expect_errors=True, + expected_status_int=401) + self.assertEqual(response['status_code'], 401) self.logout() # Check that admins can access the topics and skills dashboard data. diff --git a/core/controllers/translator_test.py b/core/controllers/translator_test.py index f38d0e5873ce..6debd2b6b723 100644 --- a/core/controllers/translator_test.py +++ b/core/controllers/translator_test.py @@ -67,7 +67,7 @@ def setUp(self): self.login(self.TRANSLATOR_EMAIL) # Generate CSRF token. - response = self.testapp.get('/create/%s' % self.EXP_ID) + response = self.get_html('/create/%s' % self.EXP_ID) self.csrf_token = self.get_csrf_token_from_response(response) def test_transator_can_save_valid_change_list(self): @@ -160,7 +160,7 @@ def setUp(self): draft_change_list_id=1).put() # Generate CSRF token. - response = self.testapp.get('/create/%s' % self.EXP_ID) + response = self.get_html('/create/%s' % self.EXP_ID) self.csrf_token = self.get_csrf_token_from_response(response) def test_draft_updated_version_valid(self): diff --git a/core/domain/dependency_registry_test.py b/core/domain/dependency_registry_test.py index 4b2d526a6abb..65d71e4cee4e 100644 --- a/core/domain/dependency_registry_test.py +++ b/core/domain/dependency_registry_test.py @@ -39,11 +39,11 @@ class DependencyControllerTests(test_utils.GenericTestBase): """Tests for dependency loading on user-facing pages.""" def test_no_dependencies_in_non_exploration_pages(self): - response = self.testapp.get(feconf.LIBRARY_INDEX_URL) + response = self.get_html(feconf.LIBRARY_INDEX_URL) self.assertEqual(response.status_int, 200) response.mustcontain(no=['skulpt']) - response = self.testapp.get('/about') + response = self.get_html('/about') self.assertEqual(response.status_int, 200) response.mustcontain(no=['skulpt']) @@ -65,7 +65,7 @@ def test_dependencies_loaded_in_exploration_editor(self): # However, Skulpt is loaded in the exploration editor anyway, since # all dependencies are loaded in the exploration editor. - response = self.testapp.get('/create/0') + response = self.get_html('/create/0') self.assertEqual(response.status_int, 200) response.mustcontain('skulpt') @@ -85,7 +85,7 @@ def test_dependency_does_not_load_in_exploration_not_containing_it(self): self.assertNotIn('skulpt', all_dependency_ids) # Thus, Skulpt is not loaded in the exploration reader. - response = self.testapp.get('/explore/%s' % exp_id) + response = self.get_html('/explore/%s' % exp_id) self.assertEqual(response.status_int, 200) response.mustcontain(no=['skulpt']) @@ -103,6 +103,6 @@ def test_dependency_loads_in_exploration_containing_it(self): self.assertIn('skulpt', all_dependency_ids) # Thus, Skulpt is loaded in the exploration reader. - response = self.testapp.get('/explore/%s' % exp_id) + response = self.get_html('/explore/%s' % exp_id) self.assertEqual(response.status_int, 200) response.mustcontain('skulpt') diff --git a/core/domain/email_manager_test.py b/core/domain/email_manager_test.py index 88e444154c0c..2b198e4c77d5 100644 --- a/core/domain/email_manager_test.py +++ b/core/domain/email_manager_test.py @@ -119,7 +119,7 @@ def test_role_email_is_sent_when_editor_assigns_role(self): with self.can_send_emails_ctx, self.can_send_editor_role_email_ctx: self.login(self.EDITOR_EMAIL) - response = self.testapp.get('%s/%s' % ( + response = self.get_html('%s/%s' % ( feconf.EDITOR_URL_PREFIX, self.exploration.id)) csrf_token = self.get_csrf_token_from_response(response) self.put_json('%s/%s' % ( @@ -472,7 +472,7 @@ def test_email_not_sent_if_config_does_not_permit_it(self): self.new_email_content) self.login(self.EDITOR_EMAIL) - response = self.testapp.get(feconf.SIGNUP_URL) + response = self.get_html(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( @@ -502,7 +502,7 @@ def _log_error_for_tests(error_message): self.assertEqual(log_new_error_counter.times_called, 0) self.login(self.EDITOR_EMAIL) - response = self.testapp.get(feconf.SIGNUP_URL) + response = self.get_html(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) # No user-facing error should surface. @@ -549,7 +549,7 @@ def _log_error_for_tests(error_message): self.assertEqual(log_new_error_counter.times_called, 0) self.login(self.EDITOR_EMAIL) - response = self.testapp.get(feconf.SIGNUP_URL) + response = self.get_html(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) # No user-facing error should surface. @@ -594,7 +594,7 @@ def _log_error_for_tests(error_message): self.assertEqual(log_new_error_counter.times_called, 0) self.login(self.EDITOR_EMAIL) - response = self.testapp.get(feconf.SIGNUP_URL) + response = self.get_html(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) # No user-facing error should surface. @@ -626,7 +626,7 @@ def test_contents_of_signup_email_are_correct(self): 'Email Sender') self.login(self.EDITOR_EMAIL) - response = self.testapp.get(feconf.SIGNUP_URL) + response = self.get_html(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( @@ -659,7 +659,7 @@ def test_email_only_sent_once_for_repeated_signups_by_same_user(self): self.new_email_content) self.login(self.EDITOR_EMAIL) - response = self.testapp.get(feconf.SIGNUP_URL) + response = self.get_html(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( @@ -693,7 +693,7 @@ def test_email_only_sent_if_signup_was_successful(self): self.new_email_content) self.login(self.EDITOR_EMAIL) - response = self.testapp.get(feconf.SIGNUP_URL) + response = self.get_html(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( @@ -737,7 +737,7 @@ def test_record_of_sent_email_is_written_to_datastore(self): self.assertEqual(len(all_models), 0) self.login(self.EDITOR_EMAIL) - response = self.testapp.get(feconf.SIGNUP_URL) + response = self.get_html(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( diff --git a/core/domain/feedback_services_test.py b/core/domain/feedback_services_test.py index bb35dfccd842..4f49acaeabb8 100644 --- a/core/domain/feedback_services_test.py +++ b/core/domain/feedback_services_test.py @@ -920,7 +920,7 @@ def test_that_emails_are_not_sent_if_already_seen(self): self.login(self.EDITOR_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.testapp.get('/create/%s' % self.exploration.id)) + self.get_html('/create/%s' % self.exploration.id)) self.post_json( '%s/%s' % ( feconf.FEEDBACK_THREAD_VIEW_EVENT_URL, thread_id), diff --git a/core/domain/summary_services_test.py b/core/domain/summary_services_test.py index 3203c375a467..cbdfb2c97db1 100644 --- a/core/domain/summary_services_test.py +++ b/core/domain/summary_services_test.py @@ -256,7 +256,7 @@ def setUp(self): super(LibraryGroupsTest, self).setUp() self.login(self.ADMIN_EMAIL, is_super_admin=True) - response = self.testapp.get('/admin') + response = self.get_html('/admin') csrf_token = self.get_csrf_token_from_response(response) with self.swap( diff --git a/core/domain/user_services_test.py b/core/domain/user_services_test.py index 33510b4d293d..c30b9eb68715 100644 --- a/core/domain/user_services_test.py +++ b/core/domain/user_services_test.py @@ -924,7 +924,7 @@ def test_legacy_user(self): # After logging in and requesting a URL, the last_logged_in property is # set. self.login(self.VIEWER_EMAIL) - self.testapp.get(feconf.LIBRARY_INDEX_URL) + self.get_html(feconf.LIBRARY_INDEX_URL) self.assertIsNotNone( user_services.get_user_settings(self.viewer_id).last_logged_in) self.logout() @@ -961,7 +961,7 @@ def utcnow(cls): with self.swap(datetime, 'datetime', PatchedDatetime11Hours): self.login(self.VIEWER_EMAIL) - self.testapp.get(feconf.LIBRARY_INDEX_URL) + self.get_html(feconf.LIBRARY_INDEX_URL) self.assertEqual( user_services.get_user_settings(self.viewer_id).last_logged_in, previous_last_logged_in_datetime) @@ -969,7 +969,7 @@ def utcnow(cls): with self.swap(datetime, 'datetime', PatchedDatetime13Hours): self.login(self.VIEWER_EMAIL) - self.testapp.get(feconf.LIBRARY_INDEX_URL) + self.get_html(feconf.LIBRARY_INDEX_URL) self.assertGreater( user_services.get_user_settings(self.viewer_id).last_logged_in, previous_last_logged_in_datetime) diff --git a/core/tests/test_utils.py b/core/tests/test_utils.py index 1a8b7bb17599..521256187b36 100644 --- a/core/tests/test_utils.py +++ b/core/tests/test_utils.py @@ -482,6 +482,28 @@ def get_expected_logout_url(self, slug): """Returns the expected logout URL.""" return current_user_services.create_logout_url(slug) + def get_html(self, url, params=None, expect_errors=False, + expected_status_int=200): + """Get a HTML response, transformed to a Python object.""" + html_response = self.testapp.get( + url, params, expect_errors=expect_errors, + status=expected_status_int) + + # Testapp takes in a status parameter which is the expected status of + # the response. However this expected status is verified only when + # expect_errors=False. For other situations we need to explicitly check + # the status. + # Reference URL: + # https://github.com/Pylons/webtest/blob/ + # bf77326420b628c9ea5431432c7e171f88c5d874/webtest/app.py#L1119 . + self.assertEqual(html_response.status_int, expected_status_int) + if not expect_errors: + self.assertEqual(html_response.status_int, 200) + self.assertEqual( + html_response.content_type, 'text/html') + + return html_response + def _parse_json_response(self, json_response, expect_errors=False): """Convert a JSON server response to an object (such as a dict).""" if not expect_errors: @@ -635,7 +657,7 @@ def signup(self, email, username): # external calls being made to Gravatar when running the backend # tests. with self.urlfetch_mock(): - response = self.testapp.get(feconf.SIGNUP_URL) + response = self.get_html(feconf.SIGNUP_URL) self.assertEqual(response.status_int, 200) csrf_token = self.get_csrf_token_from_response(response) response = self.testapp.post( @@ -656,7 +678,7 @@ def set_config_property(self, config_obj, new_config_value): self._stash_current_user_env() self.login('tmpsuperadmin@example.com', is_super_admin=True) - response = self.testapp.get('/admin') + response = self.get_html('/admin') csrf_token = self.get_csrf_token_from_response(response) self.post_json( '/adminhandler', { @@ -679,7 +701,7 @@ def set_user_role(self, username, user_role): self._stash_current_user_env() self.login('tmpsuperadmin@example.com', is_super_admin=True) - response = self.testapp.get('/admin') + response = self.get_html('/admin') csrf_token = self.get_csrf_token_from_response(response) self.post_json( '/adminrolehandler', { From 846a5d8d3ba01ac4050076e20a19623e2b06c8a8 Mon Sep 17 00:00:00 2001 From: Rishav Chakraborty Date: Sat, 24 Nov 2018 00:46:03 +0530 Subject: [PATCH 02/11] Add test cases --- core/controllers/admin_test.py | 3 +- core/controllers/base_test.py | 17 ++++------ core/controllers/collection_editor_test.py | 6 ++-- core/controllers/collection_viewer_test.py | 6 ++-- core/controllers/creator_dashboard_test.py | 11 +++--- core/controllers/editor_test.py | 39 +++++++++------------- core/controllers/moderator_test.py | 3 +- core/controllers/profile_test.py | 3 +- core/controllers/reader_test.py | 6 ++-- core/controllers/topic_editor_test.py | 3 +- core/tests/test_utils.py | 12 +++++-- 11 files changed, 47 insertions(+), 62 deletions(-) diff --git a/core/controllers/admin_test.py b/core/controllers/admin_test.py index f72522547a85..923c59d4c42f 100644 --- a/core/controllers/admin_test.py +++ b/core/controllers/admin_test.py @@ -38,8 +38,7 @@ def setUp(self): def test_admin_page_rights(self): """Test access rights to the admin page.""" - response = self.get_html('/admin', expect_errors=True, - expected_status_int=302) + response = self.get_html('/admin', expected_status_int=302) self.assertEqual(response.status_int, 302) # Login as a non-admin. diff --git a/core/controllers/base_test.py b/core/controllers/base_test.py index 2e365771a2b9..9ceed6e3a7b5 100644 --- a/core/controllers/base_test.py +++ b/core/controllers/base_test.py @@ -125,8 +125,7 @@ def test_requests_for_invalid_paths(self): def test_redirect_in_logged_out_states(self): """Test for a redirect in logged out state on '/'.""" - response = self.get_html('/', expect_errors=True, - expected_status_int=302) + response = self.get_html('/', expected_status_int=302) self.assertEqual(response.status_int, 302) self.assertIn('splash', response.headers['location']) @@ -136,8 +135,7 @@ def test_root_redirect_rules_for_logged_in_learners(self): # Since by default the homepage for all logged in users is the # learner dashboard, going to '/' should redirect to the learner # dashboard page. - response = self.get_html('/', expect_errors=True, - expected_status_int=302) + response = self.get_html('/', expected_status_int=302) self.assertEqual(response.status_int, 302) self.assertIn('learner_dashboard', response.headers['location']) self.logout() @@ -155,8 +153,7 @@ def test_root_redirect_rules_for_users_with_no_user_contribution_model( # Since by default the homepage for all logged in users is the # learner dashboard, going to '/' should redirect to the learner # dashboard page. - response = self.get_html('/', expect_errors=True, - expected_status_int=302) + response = self.get_html('/', expected_status_int=302) self.assertEqual(response.status_int, 302) self.assertIn('learner_dashboard', response.headers['location']) self.logout() @@ -170,8 +167,7 @@ def test_root_redirect_rules_for_logged_in_creators(self): # Since the default dashboard has been set as creator dashboard, going # to '/' should redirect to the creator dashboard. - response = self.get_html('/', expect_errors=True, - expected_status_int=302) + response = self.get_html('/', expected_status_int=302) self.assertIn('creator_dashboard', response.headers['location']) def test_root_redirect_rules_for_logged_in_editors(self): @@ -201,8 +197,7 @@ def test_root_redirect_rules_for_logged_in_editors(self): # Since user has edited one exploration created by another user, # going to '/' should redirect to the dashboard page. - response = self.get_html('/', expect_errors=True, - expected_status_int=302) + response = self.get_html('/', expected_status_int=302) self.assertEqual(response.status_int, 302) self.assertIn('dashboard', response.headers['location']) self.logout() @@ -316,7 +311,7 @@ def test_logout_page(self): response = self.get_html(current_page) self.assertEqual(response.status_int, 200) response = self.get_html(current_user_services.create_logout_url( - current_page), expect_errors=True, expected_status_int=302) + current_page), expected_status_int=302) expiry_date = response.headers['Set-Cookie'].rsplit('=', 1) self.assertTrue( diff --git a/core/controllers/collection_editor_test.py b/core/controllers/collection_editor_test.py index 789a6553b2e8..2176c6796452 100644 --- a/core/controllers/collection_editor_test.py +++ b/core/controllers/collection_editor_test.py @@ -82,8 +82,7 @@ def test_access_collection_editor_page(self): response = self.get_html( '%s/%s' % ( feconf.COLLECTION_EDITOR_URL_PREFIX, - self.COLLECTION_ID), expect_errors=True, - expected_status_int=302) + self.COLLECTION_ID), expected_status_int=302) self.assertEqual(response.status_int, 302) # Check that whitelisted users can access and edit in the editor page. @@ -108,8 +107,7 @@ def test_editable_collection_handler_get(self): response = self.get_html( '%s/%s' % ( feconf.COLLECTION_EDITOR_DATA_URL_PREFIX, - self.COLLECTION_ID), expect_errors=True, - expected_status_int=302) + self.COLLECTION_ID), expected_status_int=302) self.assertEqual(response.status_int, 302) # Check that whitelisted users can access the data diff --git a/core/controllers/collection_viewer_test.py b/core/controllers/collection_viewer_test.py index 6850b18d5519..99b7437d0901 100644 --- a/core/controllers/collection_viewer_test.py +++ b/core/controllers/collection_viewer_test.py @@ -86,8 +86,7 @@ def test_published_collections_are_visible_to_logged_out_users(self): rights_manager.publish_collection(self.editor, self.COLLECTION_ID) response = self.get_html( - '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID), - expect_errors=True) + '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID)) self.assertEqual(response.status_int, 200) def test_published_collections_are_visible_to_logged_in_users(self): @@ -95,8 +94,7 @@ def test_published_collections_are_visible_to_logged_in_users(self): self.login(self.NEW_USER_EMAIL) response = self.get_html( - '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID), - expect_errors=True) + '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID)) self.assertEqual(response.status_int, 200) diff --git a/core/controllers/creator_dashboard_test.py b/core/controllers/creator_dashboard_test.py index 242549db4eec..8381dcf884aa 100644 --- a/core/controllers/creator_dashboard_test.py +++ b/core/controllers/creator_dashboard_test.py @@ -38,24 +38,23 @@ class HomePageTest(test_utils.GenericTestBase): def test_logged_out_homepage(self): """Test the logged-out version of the home page.""" - response = self.get_html('/', expect_errors=True, - expected_status_int=302) + response = self.get_html('/', expected_status_int=302) self.assertEqual(response.status_int, 302) self.assertIn('splash', response.headers['location']) def test_notifications_dashboard_redirects_for_logged_out_users(self): """Test the logged-out view of the notifications dashboard.""" - response = self.get_html('/notifications_dashboard', expect_errors=True, - expected_status_int=302) + response = self.get_html( + '/notifications_dashboard', expected_status_int=302) self.assertEqual(response.status_int, 302) # This should redirect to the login page. self.assertIn('signup', response.headers['location']) self.assertIn('notifications_dashboard', response.headers['location']) self.login('reader@example.com') - response = self.get_html('/notifications_dashboard', expect_errors=True, - expected_status_int=302) + response = self.get_html( + '/notifications_dashboard', expected_status_int=302) # This should redirect the user to complete signup. self.assertEqual(response.status_int, 302) self.logout() diff --git a/core/controllers/editor_test.py b/core/controllers/editor_test.py index bd6e266c9cc8..80823d28d08f 100644 --- a/core/controllers/editor_test.py +++ b/core/controllers/editor_test.py @@ -264,8 +264,7 @@ def test_logout_from_invalid_url(self): invalid_current_page)) self.login(self.OWNER_EMAIL) - response = self.get_html(invalid_logout_url, expect_errors=True, - expected_status_int=302) + response = self.get_html(invalid_logout_url, expected_status_int=302) self.assertEqual(response.status_int, 302) response.follow() self.assertEqual(response.status_int, 302) @@ -289,8 +288,7 @@ def test_logout_from_invalid_extra_url(self): invalid_current_page)) self.login(self.OWNER_EMAIL) - response = self.get_html(invalid_logout_url, expect_errors=True, - expected_status_int=302) + response = self.get_html(invalid_logout_url, expected_status_int=302) self.assertEqual(response.status_int, 302) response.follow() self.assertEqual(response.status_int, 302) @@ -314,8 +312,7 @@ def test_logout_from_invalid_regex_exp_id(self): invalid_current_page)) self.login(self.OWNER_EMAIL) - response = self.get_html(invalid_logout_url, expect_errors=True, - expected_status_int=302) + response = self.get_html(invalid_logout_url, expected_status_int=302) self.assertEqual(response.status_int, 302) response.follow() self.assertEqual(response.status_int, 302) @@ -329,8 +326,8 @@ def test_logout_from_empty_url(self): empty_redirect_logout_url = '/exploration_editor_logout?return_url=' self.login(self.OWNER_EMAIL) - response = self.get_html(empty_redirect_logout_url, expect_errors=True, - expected_status_int=302) + response = self.get_html( + empty_redirect_logout_url, expected_status_int=302) self.assertEqual(response.status_int, 302) response.follow() @@ -349,8 +346,7 @@ def test_logout_from_invalid_exploration_id(self): '/exploration_editor_logout?return_url=%s' % invalid_current_page) self.login(self.OWNER_EMAIL) - response = self.get_html(invalid_logout_url, expect_errors=True, - expected_status_int=302) + response = self.get_html(invalid_logout_url, expected_status_int=302) self.assertEqual(response.status_int, 302) response.follow() self.assertEqual(response.status_int, 302) @@ -370,12 +366,12 @@ def test_logout_from_unpublished_exploration_editor(self): current_page_url = '%s/%s' % ( feconf.EDITOR_URL_PREFIX, unpublished_exp_id) self.login(self.OWNER_EMAIL) - response = self.get_html(current_page_url, expect_errors=False) + response = self.get_html(current_page_url) self.assertEqual(response.status_int, 200) response = self.get_html( '/exploration_editor_logout?return_url=%s' % current_page_url, - expect_errors=True, expected_status_int=302) + expected_status_int=302) self.assertEqual(response.status_int, 302) response = response.follow() self.assertEqual(response.status_int, 302) @@ -395,14 +391,14 @@ def test_logout_from_published_exploration_editor(self): current_page_url = '%s/%s' % ( feconf.EDITOR_URL_PREFIX, published_exp_id) self.login(self.OWNER_EMAIL) - response = self.get_html(current_page_url, expect_errors=False) + response = self.get_html(current_page_url) self.assertEqual(response.status_int, 200) rights_manager.publish_exploration(self.owner, published_exp_id) response = self.get_html( '/exploration_editor_logout?return_url=%s' % current_page_url, - expect_errors=True, expected_status_int=302) + expected_status_int=302) self.assertEqual(response.status_int, 302) response = response.follow() self.assertEqual(response.status_int, 302) @@ -777,7 +773,7 @@ def add_logging_info(msg, *_): self.login(self.OWNER_EMAIL) self.delete_json( - '/createhandler/data/%s' % exp_id, expect_errors=True) + '/createhandler/data/%s' % exp_id) # Observed_log_messages[1] is 'Attempting to delete documents # from index %s, ids: %s' % (index.name, ', '.join(doc_ids)). It @@ -803,8 +799,7 @@ def add_logging_info(msg, *_): exp_services.save_new_exploration(self.admin_id, exploration) self.login(self.ADMIN_EMAIL) - self.delete_json( - '/createhandler/data/%s' % exp_id, expect_errors=True) + self.delete_json('/createhandler/data/%s' % exp_id) self.assertEqual(len(observed_log_messages), 3) self.assertEqual( observed_log_messages[0], @@ -824,8 +819,7 @@ def add_logging_info(msg, *_): exp_services.save_new_exploration(self.moderator_id, exploration) self.login(self.MODERATOR_EMAIL) - self.delete_json( - '/createhandler/data/%s' % exp_id, expect_errors=True) + self.delete_json('/createhandler/data/%s' % exp_id) self.assertEqual(len(observed_log_messages), 3) self.assertEqual( observed_log_messages[0], @@ -990,10 +984,9 @@ def test_user_banning(self): self.set_banned_users(['joe']) # Test that Joe is banned (He can still access the library page). - response = self.get_html( - feconf.LIBRARY_INDEX_URL, expect_errors=True) + response = self.get_html(feconf.LIBRARY_INDEX_URL) self.assertEqual(response.status_int, 200) - response = self.get_html('/create/%s' % exp_id, expect_errors=True) + response = self.get_html('/create/%s' % exp_id) self.assertEqual(response.status_int, 200) self.assert_cannot_edit(response.body) @@ -1078,7 +1071,7 @@ def test_for_assign_role_for_exploration(self): # Check that viewer can access editor page but cannot edit. self.login(self.VIEWER_EMAIL) - response = self.get_html('/create/%s' % exp_id, expect_errors=True) + response = self.get_html('/create/%s' % exp_id) self.assertEqual(response.status_int, 200) self.assert_cannot_edit(response.body) self.assert_cannot_translate(response.body) diff --git a/core/controllers/moderator_test.py b/core/controllers/moderator_test.py index b59fe9d35610..56b17a992fe9 100644 --- a/core/controllers/moderator_test.py +++ b/core/controllers/moderator_test.py @@ -24,8 +24,7 @@ class ModeratorTest(test_utils.GenericTestBase): def test_moderator_page(self): """Tests access to the Moderator page.""" # Try accessing the moderator page without logging in. - response = self.get_html('/moderator', expect_errors=True, - expected_status_int=302) + response = self.get_html('/moderator', expected_status_int=302) self.assertEqual(response.status_int, 302) # Try accessing the moderator page without being a moderator or admin. diff --git a/core/controllers/profile_test.py b/core/controllers/profile_test.py index ea9e4cfa34dd..487c7999233f 100644 --- a/core/controllers/profile_test.py +++ b/core/controllers/profile_test.py @@ -41,8 +41,7 @@ def test_going_somewhere_else_while_signing_in_logs_user_out(self): self.login(self.EDITOR_EMAIL) response = self.get_html(feconf.SIGNUP_URL) self.assertEqual(response.status_int, 200) - response = self.get_html('/create/0', expect_errors=True, - expected_status_int=302) + response = self.get_html('/create/0', expected_status_int=302) self.assertEqual(response.status_int, 302) self.assertIn('Logout', response.headers['location']) self.assertIn('create', response.headers['location']) diff --git a/core/controllers/reader_test.py b/core/controllers/reader_test.py index 9a11502b1336..2c9dcf91d26f 100644 --- a/core/controllers/reader_test.py +++ b/core/controllers/reader_test.py @@ -108,8 +108,7 @@ def test_published_explorations_are_visible_to_logged_out_users(self): rights_manager.publish_exploration(self.editor, self.EXP_ID) response = self.get_html( - '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID), - expect_errors=True) + '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID)) self.assertEqual(response.status_int, 200) def test_published_explorations_are_visible_to_logged_in_users(self): @@ -118,8 +117,7 @@ def test_published_explorations_are_visible_to_logged_in_users(self): self.signup(self.VIEWER_EMAIL, self.VIEWER_USERNAME) self.login(self.VIEWER_EMAIL) response = self.get_html( - '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID), - expect_errors=True) + '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID)) self.assertEqual(response.status_int, 200) diff --git a/core/controllers/topic_editor_test.py b/core/controllers/topic_editor_test.py index fb57d1c05d7c..b1f585bc7baa 100644 --- a/core/controllers/topic_editor_test.py +++ b/core/controllers/topic_editor_test.py @@ -425,8 +425,7 @@ def test_assign_topic_manager_role(self): '%s/%s/%s' % ( feconf.TOPIC_MANAGER_RIGHTS_URL_PREFIX, self.topic_id, self.topic_manager_id), - {}, csrf_token=csrf_token, expect_errors=True, - expected_status_int=200) + {}, csrf_token=csrf_token) self.logout() # Test for when committer doesn't have sufficient rights to assign diff --git a/core/tests/test_utils.py b/core/tests/test_utils.py index 521256187b36..b3e563f3e1e0 100644 --- a/core/tests/test_utils.py +++ b/core/tests/test_utils.py @@ -498,7 +498,11 @@ def get_html(self, url, params=None, expect_errors=False, # bf77326420b628c9ea5431432c7e171f88c5d874/webtest/app.py#L1119 . self.assertEqual(html_response.status_int, expected_status_int) if not expect_errors: - self.assertEqual(html_response.status_int, 200) + self.assertTrue(html_response.status_int >= 200 and + html_response.status_int < 400) + else: + self.assertTrue(html_response.status_int >= 400 and + html_response.status_int < 600) self.assertEqual( html_response.content_type, 'text/html') @@ -507,7 +511,11 @@ def get_html(self, url, params=None, expect_errors=False, def _parse_json_response(self, json_response, expect_errors=False): """Convert a JSON server response to an object (such as a dict).""" if not expect_errors: - self.assertEqual(json_response.status_int, 200) + self.assertTrue(json_response.status_int >= 200 and + json_response.status_int < 400) + else: + self.assertTrue(json_response.status_int >= 400 and + json_response.status_int < 600) self.assertEqual( json_response.content_type, 'application/json') self.assertTrue(json_response.body.startswith(feconf.XSSI_PREFIX)) From 982d98314d8facd98b11c813fc48deb0a53dfb5b Mon Sep 17 00:00:00 2001 From: Rishav Chakraborty Date: Sun, 2 Dec 2018 23:05:05 +0530 Subject: [PATCH 03/11] Function get_response --- core/controllers/admin_test.py | 26 +++---- core/controllers/base_test.py | 31 ++++---- core/controllers/collection_editor_test.py | 17 ++-- core/controllers/collection_viewer_test.py | 14 ++-- core/controllers/concept_card_viewer_test.py | 2 +- core/controllers/creator_dashboard_test.py | 10 +-- core/controllers/editor_test.py | 77 ++++++++++--------- core/controllers/email_dashboard_test.py | 42 +++++----- core/controllers/feedback_test.py | 24 +++--- core/controllers/learner_dashboard_test.py | 2 +- core/controllers/learner_playlist_test.py | 4 +- core/controllers/library_test.py | 6 +- core/controllers/moderator_test.py | 12 +-- core/controllers/pages_test.py | 2 +- core/controllers/profile_test.py | 36 ++++----- core/controllers/question_editor_test.py | 18 ++--- core/controllers/reader_test.py | 40 +++++----- core/controllers/resources_test.py | 49 ++++++------ core/controllers/skill_editor_test.py | 26 +++---- core/controllers/story_editor_test.py | 8 +- core/controllers/subscriptions_test.py | 10 +-- core/controllers/suggestion_test.py | 26 +++---- core/controllers/topic_editor_test.py | 27 ++++--- core/controllers/topic_viewer_test.py | 8 +- .../topics_and_skills_dashboard_test.py | 6 +- core/controllers/translator_test.py | 4 +- core/domain/dependency_registry_test.py | 10 +-- core/domain/email_manager_test.py | 18 ++--- core/domain/feedback_services_test.py | 2 +- core/domain/summary_services_test.py | 2 +- core/domain/user_services_test.py | 6 +- core/tests/test_utils.py | 38 ++++----- 32 files changed, 306 insertions(+), 297 deletions(-) diff --git a/core/controllers/admin_test.py b/core/controllers/admin_test.py index 923c59d4c42f..0d62cf900ec1 100644 --- a/core/controllers/admin_test.py +++ b/core/controllers/admin_test.py @@ -38,19 +38,19 @@ def setUp(self): def test_admin_page_rights(self): """Test access rights to the admin page.""" - response = self.get_html('/admin', expected_status_int=302) + response = self.get_response('/admin', expected_status_int=302) self.assertEqual(response.status_int, 302) # Login as a non-admin. self.login(self.EDITOR_EMAIL) - response = self.get_html('/admin', expect_errors=True, - expected_status_int=401) + response = self.get_response('/admin', expect_errors=True, + expected_status_int=401) self.assertEqual(response.status_int, 401) self.logout() # Login as an admin. self.login(self.ADMIN_EMAIL, is_super_admin=True) - response = self.get_html('/admin') + response = self.get_response('/admin') self.assertEqual(response.status_int, 200) self.logout() @@ -58,7 +58,7 @@ def test_change_configuration_property(self): """Test that configuration properties can be changed.""" self.login(self.ADMIN_EMAIL, is_super_admin=True) - response = self.get_html('/admin') + response = self.get_response('/admin') csrf_token = self.get_csrf_token_from_response(response) response_dict = self.get_json('/adminhandler') @@ -88,11 +88,11 @@ def test_change_about_page_config_property(self): """Test that config property values are changed correctly.""" new_config_value = 'new_config_value' - response = self.get_html('/about') + response = self.get_response('/about') self.assertNotIn(new_config_value, response.body) self.login(self.ADMIN_EMAIL, is_super_admin=True) - response = self.get_html('/admin') + response = self.get_response('/admin') csrf_token = self.get_csrf_token_from_response(response) self.post_json( '/adminhandler', { @@ -102,7 +102,7 @@ def test_change_about_page_config_property(self): } }, csrf_token=csrf_token) - response = self.get_html('/about') + response = self.get_response('/about') self.assertIn(new_config_value, response.body) @@ -112,7 +112,7 @@ class GenerateDummyExplorationsTest(test_utils.GenericTestBase): def test_generate_count_greater_than_publish_count(self): self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.login(self.ADMIN_EMAIL, is_super_admin=True) - response = self.get_html('/admin') + response = self.get_response('/admin') csrf_token = self.get_csrf_token_from_response(response) self.post_json( '/adminhandler', { @@ -128,7 +128,7 @@ def test_generate_count_greater_than_publish_count(self): def test_generate_count_equal_to_publish_count(self): self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.login(self.ADMIN_EMAIL, is_super_admin=True) - response = self.get_html('/admin') + response = self.get_response('/admin') csrf_token = self.get_csrf_token_from_response(response) self.post_json( '/adminhandler', { @@ -144,7 +144,7 @@ def test_generate_count_equal_to_publish_count(self): def test_generate_count_less_than_publish_count(self): self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.login(self.ADMIN_EMAIL, is_super_admin=True) - response = self.get_html('/admin') + response = self.get_response('/admin') csrf_token = self.get_csrf_token_from_response(response) generated_exps_response = self.post_json( '/adminhandler', { @@ -186,7 +186,7 @@ def test_view_and_update_role(self): response_dict, {'user1': feconf.ROLE_ID_EXPLORATION_EDITOR}) # Check role correctly gets updated. - response = self.get_html(feconf.ADMIN_URL) + response = self.get_response(feconf.ADMIN_URL) csrf_token = self.get_csrf_token_from_response(response) response_dict = self.post_json( feconf.ADMIN_ROLE_HANDLER_URL, @@ -214,7 +214,7 @@ def test_invalid_username_in_view_and_update_role(self): expected_status_int=400, expect_errors=True) # Trying to update role of non-existent user. - response = self.get_html(feconf.ADMIN_URL) + response = self.get_response(feconf.ADMIN_URL) csrf_token = self.get_csrf_token_from_response(response) response = self.post_json( feconf.ADMIN_ROLE_HANDLER_URL, diff --git a/core/controllers/base_test.py b/core/controllers/base_test.py index 9ceed6e3a7b5..a9d650d802f8 100644 --- a/core/controllers/base_test.py +++ b/core/controllers/base_test.py @@ -72,12 +72,12 @@ def test_dev_indicator_appears_in_dev_and_not_in_production(self): """Test dev indicator appears in dev and not in production.""" with self.swap(constants, 'DEV_MODE', True): - response = self.get_html(feconf.LIBRARY_INDEX_URL) + response = self.get_response(feconf.LIBRARY_INDEX_URL) self.assertIn('
', response.body) with self.swap(constants, 'DEV_MODE', False): - response = self.get_html(feconf.LIBRARY_INDEX_URL) + response = self.get_response(feconf.LIBRARY_INDEX_URL) self.assertIn('
', response.body) @@ -94,7 +94,8 @@ def test_that_no_get_results_in_500_error(self): url = re.sub('<([^/^:]+)>', 'abc123', url) # Some of these will 404 or 302. This is expected. - response = self.testapp.get(url, expect_errors=True) + response = self.get_response(url, expect_errors=True, + can_have_multiple_responses=True) self.assertIn( response.status_int, [200, 302, 400, 401, 404], msg=url) @@ -106,12 +107,12 @@ def test_that_no_get_results_in_500_error(self): def test_requests_for_invalid_paths(self): """Test that requests for invalid paths result in a 404 error.""" - response = self.get_html('/library/extra', expect_errors=True, - expected_status_int=404) + response = self.get_response('/library/extra', expect_errors=True, + expected_status_int=404) self.assertEqual(response.status_int, 404) - response = self.get_html('/library/data/extra', expect_errors=True, - expected_status_int=404) + response = self.get_response('/library/data/extra', expect_errors=True, + expected_status_int=404) self.assertEqual(response.status_int, 404) response = self.testapp.post( @@ -125,7 +126,7 @@ def test_requests_for_invalid_paths(self): def test_redirect_in_logged_out_states(self): """Test for a redirect in logged out state on '/'.""" - response = self.get_html('/', expected_status_int=302) + response = self.get_response('/', expected_status_int=302) self.assertEqual(response.status_int, 302) self.assertIn('splash', response.headers['location']) @@ -135,7 +136,7 @@ def test_root_redirect_rules_for_logged_in_learners(self): # Since by default the homepage for all logged in users is the # learner dashboard, going to '/' should redirect to the learner # dashboard page. - response = self.get_html('/', expected_status_int=302) + response = self.get_response('/', expected_status_int=302) self.assertEqual(response.status_int, 302) self.assertIn('learner_dashboard', response.headers['location']) self.logout() @@ -153,7 +154,7 @@ def test_root_redirect_rules_for_users_with_no_user_contribution_model( # Since by default the homepage for all logged in users is the # learner dashboard, going to '/' should redirect to the learner # dashboard page. - response = self.get_html('/', expected_status_int=302) + response = self.get_response('/', expected_status_int=302) self.assertEqual(response.status_int, 302) self.assertIn('learner_dashboard', response.headers['location']) self.logout() @@ -167,7 +168,7 @@ def test_root_redirect_rules_for_logged_in_creators(self): # Since the default dashboard has been set as creator dashboard, going # to '/' should redirect to the creator dashboard. - response = self.get_html('/', expected_status_int=302) + response = self.get_response('/', expected_status_int=302) self.assertIn('creator_dashboard', response.headers['location']) def test_root_redirect_rules_for_logged_in_editors(self): @@ -197,7 +198,7 @@ def test_root_redirect_rules_for_logged_in_editors(self): # Since user has edited one exploration created by another user, # going to '/' should redirect to the dashboard page. - response = self.get_html('/', expected_status_int=302) + response = self.get_response('/', expected_status_int=302) self.assertEqual(response.status_int, 302) self.assertIn('dashboard', response.headers['location']) self.logout() @@ -281,7 +282,7 @@ def setUp(self): def test_jinja_autoescaping(self): form_url = '<[angular_tag]> x{{51 * 3}}y' with self.swap(feconf, 'SITE_FEEDBACK_FORM_URL', form_url): - response = self.get_html('/fake') + response = self.get_response('/fake') self.assertEqual(response.status_int, 200) self.assertIn('<[angular_tag]>', response.body) @@ -308,9 +309,9 @@ def test_logout_page(self): # Logout with valid query arg. This test only validates that the login # cookies have expired after hitting the logout url. current_page = '/explore/0' - response = self.get_html(current_page) + response = self.get_response(current_page) self.assertEqual(response.status_int, 200) - response = self.get_html(current_user_services.create_logout_url( + response = self.get_response(current_user_services.create_logout_url( current_page), expected_status_int=302) expiry_date = response.headers['Set-Cookie'].rsplit('=', 1) diff --git a/core/controllers/collection_editor_test.py b/core/controllers/collection_editor_test.py index 2176c6796452..97cea57bd7d6 100644 --- a/core/controllers/collection_editor_test.py +++ b/core/controllers/collection_editor_test.py @@ -71,15 +71,14 @@ def test_access_collection_editor_page(self): # Check that it is possible to access a page with specific version # number. - response = self.testapp.get( + response = self.get_json( '%s/%s?v=1' % ( feconf.COLLECTION_DATA_URL_PREFIX, self.COLLECTION_ID)) - self.assertEqual(response.status_code, 200) # Check that non-editors cannot access the editor page. This is due # to them not being whitelisted. - response = self.get_html( + response = self.get_response( '%s/%s' % ( feconf.COLLECTION_EDITOR_URL_PREFIX, self.COLLECTION_ID), expected_status_int=302) @@ -87,7 +86,7 @@ def test_access_collection_editor_page(self): # Check that whitelisted users can access and edit in the editor page. self.login(self.EDITOR_EMAIL) - response = self.get_html( + response = self.get_response( '%s/%s' % ( feconf.COLLECTION_EDITOR_URL_PREFIX, self.COLLECTION_ID)) @@ -104,7 +103,7 @@ def test_editable_collection_handler_get(self): # Check that non-editors cannot access the editor data handler. # This is due to them not being whitelisted. - response = self.get_html( + response = self.get_response( '%s/%s' % ( feconf.COLLECTION_EDITOR_DATA_URL_PREFIX, self.COLLECTION_ID), expected_status_int=302) @@ -137,7 +136,7 @@ def test_editable_collection_handler_put_cannot_access(self): self.login(self.VIEWER_EMAIL) # Call get handler to return the csrf token. - response = self.get_html( + response = self.get_response( '%s/%s' % ( feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID)) @@ -169,7 +168,7 @@ def test_editable_collection_handler_put_can_access(self): self.login(self.EDITOR_EMAIL) # Call get handler to return the csrf token. - response = self.get_html( + response = self.get_response( '%s/%s' % ( feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID)) @@ -251,7 +250,7 @@ def test_publish_unpublish_collection(self): collection_id, self.owner_id, exploration_id=exploration_id) rights_manager.publish_exploration(self.owner, exploration_id) collection = collection_services.get_collection_by_id(collection_id) - response = self.get_html( + response = self.get_response( '%s/%s' % ( feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID)) csrf_token = self.get_csrf_token_from_response(response) @@ -264,7 +263,7 @@ def test_publish_unpublish_collection(self): # Login as admin and unpublish the collection. self.login(self.ADMIN_EMAIL) - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID)) csrf_token = self.get_csrf_token_from_response(response) response_dict = self.put_json( diff --git a/core/controllers/collection_viewer_test.py b/core/controllers/collection_viewer_test.py index 99b7437d0901..d318a1fa05db 100644 --- a/core/controllers/collection_viewer_test.py +++ b/core/controllers/collection_viewer_test.py @@ -41,14 +41,14 @@ def setUp(self): self.save_new_valid_collection(self.COLLECTION_ID, self.editor_id) def test_unpublished_collections_are_invisible_to_logged_out_users(self): - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID), expect_errors=True, expected_status_int=404) self.assertEqual(response.status_int, 404) def test_unpublished_collections_are_invisible_to_unconnected_users(self): self.login(self.NEW_USER_EMAIL) - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID), expect_errors=True, expected_status_int=404) self.assertEqual(response.status_int, 404) @@ -60,7 +60,7 @@ def test_unpublished_collections_are_invisible_to_other_editors(self): self.save_new_valid_collection('cid2', self.OTHER_EDITOR_EMAIL) self.login(self.OTHER_EDITOR_EMAIL) - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID), expect_errors=True, expected_status_int=404) self.assertEqual(response.status_int, 404) @@ -68,7 +68,7 @@ def test_unpublished_collections_are_invisible_to_other_editors(self): def test_unpublished_collections_are_visible_to_their_editors(self): self.login(self.EDITOR_EMAIL) - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID)) self.assertEqual(response.status_int, 200) self.logout() @@ -77,7 +77,7 @@ def test_unpublished_collections_are_visible_to_admins(self): self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.set_admins([self.ADMIN_USERNAME]) self.login(self.ADMIN_EMAIL) - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID)) self.assertEqual(response.status_int, 200) self.logout() @@ -85,7 +85,7 @@ def test_unpublished_collections_are_visible_to_admins(self): def test_published_collections_are_visible_to_logged_out_users(self): rights_manager.publish_collection(self.editor, self.COLLECTION_ID) - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID)) self.assertEqual(response.status_int, 200) @@ -93,7 +93,7 @@ def test_published_collections_are_visible_to_logged_in_users(self): rights_manager.publish_collection(self.editor, self.COLLECTION_ID) self.login(self.NEW_USER_EMAIL) - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID)) self.assertEqual(response.status_int, 200) diff --git a/core/controllers/concept_card_viewer_test.py b/core/controllers/concept_card_viewer_test.py index e1c16b906b27..0a089c392e8a 100644 --- a/core/controllers/concept_card_viewer_test.py +++ b/core/controllers/concept_card_viewer_test.py @@ -65,7 +65,7 @@ def test_get_concept_card(self): def test_get_concept_card_fails_when_new_structures_not_enabled(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', False): - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.CONCEPT_CARD_DATA_URL_PREFIX, self.skill_id), expect_errors=True, expected_status_int=404) self.assertEqual(response.status_int, 404) diff --git a/core/controllers/creator_dashboard_test.py b/core/controllers/creator_dashboard_test.py index 8381dcf884aa..561919621df6 100644 --- a/core/controllers/creator_dashboard_test.py +++ b/core/controllers/creator_dashboard_test.py @@ -38,14 +38,14 @@ class HomePageTest(test_utils.GenericTestBase): def test_logged_out_homepage(self): """Test the logged-out version of the home page.""" - response = self.get_html('/', expected_status_int=302) + response = self.get_response('/', expected_status_int=302) self.assertEqual(response.status_int, 302) self.assertIn('splash', response.headers['location']) def test_notifications_dashboard_redirects_for_logged_out_users(self): """Test the logged-out view of the notifications dashboard.""" - response = self.get_html( + response = self.get_response( '/notifications_dashboard', expected_status_int=302) self.assertEqual(response.status_int, 302) # This should redirect to the login page. @@ -53,7 +53,7 @@ def test_notifications_dashboard_redirects_for_logged_out_users(self): self.assertIn('notifications_dashboard', response.headers['location']) self.login('reader@example.com') - response = self.get_html( + response = self.get_response( '/notifications_dashboard', expected_status_int=302) # This should redirect the user to complete signup. self.assertEqual(response.status_int, 302) @@ -64,7 +64,7 @@ def test_logged_in_notifications_dashboard(self): self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME) self.login(self.EDITOR_EMAIL) - response = self.get_html('/notifications_dashboard') + response = self.get_response('/notifications_dashboard') self.assertEqual(response.status_int, 200) self.logout() @@ -701,7 +701,7 @@ def test_new_exploration_ids(self): """Test generation of exploration ids.""" self.login(self.EDITOR_EMAIL) - response = self.get_html(feconf.CREATOR_DASHBOARD_URL) + response = self.get_response(feconf.CREATOR_DASHBOARD_URL) self.assertEqual(response.status_int, 200) csrf_token = self.get_csrf_token_from_response(response) exp_a_id = self.post_json( diff --git a/core/controllers/editor_test.py b/core/controllers/editor_test.py index 80823d28d08f..aaeabdd5fba0 100644 --- a/core/controllers/editor_test.py +++ b/core/controllers/editor_test.py @@ -114,7 +114,7 @@ def test_editor_page(self): """Test access to editor pages for the sample exploration.""" # Check that non-editors can access, but not edit, the editor page. - response = self.get_html('/create/0') + response = self.get_response('/create/0') self.assertEqual(response.status_int, 200) self.assertIn('Help others learn new things.', response.body) self.assert_cannot_edit(response.body) @@ -123,7 +123,7 @@ def test_editor_page(self): self.login(self.EDITOR_EMAIL) # Check that it is now possible to access and edit the editor page. - response = self.get_html('/create/0') + response = self.get_response('/create/0') self.assertIn('Help others learn new things.', response.body) self.assertEqual(response.status_int, 200) self.assert_can_edit(response.body) @@ -154,14 +154,14 @@ def test_that_default_exploration_cannot_be_published(self): """ self.login(self.EDITOR_EMAIL) - response = self.get_html(feconf.CREATOR_DASHBOARD_URL) + response = self.get_response(feconf.CREATOR_DASHBOARD_URL) self.assertEqual(response.status_int, 200) csrf_token = self.get_csrf_token_from_response(response) exp_id = self.post_json( feconf.NEW_EXPLORATION_URL, {}, csrf_token=csrf_token )[creator_dashboard.EXPLORATION_ID_KEY] - response = self.get_html('/create/%s' % exp_id) + response = self.get_response('/create/%s' % exp_id) csrf_token = self.get_csrf_token_from_response(response) publish_url = '%s/%s' % (feconf.EXPLORATION_STATUS_PREFIX, exp_id) self.put_json( @@ -177,7 +177,7 @@ def test_add_new_state_error_cases(self): current_version = 1 self.login(self.EDITOR_EMAIL) - response = self.get_html('/create/0') + response = self.get_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) def _get_payload(new_state_name, version=None): @@ -264,7 +264,8 @@ def test_logout_from_invalid_url(self): invalid_current_page)) self.login(self.OWNER_EMAIL) - response = self.get_html(invalid_logout_url, expected_status_int=302) + response = self.get_response( + invalid_logout_url, expected_status_int=302) self.assertEqual(response.status_int, 302) response.follow() self.assertEqual(response.status_int, 302) @@ -288,7 +289,8 @@ def test_logout_from_invalid_extra_url(self): invalid_current_page)) self.login(self.OWNER_EMAIL) - response = self.get_html(invalid_logout_url, expected_status_int=302) + response = self.get_response( + invalid_logout_url, expected_status_int=302) self.assertEqual(response.status_int, 302) response.follow() self.assertEqual(response.status_int, 302) @@ -312,7 +314,8 @@ def test_logout_from_invalid_regex_exp_id(self): invalid_current_page)) self.login(self.OWNER_EMAIL) - response = self.get_html(invalid_logout_url, expected_status_int=302) + response = self.get_response( + invalid_logout_url, expected_status_int=302) self.assertEqual(response.status_int, 302) response.follow() self.assertEqual(response.status_int, 302) @@ -326,7 +329,7 @@ def test_logout_from_empty_url(self): empty_redirect_logout_url = '/exploration_editor_logout?return_url=' self.login(self.OWNER_EMAIL) - response = self.get_html( + response = self.get_response( empty_redirect_logout_url, expected_status_int=302) self.assertEqual(response.status_int, 302) @@ -346,7 +349,8 @@ def test_logout_from_invalid_exploration_id(self): '/exploration_editor_logout?return_url=%s' % invalid_current_page) self.login(self.OWNER_EMAIL) - response = self.get_html(invalid_logout_url, expected_status_int=302) + response = self.get_response( + invalid_logout_url, expected_status_int=302) self.assertEqual(response.status_int, 302) response.follow() self.assertEqual(response.status_int, 302) @@ -366,10 +370,10 @@ def test_logout_from_unpublished_exploration_editor(self): current_page_url = '%s/%s' % ( feconf.EDITOR_URL_PREFIX, unpublished_exp_id) self.login(self.OWNER_EMAIL) - response = self.get_html(current_page_url) + response = self.get_response(current_page_url) self.assertEqual(response.status_int, 200) - response = self.get_html( + response = self.get_response( '/exploration_editor_logout?return_url=%s' % current_page_url, expected_status_int=302) self.assertEqual(response.status_int, 302) @@ -391,12 +395,12 @@ def test_logout_from_published_exploration_editor(self): current_page_url = '%s/%s' % ( feconf.EDITOR_URL_PREFIX, published_exp_id) self.login(self.OWNER_EMAIL) - response = self.get_html(current_page_url) + response = self.get_response(current_page_url) self.assertEqual(response.status_int, 200) rights_manager.publish_exploration(self.owner, published_exp_id) - response = self.get_html( + response = self.get_response( '/exploration_editor_logout?return_url=%s' % current_page_url, expected_status_int=302) self.assertEqual(response.status_int, 302) @@ -587,12 +591,13 @@ def test_exploration_download_handler_for_default_exploration(self): 'state_name': 'State 3', })], 'changes') exploration = exp_services.get_exploration_by_id(exp_id) - response = self.get_html('/create/%s' % exp_id) + response = self.get_response('/create/%s' % exp_id) # Check download to zip file. # Download to zip file using download handler. download_url = '/createhandler/download/%s' % exp_id - response = self.testapp.get(download_url) + response = self.get_response(download_url, + expected_content_type='text/plain') # Check downloaded zip file. self.assertEqual(response.headers['Content-Type'], 'text/plain') @@ -650,7 +655,7 @@ def test_state_yaml_handler(self): exploration.add_states(['State A', 'State 2', 'State 3']) exploration.states['State A'].update_interaction_id('TextInput') - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.EDITOR_URL_PREFIX, exp_id)) csrf_token = self.get_csrf_token_from_response(response) response = self.post_json('/createhandler/state_yaml/%s' % exp_id, { @@ -868,7 +873,7 @@ def setUp(self): def test_reverting_to_old_exploration(self): """Test reverting to old exploration versions.""" # Open editor page. - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.EDITOR_URL_PREFIX, self.EXP_ID)) csrf_token = self.get_csrf_token_from_response(response) @@ -974,9 +979,9 @@ def test_user_banning(self): # Joe logs in. self.login('joe@example.com') - response = self.get_html(feconf.LIBRARY_INDEX_URL) + response = self.get_response(feconf.LIBRARY_INDEX_URL) self.assertEqual(response.status_int, 200) - response = self.get_html('/create/%s' % exp_id) + response = self.get_response('/create/%s' % exp_id) self.assertEqual(response.status_int, 200) self.assert_can_edit(response.body) @@ -984,9 +989,9 @@ def test_user_banning(self): self.set_banned_users(['joe']) # Test that Joe is banned (He can still access the library page). - response = self.get_html(feconf.LIBRARY_INDEX_URL) + response = self.get_response(feconf.LIBRARY_INDEX_URL) self.assertEqual(response.status_int, 200) - response = self.get_html('/create/%s' % exp_id) + response = self.get_response('/create/%s' % exp_id) self.assertEqual(response.status_int, 200) self.assert_cannot_edit(response.body) @@ -995,7 +1000,7 @@ def test_user_banning(self): # Sandra logs in and is unaffected. self.login('sandra@example.com') - response = self.get_html('/create/%s' % exp_id) + response = self.get_response('/create/%s' % exp_id) self.assertEqual(response.status_int, 200) self.assert_can_edit(response.body) self.logout() @@ -1036,7 +1041,7 @@ def test_for_assign_role_for_exploration(self): exploration.states['State 2'].update_interaction_id('TextInput') exploration.states['State 3'].update_interaction_id('TextInput') - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.EDITOR_URL_PREFIX, exp_id)) csrf_token = self.get_csrf_token_from_response(response) @@ -1071,7 +1076,7 @@ def test_for_assign_role_for_exploration(self): # Check that viewer can access editor page but cannot edit. self.login(self.VIEWER_EMAIL) - response = self.get_html('/create/%s' % exp_id) + response = self.get_response('/create/%s' % exp_id) self.assertEqual(response.status_int, 200) self.assert_cannot_edit(response.body) self.assert_cannot_translate(response.body) @@ -1079,7 +1084,7 @@ def test_for_assign_role_for_exploration(self): # Check that collaborator can access editor page and can edit. self.login(self.COLLABORATOR_EMAIL) - response = self.get_html('/create/%s' % exp_id) + response = self.get_response('/create/%s' % exp_id) self.assertEqual(response.status_int, 200) self.assert_can_edit(response.body) self.assert_can_translate(response.body) @@ -1123,7 +1128,7 @@ def test_for_assign_role_for_exploration(self): # Check that collaborator2 can access editor page and can edit. self.login(self.COLLABORATOR2_EMAIL) - response = self.get_html('/create/%s' % exp_id) + response = self.get_response('/create/%s' % exp_id) self.assertEqual(response.status_int, 200) self.assert_can_edit(response.body) csrf_token = self.get_csrf_token_from_response(response) @@ -1166,7 +1171,7 @@ def test_for_assign_role_for_exploration(self): # Check that translator can access editor page and can only translate. self.login(self.TRANSLATOR_EMAIL) - response = self.get_html('/create/%s' % exp_id) + response = self.get_response('/create/%s' % exp_id) self.assertEqual(response.status_int, 200) self.assert_cannot_edit(response.body) self.assert_can_translate(response.body) @@ -1196,7 +1201,7 @@ def test_transfering_ownership_to_the_community(self): self.save_new_valid_exploration( exp_id, self.owner_id, title='My Exploration', end_state_name='END') - response = self.get_html('/create/%s' % exp_id) + response = self.get_response('/create/%s' % exp_id) csrf_token = self.get_csrf_token_from_response(response) rights_manager.publish_exploration(self.owner, exp_id) @@ -1222,7 +1227,7 @@ def test_transfering_ownership_to_the_community(self): # Check that any random user can access editor page and can edit. self.login(self.RANDOM_USER_EMAIL) - response = self.get_html('/create/%s' % exp_id) + response = self.get_response('/create/%s' % exp_id) self.assertEqual(response.status_int, 200) self.assert_can_edit(response.body) @@ -1244,7 +1249,7 @@ def test_user_exploration_emails_handler(self): exploration = exp_services.get_exploration_by_id(exp_id) - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.EDITOR_URL_PREFIX, exp_id)) csrf_token = self.get_csrf_token_from_response(response) @@ -1327,7 +1332,7 @@ def test_error_cases_for_email_sending(self): self.login(self.MODERATOR_EMAIL) # Go to the exploration editor page. - response = self.get_html('/create/%s' % self.EXP_ID) + response = self.get_response('/create/%s' % self.EXP_ID) self.assertEqual(response.status_int, 200) csrf_token = self.get_csrf_token_from_response(response) @@ -1383,7 +1388,7 @@ def test_email_is_sent_correctly_when_unpublishing(self): self.login(self.MODERATOR_EMAIL) # Go to the exploration editor page. - response = self.get_html('/create/%s' % self.EXP_ID) + response = self.get_response('/create/%s' % self.EXP_ID) self.assertEqual(response.status_int, 200) csrf_token = self.get_csrf_token_from_response(response) @@ -1445,7 +1450,7 @@ def test_email_functionality_cannot_be_used_by_non_moderators(self): self.login(self.EDITOR_EMAIL) # Go to the exploration editor page. - response = self.get_html('/create/%s' % self.EXP_ID) + response = self.get_response('/create/%s' % self.EXP_ID) self.assertEqual(response.status_int, 200) csrf_token = self.get_csrf_token_from_response(response) @@ -1699,7 +1704,7 @@ def setUp(self): 'is_valid': True } - response = self.get_html('/create/%s' % self.EXP_ID) + response = self.get_response('/create/%s' % self.EXP_ID) self.csrf_token = self.get_csrf_token_from_response(response) def test_resolve_issue_handler(self): @@ -1811,7 +1816,7 @@ def setUp(self): self._create_exp_user_data_model_objects_for_tests() # Generate CSRF token. - response = self.get_html('/create/%s' % self.EXP_ID1) + response = self.get_response('/create/%s' % self.EXP_ID1) self.csrf_token = self.get_csrf_token_from_response(response) def test_exploration_loaded_with_draft_applied(self): diff --git a/core/controllers/email_dashboard_test.py b/core/controllers/email_dashboard_test.py index 33f145c57189..6bc1fca1b5f7 100644 --- a/core/controllers/email_dashboard_test.py +++ b/core/controllers/email_dashboard_test.py @@ -44,7 +44,7 @@ def setUp(self): def test_that_handler_works_correctly(self): self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_html('/emaildashboard')) + self.get_response('/emaildashboard')) self.post_json( '/emaildashboarddatahandler', { 'data': { @@ -83,15 +83,15 @@ def test_that_page_is_accessible_to_authorised_users_only(self): # Make sure that only authorised users can access query pages. self.login(self.USER_A_EMAIL) with self.assertRaisesRegexp(Exception, '401 Unauthorized'): - self.get_html('/emaildashboard') + self.get_response('/emaildashboard') with self.assertRaisesRegexp(Exception, '401 Unauthorized'): - self.get_html('/querystatuscheck') + self.get_response('/querystatuscheck') self.logout() def test_that_exception_is_raised_for_invalid_input(self): self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_html('/emaildashboard')) + self.get_response('/emaildashboard')) self.post_json( '/emaildashboarddatahandler', { 'data': { @@ -157,7 +157,7 @@ def setUp(self): def test_that_correct_emails_are_sent_to_all_users(self): self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_html('/emaildashboard')) + self.get_response('/emaildashboard')) self.post_json( '/emaildashboarddatahandler', { 'data': { @@ -195,7 +195,7 @@ def test_that_correct_emails_are_sent_to_all_users(self): # Send email from email dashboard result page. self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_html('/emaildashboardresult/%s' % query_model.id)) + self.get_response('/emaildashboardresult/%s' % query_model.id)) self.post_json( '/emaildashboardresult/%s' % query_model.id, { 'data': { @@ -256,10 +256,10 @@ def test_that_valid_exceptions_are_raised(self): # Check that exception is raised for incorrect query id. self.login(self.SUBMITTER_EMAIL) with self.assertRaisesRegexp(Exception, '400 Bad Request'): - self.get_html('/emaildashboardresult/%s' % 'q123') + self.get_response('/emaildashboardresult/%s' % 'q123') csrf_token = self.get_csrf_token_from_response( - self.get_html('/emaildashboard')) + self.get_response('/emaildashboard')) self.post_json( '/emaildashboarddatahandler', { 'data': { @@ -276,7 +276,7 @@ def test_that_valid_exceptions_are_raised(self): self.assertEqual( query_models[0].query_status, feconf.USER_QUERY_STATUS_PROCESSING) with self.assertRaisesRegexp(Exception, '400 Bad Request'): - self.get_html('/emaildashboardresult/%s' % query_models[0].id) + self.get_response('/emaildashboardresult/%s' % query_models[0].id) self.logout() # Complete execution of query. @@ -293,14 +293,14 @@ def test_that_valid_exceptions_are_raised(self): # Check that exception is raised for unauthorized user. self.login(self.USER_A_EMAIL) with self.assertRaisesRegexp(Exception, '401 Unauthorized'): - self.get_html('/emaildashboardresult/%s' % query_models[0].id) + self.get_response('/emaildashboardresult/%s' % query_models[0].id) self.logout() # Check that exception is raised if current user is not submitter of # that query. self.login(self.NEW_SUBMITTER_EMAIL) with self.assertRaisesRegexp(Exception, '401 Unauthorized'): - self.get_html('/emaildashboardresult/%s' % query_models[0].id) + self.get_response('/emaildashboardresult/%s' % query_models[0].id) self.logout() # Check that exception is raised for accessing query result after @@ -309,7 +309,7 @@ def test_that_valid_exceptions_are_raised(self): # Send email from email dashboard result page. self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_html( + self.get_response( '/emaildashboardresult/%s' % query_models[0].id)) self.post_json( '/emaildashboardresult/%s' % query_models[0].id, { @@ -326,13 +326,13 @@ def test_that_valid_exceptions_are_raised(self): query_models[0].query_status, feconf.USER_QUERY_STATUS_ARCHIVED) self.login(self.SUBMITTER_EMAIL) with self.assertRaisesRegexp(Exception, '400 Bad Request'): - self.get_html('/emaildashboardresult/%s' % query_models[0].id) + self.get_response('/emaildashboardresult/%s' % query_models[0].id) self.logout() def test_that_correct_emails_are_sent_to_max_n_recipients(self): self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_html('/emaildashboard')) + self.get_response('/emaildashboard')) self.post_json( '/emaildashboarddatahandler', { 'data': { @@ -356,7 +356,7 @@ def test_that_correct_emails_are_sent_to_max_n_recipients(self): # Send email from email dashboard result page. self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_html( + self.get_response( '/emaildashboardresult/%s' % query_models[0].id)) self.post_json( '/emaildashboardresult/%s' % query_models[0].id, { @@ -380,7 +380,7 @@ def test_that_correct_emails_are_sent_to_max_n_recipients(self): def test_that_no_emails_are_sent_if_query_is_canceled(self): self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_html('/emaildashboard')) + self.get_response('/emaildashboard')) self.post_json( '/emaildashboarddatahandler', { 'data': { @@ -404,7 +404,7 @@ def test_that_no_emails_are_sent_if_query_is_canceled(self): # Send email from email dashboard result page. self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_html( + self.get_response( '/emaildashboardresult/%s' % query_models[0].id)) self.post_json( '/emaildashboardcancelresult/%s' % query_models[0].id, {}, @@ -420,7 +420,7 @@ def test_that_no_emails_are_sent_if_query_is_canceled(self): def test_that_test_email_for_bulk_emails_is_sent(self): self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_html('/emaildashboard')) + self.get_response('/emaildashboard')) self.post_json( '/emaildashboarddatahandler', { 'data': { @@ -444,7 +444,7 @@ def test_that_test_email_for_bulk_emails_is_sent(self): # Check that correct test email is sent. self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_html( + self.get_response( '/emaildashboardresult/%s' % query_models[0].id)) self.post_json( '/emaildashboardtestbulkemailhandler/%s' % query_models[0].id, { @@ -484,7 +484,7 @@ def test_that_test_email_for_bulk_emails_is_sent(self): def test_that_test_email_is_not_sent_to_query_recipients(self): self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_html('/emaildashboard')) + self.get_response('/emaildashboard')) self.post_json( '/emaildashboarddatahandler', { 'data': { @@ -504,7 +504,7 @@ def test_that_test_email_is_not_sent_to_query_recipients(self): self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_html( + self.get_response( '/emaildashboardresult/%s' % query_models[0].id)) self.post_json( '/emaildashboardtestbulkemailhandler/%s' % query_models[0].id, { diff --git a/core/controllers/feedback_test.py b/core/controllers/feedback_test.py index 7533397adfa4..10b528c05171 100644 --- a/core/controllers/feedback_test.py +++ b/core/controllers/feedback_test.py @@ -54,7 +54,7 @@ def setUp(self): # The corresponding user has already registered as an editor, and has a # username. self.login(self.EDITOR_EMAIL) - response = self.get_html('/create/%s' % self.EXP_ID) + response = self.get_response('/create/%s' % self.EXP_ID) self.csrf_token = self.get_csrf_token_from_response(response) self.post_json('%s/%s' % ( feconf.FEEDBACK_THREADLIST_URL_PREFIX, self.EXP_ID @@ -133,7 +133,7 @@ def setUp(self): def test_create_thread(self): self.login(self.EDITOR_EMAIL) - response = self.get_html('/create/%s' % self.EXP_ID) + response = self.get_response('/create/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.post_json( '%s/%s' % (feconf.FEEDBACK_THREADLIST_URL_PREFIX, self.EXP_ID), { @@ -166,7 +166,7 @@ def test_create_thread(self): def test_missing_thread_subject_raises_400_error(self): self.login(self.EDITOR_EMAIL) - response = self.get_html('/create/%s' % self.EXP_ID) + response = self.get_response('/create/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) response_dict = self.post_json( '%s/%s' % (feconf.FEEDBACK_THREADLIST_URL_PREFIX, self.EXP_ID), { @@ -180,7 +180,7 @@ def test_missing_thread_subject_raises_400_error(self): def test_missing_thread_text_raises_400_error(self): self.login(self.EDITOR_EMAIL) - response = self.get_html('/create/%s' % self.EXP_ID) + response = self.get_response('/create/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) response_dict = self.post_json( '%s/%s' % (feconf.FEEDBACK_THREADLIST_URL_PREFIX, self.EXP_ID), @@ -196,7 +196,7 @@ def test_missing_thread_text_raises_400_error(self): def test_post_message_to_existing_thread(self): self.login(self.EDITOR_EMAIL) - response = self.get_html('/create/%s' % self.EXP_ID) + response = self.get_response('/create/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) # First, create a thread. @@ -256,7 +256,7 @@ def test_no_username_shown_for_logged_out_learners(self): exp_services.save_new_exploration(self.editor_id, exploration) rights_manager.publish_exploration(self.editor, new_exp_id) - response = self.get_html('/create/%s' % new_exp_id) + response = self.get_response('/create/%s' % new_exp_id) csrf_token = self.get_csrf_token_from_response(response) self.post_json( '/explorehandler/give_feedback/%s' % new_exp_id, @@ -279,7 +279,7 @@ def test_no_username_shown_for_logged_out_learners(self): def test_message_id_assignment_for_multiple_posts_to_same_thread(self): # Create a thread for others to post to. self.login(self.EDITOR_EMAIL) - response = self.get_html('/create/%s' % self.EXP_ID) + response = self.get_response('/create/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.post_json( '%s/%s' % (feconf.FEEDBACK_THREADLIST_URL_PREFIX, self.EXP_ID), { @@ -311,7 +311,7 @@ def _get_email(index): # Each of these users posts a new message to the same thread. for num in range(num_users): self.login(_get_email(num)) - response = self.get_html('/create/%s' % self.EXP_ID) + response = self.get_response('/create/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.post_json( thread_url, { @@ -393,7 +393,7 @@ def _get_message_ids_in_a_thread(self, thread_id): def test_feedback_threads(self): self.login(self.USER_EMAIL) - response = self.get_html(feconf.LIBRARY_INDEX_URL) + response = self.get_response(feconf.LIBRARY_INDEX_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json('%s/%s' % ( @@ -420,7 +420,7 @@ def test_feedback_threads(self): self.logout() self.login(self.OWNER_EMAIL_1) - response = self.get_html(feconf.LIBRARY_INDEX_URL) + response = self.get_response(feconf.LIBRARY_INDEX_URL) csrf_token = self.get_csrf_token_from_response(response) # The owner opens the feedback thread. @@ -450,7 +450,7 @@ def test_feedback_threads(self): self.logout() self.login(self.USER_EMAIL) - response = self.get_html(feconf.LIBRARY_INDEX_URL) + response = self.get_response(feconf.LIBRARY_INDEX_URL) csrf_token = self.get_csrf_token_from_response(response) # The user opens the feedback thread. @@ -480,7 +480,7 @@ def test_feedback_threads(self): # Another owner logs in. self.login(self.OWNER_EMAIL_2) - response = self.get_html(feconf.LIBRARY_INDEX_URL) + response = self.get_response(feconf.LIBRARY_INDEX_URL) csrf_token = self.get_csrf_token_from_response(response) # The second owner opens the feedback thread. diff --git a/core/controllers/learner_dashboard_test.py b/core/controllers/learner_dashboard_test.py index 7445655e0f60..b1d6320f6702 100644 --- a/core/controllers/learner_dashboard_test.py +++ b/core/controllers/learner_dashboard_test.py @@ -252,7 +252,7 @@ def setUp(self): # Get the CSRF token and create a single thread with a single message. self.login(self.EDITOR_EMAIL) - response = self.get_html('/create/%s' % self.EXP_ID_1) + response = self.get_response('/create/%s' % self.EXP_ID_1) self.csrf_token = self.get_csrf_token_from_response(response) self.post_json('%s/%s' % ( feconf.FEEDBACK_THREADLIST_URL_PREFIX, self.EXP_ID_1 diff --git a/core/controllers/learner_playlist_test.py b/core/controllers/learner_playlist_test.py index 6137bcd17add..d80cdbba6c5d 100644 --- a/core/controllers/learner_playlist_test.py +++ b/core/controllers/learner_playlist_test.py @@ -71,7 +71,7 @@ def setUp(self): def test_add_exploration_to_learner_playlist(self): self.login(self.VIEWER_EMAIL) - response = self.get_html(feconf.LEARNER_DASHBOARD_URL) + response = self.get_response(feconf.LEARNER_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) # Add one exploration to the playlist. @@ -169,7 +169,7 @@ def test_add_exploration_to_learner_playlist(self): def test_add_collection_to_learner_playlist(self): self.login(self.VIEWER_EMAIL) - response = self.get_html(feconf.LEARNER_DASHBOARD_URL) + response = self.get_response(feconf.LEARNER_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) # Add one collection to the playlist. diff --git a/core/controllers/library_test.py b/core/controllers/library_test.py index 9d94e0a8c0f0..d0f8d6f3d948 100644 --- a/core/controllers/library_test.py +++ b/core/controllers/library_test.py @@ -45,7 +45,7 @@ def setUp(self): def test_library_page(self): """Test access to the library page.""" - response = self.get_html(feconf.LIBRARY_INDEX_URL) + response = self.get_response(feconf.LIBRARY_INDEX_URL) self.assertEqual(response.status_int, 200) response.mustcontain('Library - Oppia') @@ -199,10 +199,10 @@ class LibraryGroupPageTest(test_utils.GenericTestBase): def test_library_group_pages(self): """Test access to the top rated and recently published pages.""" - response = self.get_html(feconf.LIBRARY_TOP_RATED_URL) + response = self.get_response(feconf.LIBRARY_TOP_RATED_URL) self.assertEqual(response.status_int, 200) - response = self.get_html(feconf.LIBRARY_RECENTLY_PUBLISHED_URL) + response = self.get_response(feconf.LIBRARY_RECENTLY_PUBLISHED_URL) self.assertEqual(response.status_int, 200) def test_handler_for_recently_published_library_group_page(self): diff --git a/core/controllers/moderator_test.py b/core/controllers/moderator_test.py index 56b17a992fe9..7c4c5a6c9427 100644 --- a/core/controllers/moderator_test.py +++ b/core/controllers/moderator_test.py @@ -24,14 +24,14 @@ class ModeratorTest(test_utils.GenericTestBase): def test_moderator_page(self): """Tests access to the Moderator page.""" # Try accessing the moderator page without logging in. - response = self.get_html('/moderator', expected_status_int=302) + response = self.get_response('/moderator', expected_status_int=302) self.assertEqual(response.status_int, 302) # Try accessing the moderator page without being a moderator or admin. self.signup(self.VIEWER_EMAIL, self.VIEWER_USERNAME) self.login(self.VIEWER_EMAIL) - response = self.get_html('/moderator', expect_errors=True, - expected_status_int=401) + response = self.get_response('/moderator', expect_errors=True, + expected_status_int=401) self.assertEqual(response.status_int, 401) self.logout() @@ -39,7 +39,7 @@ def test_moderator_page(self): self.signup(self.MODERATOR_EMAIL, self.MODERATOR_USERNAME) self.set_moderators([self.MODERATOR_USERNAME]) self.login(self.MODERATOR_EMAIL) - response = self.get_html('/moderator') + response = self.get_response('/moderator') self.assertEqual(response.status_int, 200) self.logout() @@ -47,7 +47,7 @@ def test_moderator_page(self): self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.set_admins([self.ADMIN_USERNAME]) self.login(self.ADMIN_EMAIL) - response = self.get_html('/moderator') + response = self.get_response('/moderator') self.assertEqual(response.status_int, 200) self.logout() @@ -73,7 +73,7 @@ def setUp(self): def test_unpublished_activities_cannot_be_added_to_featured_list(self): self.login(self.MODERATOR_EMAIL) - response = self.get_html('/moderator') + response = self.get_response('/moderator') self.assertEqual(response.status_int, 200) csrf_token = self.get_csrf_token_from_response(response) diff --git a/core/controllers/pages_test.py b/core/controllers/pages_test.py index a1899fa6bc8a..71377e2a7606 100644 --- a/core/controllers/pages_test.py +++ b/core/controllers/pages_test.py @@ -21,7 +21,7 @@ class NoninteractivePagesTest(test_utils.GenericTestBase): def test_about_page(self): """Test the About page.""" - response = self.get_html('/about') + response = self.get_response('/about') self.assertEqual(response.status_int, 200) self.assertEqual(response.content_type, 'text/html') response.mustcontain( diff --git a/core/controllers/profile_test.py b/core/controllers/profile_test.py index 487c7999233f..ddbcbea9f5e2 100644 --- a/core/controllers/profile_test.py +++ b/core/controllers/profile_test.py @@ -29,7 +29,7 @@ class SignupTest(test_utils.GenericTestBase): def test_signup_page_does_not_have_top_right_menu(self): self.login(self.EDITOR_EMAIL) - response = self.get_html(feconf.SIGNUP_URL) + response = self.get_response(feconf.SIGNUP_URL) self.assertEqual(response.status_int, 200) # Sign in can't be inside an html tag, but can appear inside js code. response.mustcontain(no=['Logout']) @@ -39,9 +39,9 @@ def test_going_somewhere_else_while_signing_in_logs_user_out(self): exp_services.load_demo('0') self.login(self.EDITOR_EMAIL) - response = self.get_html(feconf.SIGNUP_URL) + response = self.get_response(feconf.SIGNUP_URL) self.assertEqual(response.status_int, 200) - response = self.get_html('/create/0', expected_status_int=302) + response = self.get_response('/create/0', expected_status_int=302) self.assertEqual(response.status_int, 302) self.assertIn('Logout', response.headers['location']) self.assertIn('create', response.headers['location']) @@ -50,7 +50,7 @@ def test_going_somewhere_else_while_signing_in_logs_user_out(self): def test_accepting_terms_is_handled_correctly(self): self.login(self.EDITOR_EMAIL) - response = self.get_html(feconf.SIGNUP_URL) + response = self.get_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) response_dict = self.post_json( @@ -76,7 +76,7 @@ def test_accepting_terms_is_handled_correctly(self): def test_username_is_handled_correctly(self): self.login(self.EDITOR_EMAIL) - response = self.get_html(feconf.SIGNUP_URL) + response = self.get_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) response_dict = self.post_json( @@ -117,7 +117,7 @@ def test_username_is_handled_correctly(self): def test_default_dashboard_for_new_users(self): self.login(self.EDITOR_EMAIL) - response = self.get_html(feconf.SIGNUP_URL) + response = self.get_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) # This user should have the creator dashboard as default. @@ -136,7 +136,7 @@ def test_default_dashboard_for_new_users(self): self.logout() self.login(self.VIEWER_EMAIL) - response = self.get_html(feconf.SIGNUP_URL) + response = self.get_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) # This user should have the learner dashboard as default. @@ -161,7 +161,7 @@ def test_username_check(self): self.signup('abc@example.com', username='abc') self.login(self.EDITOR_EMAIL) - response = self.get_html(feconf.SIGNUP_URL) + response = self.get_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) response_dict = self.post_json( @@ -202,7 +202,7 @@ class EmailPreferencesTests(test_utils.GenericTestBase): def test_user_not_setting_email_prefs_on_signup(self): self.login(self.EDITOR_EMAIL) - response = self.get_html(feconf.SIGNUP_URL) + response = self.get_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( feconf.SIGNUP_DATA_URL, @@ -239,7 +239,7 @@ def test_user_not_setting_email_prefs_on_signup(self): def test_user_allowing_emails_on_signup(self): self.login(self.EDITOR_EMAIL) - response = self.get_html(feconf.SIGNUP_URL) + response = self.get_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( feconf.SIGNUP_DATA_URL, @@ -276,7 +276,7 @@ def test_user_allowing_emails_on_signup(self): def test_user_disallowing_emails_on_signup(self): self.login(self.EDITOR_EMAIL) - response = self.get_html(feconf.SIGNUP_URL) + response = self.get_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( feconf.SIGNUP_DATA_URL, @@ -320,7 +320,7 @@ def test_email_preferences_updates(self): self.signup(self.EDITOR_EMAIL, username=self.EDITOR_USERNAME) editor_id = self.get_user_id_from_email(self.EDITOR_EMAIL) self.login(self.EDITOR_EMAIL) - response = self.get_html('/preferences') + response = self.get_response('/preferences') csrf_token = self.get_csrf_token_from_response(response) payload = { @@ -427,7 +427,7 @@ class ProfileDataHandlerTests(test_utils.GenericTestBase): def test_preference_page_updates(self): self.signup(self.EDITOR_EMAIL, username=self.EDITOR_USERNAME) self.login(self.EDITOR_EMAIL) - response = self.get_html('/preferences') + response = self.get_response('/preferences') csrf_token = self.get_csrf_token_from_response(response) original_preferences = self.get_json('/preferenceshandler/data') self.assertEqual( @@ -455,7 +455,7 @@ def test_preference_page_updates(self): def test_profile_data_is_independent_of_currently_logged_in_user(self): self.signup(self.EDITOR_EMAIL, username=self.EDITOR_USERNAME) self.login(self.EDITOR_EMAIL) - response = self.get_html('/preferences') + response = self.get_response('/preferences') csrf_token = self.get_csrf_token_from_response(response) self.put_json( '/preferenceshandler/data', @@ -469,7 +469,7 @@ def test_profile_data_is_independent_of_currently_logged_in_user(self): self.signup(self.VIEWER_EMAIL, username=self.VIEWER_USERNAME) self.login(self.VIEWER_EMAIL) - response = self.get_html('/preferences') + response = self.get_response('/preferences') csrf_token = self.get_csrf_token_from_response(response) self.put_json( '/preferenceshandler/data', @@ -629,7 +629,7 @@ def test_save_site_language_handler(self): self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME) language_code = 'es' self.login(self.EDITOR_EMAIL) - response = self.get_html('/preferences') + response = self.get_response('/preferences') self.assertEqual(response.status_int, 200) csrf_token = self.get_csrf_token_from_response(response) self.put_json( @@ -655,7 +655,7 @@ class LongUserBioHandlerTests(test_utils.GenericTestBase): def test_userbio_within_limit(self): self.signup(self.EMAIL_A, self.USERNAME_A) self.login(self.EMAIL_A) - response = self.get_html('/preferences') + response = self.get_response('/preferences') self.assertEqual(response.status_int, 200) csrf_token = self.get_csrf_token_from_response(response) self.put_json( @@ -672,7 +672,7 @@ def test_userbio_within_limit(self): def test_user_bio_exceeds_limit(self): self.signup(self.EMAIL_B, self.USERNAME_B) self.login(self.EMAIL_B) - response = self.get_html('/preferences') + response = self.get_response('/preferences') self.assertEqual(response.status_int, 200) csrf_token = self.get_csrf_token_from_response(response) user_bio_response = self.put_json( diff --git a/core/controllers/question_editor_test.py b/core/controllers/question_editor_test.py index 6fd1d3ba7b36..887c9fe09976 100644 --- a/core/controllers/question_editor_test.py +++ b/core/controllers/question_editor_test.py @@ -78,7 +78,7 @@ def test_post(self): self.logout() self.login(self.ADMIN_EMAIL) - response = self.get_html(feconf.CREATOR_DASHBOARD_URL) + response = self.get_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) question_dict = self.question.to_dict() question_dict['id'] = None @@ -96,7 +96,7 @@ def test_post(self): self.logout() self.login(self.TOPIC_MANAGER_EMAIL) - response = self.get_html(feconf.CREATOR_DASHBOARD_URL) + response = self.get_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) question_dict = self.question.to_dict() question_dict['id'] = None @@ -131,7 +131,7 @@ def setUp(self): def test_post(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): self.login(self.NEW_USER_EMAIL) - response = self.get_html(feconf.CREATOR_DASHBOARD_URL) + response = self.get_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) response = self.testapp.post( '%s/%s/%s' % ( @@ -142,7 +142,7 @@ def test_post(self): self.logout() self.login(self.ADMIN_EMAIL) - response = self.get_html(feconf.CREATOR_DASHBOARD_URL) + response = self.get_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( '%s/%s/%s' % ( @@ -158,7 +158,7 @@ def test_post(self): self.logout() self.login(self.TOPIC_MANAGER_EMAIL) - response = self.get_html(feconf.CREATOR_DASHBOARD_URL) + response = self.get_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( '%s/%s/%s' % ( @@ -225,7 +225,7 @@ def test_get(self): # Check that non-admin and topic_manager cannot access the editor # data. self.login(self.NEW_USER_EMAIL) - response = self.get_html( + response = self.get_response( '%s/%s' % ( feconf.QUESTION_EDITOR_DATA_URL_PREFIX, self.question_id), expect_errors=True, expected_status_int=401) @@ -292,7 +292,7 @@ def test_put(self): payload['commit_message'] = 'update question data' self.login(self.ADMIN_EMAIL) - response = self.get_html(feconf.CREATOR_DASHBOARD_URL) + response = self.get_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) response_json = self.put_json( '%s/%s' % ( @@ -333,7 +333,7 @@ def test_put(self): self.logout() self.login(self.TOPIC_MANAGER_EMAIL) - response = self.get_html(feconf.CREATOR_DASHBOARD_URL) + response = self.get_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) payload = {} new_question_data = self._create_valid_question_data('GHI') @@ -363,7 +363,7 @@ def test_put(self): # Check that the question creator can edit the question. self.login(self.EDITOR_EMAIL) - response = self.get_html(feconf.CREATOR_DASHBOARD_URL) + response = self.get_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) payload = {} new_question_data = self._create_valid_question_data('GHI') diff --git a/core/controllers/reader_test.py b/core/controllers/reader_test.py index 2c9dcf91d26f..e8718d7e06cc 100644 --- a/core/controllers/reader_test.py +++ b/core/controllers/reader_test.py @@ -58,7 +58,7 @@ def setUp(self): category=self.UNICODE_TEST_STRING) def test_unpublished_explorations_are_invisible_to_logged_out_users(self): - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID), expect_errors=True, expected_status_int=404) self.assertEqual(response.status_int, 404) @@ -66,7 +66,7 @@ def test_unpublished_explorations_are_invisible_to_logged_out_users(self): def test_unpublished_explorations_are_invisible_to_unconnected_users(self): self.signup(self.VIEWER_EMAIL, self.VIEWER_USERNAME) self.login(self.VIEWER_EMAIL) - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID), expect_errors=True, expected_status_int=404) self.assertEqual(response.status_int, 404) @@ -82,7 +82,7 @@ def test_unpublished_explorations_are_invisible_to_other_editors(self): other_editor_email, other_exploration) self.login(other_editor_email) - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID), expect_errors=True, expected_status_int=404) self.assertEqual(response.status_int, 404) @@ -90,7 +90,7 @@ def test_unpublished_explorations_are_invisible_to_other_editors(self): def test_unpublished_explorations_are_visible_to_their_editors(self): self.login(self.EDITOR_EMAIL) - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID)) self.assertEqual(response.status_int, 200) self.logout() @@ -99,7 +99,7 @@ def test_unpublished_explorations_are_visible_to_admins(self): self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.set_admins([self.ADMIN_USERNAME]) self.login(self.ADMIN_EMAIL) - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID)) self.assertEqual(response.status_int, 200) self.logout() @@ -107,7 +107,7 @@ def test_unpublished_explorations_are_visible_to_admins(self): def test_published_explorations_are_visible_to_logged_out_users(self): rights_manager.publish_exploration(self.editor, self.EXP_ID) - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID)) self.assertEqual(response.status_int, 200) @@ -116,7 +116,7 @@ def test_published_explorations_are_visible_to_logged_in_users(self): self.signup(self.VIEWER_EMAIL, self.VIEWER_USERNAME) self.login(self.VIEWER_EMAIL) - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID)) self.assertEqual(response.status_int, 200) @@ -268,13 +268,13 @@ def test_get_exploration_pretests(self): json_response_1['pretest_question_dicts'][0]['id'], json_response_2['pretest_question_dicts'][0]['id']) - response = self.get_html( + response = self.get_response( '%s/%s?story_id=%s' % ( feconf.EXPLORATION_PRETESTS_URL_PREFIX, exp_id_2, STORY_ID), expect_errors=True, expected_status_int=400) self.assertEqual(response.status_int, 400) - response = self.get_html( + response = self.get_response( '%s/%s?story_id=%s' % ( feconf.EXPLORATION_PRETESTS_URL_PREFIX, exp_id_2, 'story'), expect_errors=True, expected_status_int=400) @@ -353,7 +353,7 @@ def test_assign_and_read_ratings(self): self.signup('user@example.com', 'user') self.login('user@example.com') csrf_token = self.get_csrf_token_from_response( - self.get_html('/explore/%s' % self.EXP_ID)) + self.get_response('/explore/%s' % self.EXP_ID)) # User checks rating. ratings = self.get_json('/explorehandler/rating/%s' % self.EXP_ID) @@ -395,7 +395,7 @@ def test_non_logged_in_users_cannot_rate(self): self.signup('user@example.com', 'user') self.login('user@example.com') csrf_token = self.get_csrf_token_from_response( - self.get_html('/explore/%s' % self.EXP_ID)) + self.get_response('/explore/%s' % self.EXP_ID)) self.logout() ratings = self.get_json('/explorehandler/rating/%s' % self.EXP_ID) @@ -418,7 +418,7 @@ def test_ratings_by_different_users(self): self.login('a@example.com') csrf_token = self.get_csrf_token_from_response( - self.get_html('/explore/%s' % self.EXP_ID)) + self.get_response('/explore/%s' % self.EXP_ID)) self.put_json( '/explorehandler/rating/%s' % self.EXP_ID, { 'user_rating': 4 @@ -428,7 +428,7 @@ def test_ratings_by_different_users(self): self.login('b@example.com') csrf_token = self.get_csrf_token_from_response( - self.get_html('/explore/%s' % self.EXP_ID)) + self.get_response('/explore/%s' % self.EXP_ID)) ratings = self.get_json('/explorehandler/rating/%s' % self.EXP_ID) self.assertEqual(ratings['user_rating'], None) self.put_json( @@ -499,7 +499,7 @@ def _get_recommendation_ids( exploration_id, author_recommended_ids_str, collection_id_param, include_recommendations_param)) - response = self.get_html('/explore/%s' % exploration_id) + response = self.get_response('/explore/%s' % exploration_id) csrf_token = self.get_csrf_token_from_response(response) summaries = self.get_json( recommendations_url, params=csrf_token)['summaries'] @@ -925,7 +925,7 @@ def test_that_emails_are_sent(self): # Login and flag exploration. self.login(self.NEW_USER_EMAIL) - response = self.get_html('/explore/%s' % self.EXP_ID) + response = self.get_response('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.post_json( @@ -981,7 +981,7 @@ def test_non_logged_in_users_cannot_report(self): self.login(self.NEW_USER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_html('/explore/%s' % self.EXP_ID)) + self.get_response('/explore/%s' % self.EXP_ID)) self.logout() # Create report for exploration. @@ -1066,7 +1066,7 @@ def test_independent_exp_complete_event_handler(self): """ self.login(self.USER_EMAIL) - response = self.get_html(feconf.LIBRARY_INDEX_URL) + response = self.get_response(feconf.LIBRARY_INDEX_URL) csrf_token = self.get_csrf_token_from_response(response) payload = { @@ -1104,7 +1104,7 @@ def test_exp_complete_event_in_collection(self): """ self.login(self.USER_EMAIL) - response = self.get_html(feconf.LIBRARY_INDEX_URL) + response = self.get_response(feconf.LIBRARY_INDEX_URL) csrf_token = self.get_csrf_token_from_response(response) payload = { @@ -1149,7 +1149,7 @@ def test_exp_incomplete_event_handler(self): """Test handler for leaving an exploration incomplete.""" self.login(self.USER_EMAIL) - response = self.get_html(feconf.LIBRARY_INDEX_URL) + response = self.get_response(feconf.LIBRARY_INDEX_URL) csrf_token = self.get_csrf_token_from_response(response) payload = { @@ -1343,7 +1343,7 @@ def setUp(self): }] } - response = self.get_html('/explore/%s' % self.exp_id) + response = self.get_response('/explore/%s' % self.exp_id) self.csrf_token = self.get_csrf_token_from_response(response) def test_new_playthrough_gets_stored(self): diff --git a/core/controllers/resources_test.py b/core/controllers/resources_test.py index 7f1a3f50f35c..9bffb9c1b4c7 100644 --- a/core/controllers/resources_test.py +++ b/core/controllers/resources_test.py @@ -49,7 +49,7 @@ def test_image_upload_and_download(self): """Test image uploading and downloading.""" self.login(self.EDITOR_EMAIL) - response = self.get_html('/create/0') + response = self.get_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) with open(os.path.join(feconf.TESTS_DATA_DIR, 'img.png'), @@ -65,13 +65,13 @@ def test_image_upload_and_download(self): self.logout() - response = self.testapp.get(self._get_image_url('0', filename)) - self.assertEqual(response.content_type, 'image/png') + response = self.get_response(self._get_image_url('0', filename), + expected_content_type='image/png') self.assertEqual(response.body, raw_image) def test_non_matching_extensions_are_detected(self): self.login(self.EDITOR_EMAIL) - response = self.get_html('/create/0') + response = self.get_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) filename_without_extension = 'test' @@ -100,20 +100,22 @@ def test_non_matching_extensions_are_detected(self): self.logout() # Test that neither form of the image is stored. - response = self.testapp.get( + response = self.get_response( self._get_image_url('0', supplied_filename), - expect_errors=True) + expect_errors=True, expected_status_int=404, + expected_content_type='image/jpg') self.assertEqual(response.status_int, 404) - response = self.testapp.get( + response = self.get_response( self._get_image_url('0', filename_with_correct_extension), - expect_errors=True) + expect_errors=True, expected_status_int=404, + expected_content_type='image/png') self.assertEqual(response.status_int, 404) def test_upload_empty_image(self): """Test upload of an empty image.""" self.login(self.EDITOR_EMAIL) - response = self.get_html('/create/0') + response = self.get_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) # Upload an empty image. @@ -134,7 +136,7 @@ def test_upload_bad_image(self): """Test upload of a malformed image.""" self.login(self.EDITOR_EMAIL) - response = self.get_html('/create/0') + response = self.get_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) # Upload an invalid image. @@ -154,16 +156,17 @@ def test_upload_bad_image(self): def test_get_invalid_image(self): """Test retrieval of invalid images.""" - response = self.testapp.get( + response = self.get_response( self._get_image_url('0', 'bad_image'), - expect_errors=True) + expect_errors=True, expected_status_int=404, + expected_content_type='image/bad_image') self.assertEqual(response.status_int, 404) def test_bad_filenames_are_detected(self): # TODO(sll): Add more tests here. self.login(self.EDITOR_EMAIL) - response = self.get_html('/create/0') + response = self.get_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) with open(os.path.join(feconf.TESTS_DATA_DIR, 'img.png'), @@ -183,7 +186,7 @@ def test_bad_filenames_are_detected(self): def test_missing_extensions_are_detected(self): self.login(self.EDITOR_EMAIL) - response = self.get_html('/create/0') + response = self.get_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) with open(os.path.join(feconf.TESTS_DATA_DIR, 'img.png'), @@ -204,7 +207,7 @@ def test_missing_extensions_are_detected(self): def test_bad_extensions_are_detected(self): self.login(self.EDITOR_EMAIL) - response = self.get_html('/create/0') + response = self.get_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) with open(os.path.join(feconf.TESTS_DATA_DIR, 'img.png'), @@ -245,7 +248,7 @@ def setUp(self): def test_audio_upload(self): self.login(self.EDITOR_EMAIL) - response = self.get_html('/create/0') + response = self.get_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) with open(os.path.join(feconf.TESTS_DATA_DIR, self.TEST_AUDIO_FILE_MP3), @@ -261,7 +264,7 @@ def test_audio_upload(self): def test_audio_upload_mpeg_container(self): self.login(self.EDITOR_EMAIL) - response = self.get_html('/create/0') + response = self.get_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) with open(os.path.join( @@ -280,7 +283,7 @@ def test_invalid_extension_is_detected(self): """Test that invalid extensions are caught.""" self.login(self.EDITOR_EMAIL) - response = self.get_html('/create/0') + response = self.get_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) filename_without_extension = 'test' @@ -311,7 +314,7 @@ def test_upload_empty_audio(self): """Test upload of empty audio.""" self.login(self.EDITOR_EMAIL) - response = self.get_html('/create/0') + response = self.get_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) # Upload empty audio. @@ -331,7 +334,7 @@ def test_upload_bad_audio(self): """Test upload of malformed audio.""" self.login(self.EDITOR_EMAIL) - response = self.get_html('/create/0') + response = self.get_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) response_dict = self.post_json( '%s/0' % self.AUDIO_UPLOAD_URL_PREFIX, @@ -351,7 +354,7 @@ def test_missing_extensions_are_detected(self): """Test upload of filenames with no extensions are caught.""" self.login(self.EDITOR_EMAIL) - response = self.get_html('/create/0') + response = self.get_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) missing_extension_filename = 'test' @@ -378,7 +381,7 @@ def test_exceed_max_length_detected(self): """Test that audio file is less than max playback length.""" self.login(self.EDITOR_EMAIL) - response = self.get_html('/create/0') + response = self.get_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) with open(os.path.join(feconf.TESTS_DATA_DIR, @@ -405,7 +408,7 @@ def test_non_matching_extensions_are_detected(self): """ self.login(self.EDITOR_EMAIL) - response = self.get_html('/create/0') + response = self.get_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) # Use an accepted audio extension in mismatched_filename diff --git a/core/controllers/skill_editor_test.py b/core/controllers/skill_editor_test.py index 162b81ded380..c9e548603435 100644 --- a/core/controllers/skill_editor_test.py +++ b/core/controllers/skill_editor_test.py @@ -53,7 +53,7 @@ def _get_csrf_token_for_put(self): csrf_token = None url_prefix = feconf.SKILL_EDITOR_URL_PREFIX with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.get_html('%s/%s' % (url_prefix, self.skill_id)) + response = self.get_response('%s/%s' % (url_prefix, self.skill_id)) csrf_token = self.get_csrf_token_from_response(response) return csrf_token @@ -89,14 +89,14 @@ def test_access_skill_editor_page(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): # Check that non-admins cannot access the editor page. self.login(self.NEW_USER_EMAIL) - response = self.get_html( + response = self.get_response( self.url, expect_errors=True, expected_status_int=401) self.assertEqual(response.status_int, 401) self.logout() # Check that admins can access and edit in the editor page. self.login(self.ADMIN_EMAIL) - response = self.get_html(self.url) + response = self.get_response(self.url) self.assertEqual(response.status_int, 200) self.logout() @@ -104,15 +104,15 @@ def test_skill_editor_page_fails(self): self.login(self.ADMIN_EMAIL) # Check GET returns 404 when new strutures' pages are not enabled. with self.swap(constants, 'ENABLE_NEW_STRUCTURES', False): - response = self.get_html(self.url, expect_errors=True, - expected_status_int=404) + response = self.get_response(self.url, expect_errors=True, + expected_status_int=404) self.assertEqual(response.status_int, 404) # Check GET returns 404 when cannot get skill by id. self._delete_skill_model_and_memcache(self.admin_id, self.skill_id) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.get_html(self.url, expect_errors=True, - expected_status_int=404) + response = self.get_response(self.url, expect_errors=True, + expected_status_int=404) self.assertEqual(response.status_int, 404) self.logout() @@ -145,8 +145,8 @@ def test_skill_rights_handler_fails(self): skill_services_swap = self.swap( skill_services, 'get_skill_rights', self._mock_get_skill_rights) with skill_services_swap: - response = self.get_html(self.url, expect_errors=True, - expected_status_int=404) + response = self.get_response(self.url, expect_errors=True, + expected_status_int=404) self.assertEqual(response.status_int, 404) self.logout() @@ -181,14 +181,14 @@ def test_editable_skill_handler_get_fails(self): self.login(self.ADMIN_EMAIL) # Check GET returns 404 when new strutures' pages are not enabled. with self.swap(constants, 'ENABLE_NEW_STRUCTURES', False): - response = self.get_html(self.url, expect_errors=True, - expected_status_int=404) + response = self.get_response(self.url, expect_errors=True, + expected_status_int=404) self.assertEqual(response.status_int, 404) # Check GET returns 404 when cannot get skill by id. self._delete_skill_model_and_memcache(self.admin_id, self.skill_id) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.get_html(self.url, expect_errors=True, - expected_status_int=404) + response = self.get_response(self.url, expect_errors=True, + expected_status_int=404) self.assertEqual(response.status_int, 404) self.logout() diff --git a/core/controllers/story_editor_test.py b/core/controllers/story_editor_test.py index 0d38620519c8..463d04f61dc7 100644 --- a/core/controllers/story_editor_test.py +++ b/core/controllers/story_editor_test.py @@ -53,7 +53,7 @@ def test_access_story_editor_page(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): # Check that non-admins cannot access the editor page. self.login(self.NEW_USER_EMAIL) - response = self.get_html( + response = self.get_response( '%s/%s/%s' % ( feconf.STORY_EDITOR_URL_PREFIX, self.topic_id, self.story_id), expect_errors=True, expected_status_int=401) @@ -63,7 +63,7 @@ def test_access_story_editor_page(self): # Check that admins can access and edit in the editor # page. self.login(self.ADMIN_EMAIL) - response = self.get_html( + response = self.get_response( '%s/%s/%s' % ( feconf.STORY_EDITOR_URL_PREFIX, self.topic_id, self.story_id)) @@ -74,7 +74,7 @@ def test_editable_story_handler_get(self): # Check that non-admins cannot access the editable story data. with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): self.login(self.NEW_USER_EMAIL) - response = self.get_html( + response = self.get_response( '%s/%s/%s' % ( feconf.STORY_EDITOR_DATA_URL_PREFIX, self.topic_id, self.story_id), expect_errors=True, expected_status_int=401) @@ -106,7 +106,7 @@ def test_editable_story_handler_put(self): } self.login(self.ADMIN_EMAIL) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.get_html( + response = self.get_response( '%s/%s/%s' % ( feconf.STORY_EDITOR_URL_PREFIX, self.topic_id, self.story_id)) diff --git a/core/controllers/subscriptions_test.py b/core/controllers/subscriptions_test.py index 6b619edd1a2e..95b30213205b 100644 --- a/core/controllers/subscriptions_test.py +++ b/core/controllers/subscriptions_test.py @@ -44,7 +44,7 @@ def test_subscribe_handler(self): """Test handler for new subscriptions to creators.""" self.login(self.USER_EMAIL) - response = self.get_html(feconf.CREATOR_DASHBOARD_URL) + response = self.get_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) payload = { @@ -77,7 +77,7 @@ def test_subscribe_handler(self): # Test another user subscription. self.login(self.USER2_EMAIL) - response = self.get_html(feconf.CREATOR_DASHBOARD_URL) + response = self.get_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( @@ -99,7 +99,7 @@ def test_unsubscribe_handler(self): # Add one subscription to editor. self.login(self.USER_EMAIL) - response = self.get_html(feconf.CREATOR_DASHBOARD_URL) + response = self.get_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( feconf.SUBSCRIBE_URL_PREFIX, payload, @@ -108,7 +108,7 @@ def test_unsubscribe_handler(self): # Add another subscription. self.login(self.USER2_EMAIL) - response = self.get_html(feconf.CREATOR_DASHBOARD_URL) + response = self.get_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( feconf.SUBSCRIBE_URL_PREFIX, payload, @@ -140,7 +140,7 @@ def test_unsubscribe_handler(self): # Unsubscribing another user. self.login(self.USER_EMAIL) - response = self.get_html(feconf.CREATOR_DASHBOARD_URL) + response = self.get_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( feconf.UNSUBSCRIBE_URL_PREFIX, payload, diff --git a/core/controllers/suggestion_test.py b/core/controllers/suggestion_test.py index 87aed928fdba..dcb1165f4211 100644 --- a/core/controllers/suggestion_test.py +++ b/core/controllers/suggestion_test.py @@ -89,7 +89,7 @@ def setUp(self): self.logout() self.login(self.AUTHOR_EMAIL) - response = self.get_html('/explore/%s' % self.EXP_ID) + response = self.get_response('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.post_json( @@ -114,7 +114,7 @@ def setUp(self): self.logout() self.login(self.AUTHOR_EMAIL_2) - response = self.get_html('/explore/%s' % self.EXP_ID) + response = self.get_response('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.post_json( @@ -160,7 +160,7 @@ def setUp(self): def test_create_suggestion(self): self.login(self.AUTHOR_EMAIL_2) - response = self.get_html('/explore/%s' % self.EXP_ID) + response = self.get_response('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) exploration = exp_services.get_exploration_by_id(self.EXP_ID) @@ -193,7 +193,7 @@ def test_accept_suggestion(self): # Test editor can accept successfully. self.login(self.EDITOR_EMAIL) - response = self.get_html('/explore/%s' % self.EXP_ID) + response = self.get_response('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) suggestion_to_accept = self.get_json( @@ -201,7 +201,7 @@ def test_accept_suggestion(self): feconf.SUGGESTION_LIST_URL_PREFIX, self.author_id))['suggestions'][0] - response = self.get_html('/explore/%s' % self.EXP_ID) + response = self.get_response('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.put_json('%s/exploration/%s/%s' % ( feconf.SUGGESTION_ACTION_URL_PREFIX, @@ -232,7 +232,7 @@ def test_accept_suggestion(self): feconf.SUGGESTION_LIST_URL_PREFIX, self.author_id_2))['suggestions'][0] - response = self.get_html('/explore/%s' % self.EXP_ID) + response = self.get_response('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.put_json('%s/exploration/%s/%s' % ( feconf.SUGGESTION_ACTION_URL_PREFIX, @@ -252,7 +252,7 @@ def test_accept_suggestion(self): feconf.SUGGESTION_LIST_URL_PREFIX, self.author_id_2))['suggestions'][0] - response = self.get_html('/explore/%s' % self.EXP_ID) + response = self.get_response('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.put_json('%s/exploration/%s/%s' % ( feconf.SUGGESTION_ACTION_URL_PREFIX, @@ -269,7 +269,7 @@ def test_accept_suggestion(self): suggestion_services.increment_score_for_user( self.author_id, 'content.Algebra', 15) - response = self.get_html('/explore/%s' % self.EXP_ID) + response = self.get_response('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.put_json('%s/exploration/%s/%s' % ( feconf.SUGGESTION_ACTION_URL_PREFIX, @@ -291,7 +291,7 @@ def test_accept_suggestion(self): # Testing admins can accept suggestions. self.login(self.ADMIN_EMAIL) - response = self.get_html('/explore/%s' % self.EXP_ID) + response = self.get_response('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) suggestion_to_accept = self.get_json( '%s?author_id=%s' % ( @@ -325,7 +325,7 @@ def test_suggestion_list_handler(self): def test_resubmit_rejected_suggestion(self): self.login(self.EDITOR_EMAIL) - response = self.get_html('/explore/%s' % self.EXP_ID) + response = self.get_response('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) suggestion = suggestion_services.query_suggestions( @@ -335,7 +335,7 @@ def test_resubmit_rejected_suggestion(self): self.logout() self.login(self.AUTHOR_EMAIL) - response = self.get_html('/explore/%s' % self.EXP_ID) + response = self.get_response('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.put_json('%s/resubmit/%s' % ( @@ -395,7 +395,7 @@ def setUp(self): feconf.CURRENT_STATES_SCHEMA_VERSION) } self.login(self.AUTHOR_EMAIL) - response = self.get_html(feconf.CREATOR_DASHBOARD_URL) + response = self.get_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( @@ -442,7 +442,7 @@ def test_accept_question_suggestion(self): )['suggestions'][0] self.login(self.ADMIN_EMAIL) - response = self.get_html(feconf.CREATOR_DASHBOARD_URL) + response = self.get_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): self.put_json('%s/topic/%s/%s' % ( diff --git a/core/controllers/topic_editor_test.py b/core/controllers/topic_editor_test.py index b1f585bc7baa..48cf80a0d888 100644 --- a/core/controllers/topic_editor_test.py +++ b/core/controllers/topic_editor_test.py @@ -67,7 +67,7 @@ class TopicEditorStoryHandlerTest(BaseTopicEditorControllerTest): def test_story_creation(self): self.login(self.ADMIN_EMAIL) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.TOPIC_EDITOR_URL_PREFIX, self.topic_id)) csrf_token = self.get_csrf_token_from_response(response) json_response = self.post_json( @@ -117,10 +117,9 @@ def test_get(self): self.logout() self.login(self.TOPIC_MANAGER_EMAIL) - response = self.testapp.get( + response = self.get_json( '%s/%s?cursor=' % ( feconf.TOPIC_EDITOR_QUESTION_URL, self.topic_id)) - self.assertEqual(response.status_code, 200) self.logout() topic_services.assign_role( @@ -137,7 +136,7 @@ def test_get(self): self.logout() self.login(self.NEW_USER_EMAIL) - response = self.get_html( + response = self.get_response( '%s/%s?cursor=' % ( feconf.TOPIC_EDITOR_QUESTION_URL, self.topic_id ), expect_errors=True, expected_status_int=401) @@ -152,7 +151,7 @@ def test_editable_subtopic_page_get(self): # editable subtopic data. with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): self.login(self.NEW_USER_EMAIL) - response = self.get_html( + response = self.get_response( '%s/%s/%s' % ( feconf.SUBTOPIC_PAGE_EDITOR_DATA_URL_PREFIX, self.topic_id, 1), @@ -202,7 +201,7 @@ def test_access_topic_editor_page(self): # Check that non-admin and topic_manager cannot access the editor # page. self.login(self.NEW_USER_EMAIL) - response = self.get_html( + response = self.get_response( '%s/%s' % ( feconf.TOPIC_EDITOR_URL_PREFIX, self.topic_id), expect_errors=True, expected_status_int=401) @@ -211,14 +210,14 @@ def test_access_topic_editor_page(self): # Check that admins can access the editor page. self.login(self.ADMIN_EMAIL) - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.TOPIC_EDITOR_URL_PREFIX, self.topic_id)) self.assertEqual(response.status_int, 200) self.logout() # Check that any topic manager can access the editor page. self.login(self.TOPIC_MANAGER_EMAIL) - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.TOPIC_EDITOR_URL_PREFIX, self.topic_id)) self.assertEqual(response.status_int, 200) self.logout() @@ -228,7 +227,7 @@ def test_editable_topic_handler_get(self): # Check that non-admins cannot access the editable topic data. with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): self.login(self.NEW_USER_EMAIL) - response = self.get_html( + response = self.get_response( '%s/%s' % ( feconf.TOPIC_EDITOR_DATA_URL_PREFIX, self.topic_id), expect_errors=True, expected_status_int=401) @@ -281,7 +280,7 @@ def test_editable_topic_handler_put(self): } self.login(self.ADMIN_EMAIL) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.TOPIC_EDITOR_URL_PREFIX, self.topic_id)) csrf_token = self.get_csrf_token_from_response(response) @@ -367,7 +366,7 @@ def test_editable_topic_handler_put_for_assigned_topic_manager(self): self.login(self.TOPIC_MANAGER_EMAIL) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.TOPIC_EDITOR_URL_PREFIX, self.topic_id)) csrf_token = self.get_csrf_token_from_response(response) # Check that the topic manager can edit the topic now. @@ -406,7 +405,7 @@ def test_assign_topic_manager_role(self): """Test the assign topic manager role for a topic functionality.""" self.login(self.ADMIN_EMAIL) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.TOPIC_EDITOR_URL_PREFIX, self.topic_id)) csrf_token = self.get_csrf_token_from_response(response) @@ -455,7 +454,7 @@ def test_get_topic_rights(self): self.login(self.NEW_USER_EMAIL) # Test that other users cannot access topic rights. - response = self.get_html( + response = self.get_response( '%s/%s' % ( feconf.TOPIC_RIGHTS_URL_PREFIX, self.topic_id), expect_errors=True, expected_status_int=401) @@ -469,7 +468,7 @@ def test_publish_and_unpublish_topic(self): """Test the publish and unpublish functionality.""" self.login(self.ADMIN_EMAIL) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.TOPIC_EDITOR_URL_PREFIX, self.topic_id)) csrf_token = self.get_csrf_token_from_response(response) # Test whether admin can publish and unpublish a topic. diff --git a/core/controllers/topic_viewer_test.py b/core/controllers/topic_viewer_test.py index 4cd3a53c0b43..40e635e2f98a 100644 --- a/core/controllers/topic_viewer_test.py +++ b/core/controllers/topic_viewer_test.py @@ -59,14 +59,14 @@ class TopicViewerPage(BaseTopicViewerControllerTest): def test_any_user_can_access_topic_viewer_page(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.TOPIC_VIEWER_URL_PREFIX, 'public_topic_name')) self.assertEqual(response.status_int, 200) def test_no_user_can_access_unpublished_topic_viewer_page(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.get_html( + response = self.get_response( '%s/%s' % ( feconf.TOPIC_VIEWER_URL_PREFIX, 'private_topic_name'), expect_errors=True, expected_status_int=404) @@ -75,7 +75,7 @@ def test_no_user_can_access_unpublished_topic_viewer_page(self): def test_get_fails_when_new_structures_not_enabled(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', False): - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.TOPIC_VIEWER_URL_PREFIX, 'public_topic_name'), expect_errors=True, expected_status_int=404) self.assertEqual(response.status_int, 404) @@ -100,7 +100,7 @@ def test_get(self): def test_get_fails_when_new_structures_not_enabled(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', False): - response = self.get_html( + response = self.get_response( '%s/%s' % (feconf.TOPIC_DATA_HANDLER, 'public_topic_name'), expect_errors=True, expected_status_int=404) self.assertEqual(response.status_int, 404) diff --git a/core/controllers/topics_and_skills_dashboard_test.py b/core/controllers/topics_and_skills_dashboard_test.py index 5e9be8761afe..8dd392a0a886 100644 --- a/core/controllers/topics_and_skills_dashboard_test.py +++ b/core/controllers/topics_and_skills_dashboard_test.py @@ -51,7 +51,7 @@ def _get_csrf_token_for_put(self): csrf_token = None url_prefix = feconf.TOPICS_AND_SKILLS_DASHBOARD_URL with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.get_html(url_prefix) + response = self.get_response(url_prefix) csrf_token = self.get_csrf_token_from_response(response) return csrf_token @@ -62,8 +62,8 @@ def test_get_fails_when_new_structures_not_enabled(self): self.login(self.ADMIN_EMAIL) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', False): url = feconf.TOPICS_AND_SKILLS_DASHBOARD_URL - response = self.get_html(url, expect_errors=True, - expected_status_int=404) + response = self.get_response(url, expect_errors=True, + expected_status_int=404) self.assertEqual(response.status_int, 404) self.logout() diff --git a/core/controllers/translator_test.py b/core/controllers/translator_test.py index 6debd2b6b723..e6cb1f2f763e 100644 --- a/core/controllers/translator_test.py +++ b/core/controllers/translator_test.py @@ -67,7 +67,7 @@ def setUp(self): self.login(self.TRANSLATOR_EMAIL) # Generate CSRF token. - response = self.get_html('/create/%s' % self.EXP_ID) + response = self.get_response('/create/%s' % self.EXP_ID) self.csrf_token = self.get_csrf_token_from_response(response) def test_transator_can_save_valid_change_list(self): @@ -160,7 +160,7 @@ def setUp(self): draft_change_list_id=1).put() # Generate CSRF token. - response = self.get_html('/create/%s' % self.EXP_ID) + response = self.get_response('/create/%s' % self.EXP_ID) self.csrf_token = self.get_csrf_token_from_response(response) def test_draft_updated_version_valid(self): diff --git a/core/domain/dependency_registry_test.py b/core/domain/dependency_registry_test.py index 65d71e4cee4e..7c020154ab6e 100644 --- a/core/domain/dependency_registry_test.py +++ b/core/domain/dependency_registry_test.py @@ -39,11 +39,11 @@ class DependencyControllerTests(test_utils.GenericTestBase): """Tests for dependency loading on user-facing pages.""" def test_no_dependencies_in_non_exploration_pages(self): - response = self.get_html(feconf.LIBRARY_INDEX_URL) + response = self.get_response(feconf.LIBRARY_INDEX_URL) self.assertEqual(response.status_int, 200) response.mustcontain(no=['skulpt']) - response = self.get_html('/about') + response = self.get_response('/about') self.assertEqual(response.status_int, 200) response.mustcontain(no=['skulpt']) @@ -65,7 +65,7 @@ def test_dependencies_loaded_in_exploration_editor(self): # However, Skulpt is loaded in the exploration editor anyway, since # all dependencies are loaded in the exploration editor. - response = self.get_html('/create/0') + response = self.get_response('/create/0') self.assertEqual(response.status_int, 200) response.mustcontain('skulpt') @@ -85,7 +85,7 @@ def test_dependency_does_not_load_in_exploration_not_containing_it(self): self.assertNotIn('skulpt', all_dependency_ids) # Thus, Skulpt is not loaded in the exploration reader. - response = self.get_html('/explore/%s' % exp_id) + response = self.get_response('/explore/%s' % exp_id) self.assertEqual(response.status_int, 200) response.mustcontain(no=['skulpt']) @@ -103,6 +103,6 @@ def test_dependency_loads_in_exploration_containing_it(self): self.assertIn('skulpt', all_dependency_ids) # Thus, Skulpt is loaded in the exploration reader. - response = self.get_html('/explore/%s' % exp_id) + response = self.get_response('/explore/%s' % exp_id) self.assertEqual(response.status_int, 200) response.mustcontain('skulpt') diff --git a/core/domain/email_manager_test.py b/core/domain/email_manager_test.py index 2b198e4c77d5..2042f7a64a85 100644 --- a/core/domain/email_manager_test.py +++ b/core/domain/email_manager_test.py @@ -119,7 +119,7 @@ def test_role_email_is_sent_when_editor_assigns_role(self): with self.can_send_emails_ctx, self.can_send_editor_role_email_ctx: self.login(self.EDITOR_EMAIL) - response = self.get_html('%s/%s' % ( + response = self.get_response('%s/%s' % ( feconf.EDITOR_URL_PREFIX, self.exploration.id)) csrf_token = self.get_csrf_token_from_response(response) self.put_json('%s/%s' % ( @@ -472,7 +472,7 @@ def test_email_not_sent_if_config_does_not_permit_it(self): self.new_email_content) self.login(self.EDITOR_EMAIL) - response = self.get_html(feconf.SIGNUP_URL) + response = self.get_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( @@ -502,7 +502,7 @@ def _log_error_for_tests(error_message): self.assertEqual(log_new_error_counter.times_called, 0) self.login(self.EDITOR_EMAIL) - response = self.get_html(feconf.SIGNUP_URL) + response = self.get_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) # No user-facing error should surface. @@ -549,7 +549,7 @@ def _log_error_for_tests(error_message): self.assertEqual(log_new_error_counter.times_called, 0) self.login(self.EDITOR_EMAIL) - response = self.get_html(feconf.SIGNUP_URL) + response = self.get_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) # No user-facing error should surface. @@ -594,7 +594,7 @@ def _log_error_for_tests(error_message): self.assertEqual(log_new_error_counter.times_called, 0) self.login(self.EDITOR_EMAIL) - response = self.get_html(feconf.SIGNUP_URL) + response = self.get_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) # No user-facing error should surface. @@ -626,7 +626,7 @@ def test_contents_of_signup_email_are_correct(self): 'Email Sender') self.login(self.EDITOR_EMAIL) - response = self.get_html(feconf.SIGNUP_URL) + response = self.get_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( @@ -659,7 +659,7 @@ def test_email_only_sent_once_for_repeated_signups_by_same_user(self): self.new_email_content) self.login(self.EDITOR_EMAIL) - response = self.get_html(feconf.SIGNUP_URL) + response = self.get_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( @@ -693,7 +693,7 @@ def test_email_only_sent_if_signup_was_successful(self): self.new_email_content) self.login(self.EDITOR_EMAIL) - response = self.get_html(feconf.SIGNUP_URL) + response = self.get_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( @@ -737,7 +737,7 @@ def test_record_of_sent_email_is_written_to_datastore(self): self.assertEqual(len(all_models), 0) self.login(self.EDITOR_EMAIL) - response = self.get_html(feconf.SIGNUP_URL) + response = self.get_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( diff --git a/core/domain/feedback_services_test.py b/core/domain/feedback_services_test.py index 4f49acaeabb8..95ae48774da9 100644 --- a/core/domain/feedback_services_test.py +++ b/core/domain/feedback_services_test.py @@ -920,7 +920,7 @@ def test_that_emails_are_not_sent_if_already_seen(self): self.login(self.EDITOR_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_html('/create/%s' % self.exploration.id)) + self.get_response('/create/%s' % self.exploration.id)) self.post_json( '%s/%s' % ( feconf.FEEDBACK_THREAD_VIEW_EVENT_URL, thread_id), diff --git a/core/domain/summary_services_test.py b/core/domain/summary_services_test.py index cbdfb2c97db1..9614c6217f13 100644 --- a/core/domain/summary_services_test.py +++ b/core/domain/summary_services_test.py @@ -256,7 +256,7 @@ def setUp(self): super(LibraryGroupsTest, self).setUp() self.login(self.ADMIN_EMAIL, is_super_admin=True) - response = self.get_html('/admin') + response = self.get_response('/admin') csrf_token = self.get_csrf_token_from_response(response) with self.swap( diff --git a/core/domain/user_services_test.py b/core/domain/user_services_test.py index c30b9eb68715..e33abaad89a2 100644 --- a/core/domain/user_services_test.py +++ b/core/domain/user_services_test.py @@ -924,7 +924,7 @@ def test_legacy_user(self): # After logging in and requesting a URL, the last_logged_in property is # set. self.login(self.VIEWER_EMAIL) - self.get_html(feconf.LIBRARY_INDEX_URL) + self.get_response(feconf.LIBRARY_INDEX_URL) self.assertIsNotNone( user_services.get_user_settings(self.viewer_id).last_logged_in) self.logout() @@ -961,7 +961,7 @@ def utcnow(cls): with self.swap(datetime, 'datetime', PatchedDatetime11Hours): self.login(self.VIEWER_EMAIL) - self.get_html(feconf.LIBRARY_INDEX_URL) + self.get_response(feconf.LIBRARY_INDEX_URL) self.assertEqual( user_services.get_user_settings(self.viewer_id).last_logged_in, previous_last_logged_in_datetime) @@ -969,7 +969,7 @@ def utcnow(cls): with self.swap(datetime, 'datetime', PatchedDatetime13Hours): self.login(self.VIEWER_EMAIL) - self.get_html(feconf.LIBRARY_INDEX_URL) + self.get_response(feconf.LIBRARY_INDEX_URL) self.assertGreater( user_services.get_user_settings(self.viewer_id).last_logged_in, previous_last_logged_in_datetime) diff --git a/core/tests/test_utils.py b/core/tests/test_utils.py index b3e563f3e1e0..b00316081061 100644 --- a/core/tests/test_utils.py +++ b/core/tests/test_utils.py @@ -482,10 +482,11 @@ def get_expected_logout_url(self, slug): """Returns the expected logout URL.""" return current_user_services.create_logout_url(slug) - def get_html(self, url, params=None, expect_errors=False, - expected_status_int=200): - """Get a HTML response, transformed to a Python object.""" - html_response = self.testapp.get( + def get_response(self, url, params=None, expect_errors=False, + expected_status_int=200, expected_content_type='text/html', + can_have_multiple_responses=False): + """Get a response, transformed to a Python object.""" + response = self.testapp.get( url, params, expect_errors=expect_errors, status=expected_status_int) @@ -496,17 +497,18 @@ def get_html(self, url, params=None, expect_errors=False, # Reference URL: # https://github.com/Pylons/webtest/blob/ # bf77326420b628c9ea5431432c7e171f88c5d874/webtest/app.py#L1119 . - self.assertEqual(html_response.status_int, expected_status_int) - if not expect_errors: - self.assertTrue(html_response.status_int >= 200 and - html_response.status_int < 400) - else: - self.assertTrue(html_response.status_int >= 400 and - html_response.status_int < 600) - self.assertEqual( - html_response.content_type, 'text/html') - - return html_response + if not can_have_multiple_responses: + self.assertEqual(response.status_int, expected_status_int) + if not expect_errors: + self.assertTrue(response.status_int >= 200 and + response.status_int < 400) + else: + self.assertTrue(response.status_int >= 400 and + response.status_int < 600) + self.assertEqual( + response.content_type, expected_content_type) + + return response def _parse_json_response(self, json_response, expect_errors=False): """Convert a JSON server response to an object (such as a dict).""" @@ -665,7 +667,7 @@ def signup(self, email, username): # external calls being made to Gravatar when running the backend # tests. with self.urlfetch_mock(): - response = self.get_html(feconf.SIGNUP_URL) + response = self.get_response(feconf.SIGNUP_URL) self.assertEqual(response.status_int, 200) csrf_token = self.get_csrf_token_from_response(response) response = self.testapp.post( @@ -686,7 +688,7 @@ def set_config_property(self, config_obj, new_config_value): self._stash_current_user_env() self.login('tmpsuperadmin@example.com', is_super_admin=True) - response = self.get_html('/admin') + response = self.get_response('/admin') csrf_token = self.get_csrf_token_from_response(response) self.post_json( '/adminhandler', { @@ -709,7 +711,7 @@ def set_user_role(self, username, user_role): self._stash_current_user_env() self.login('tmpsuperadmin@example.com', is_super_admin=True) - response = self.get_html('/admin') + response = self.get_response('/admin') csrf_token = self.get_csrf_token_from_response(response) self.post_json( '/adminrolehandler', { From ba2eafc28f0246aef352586c92ebb7900b5cad88 Mon Sep 17 00:00:00 2001 From: Rishav Chakraborty Date: Tue, 4 Dec 2018 00:13:50 +0530 Subject: [PATCH 04/11] Function get_response_without_checking_for_errors --- core/controllers/base_test.py | 6 ++---- core/tests/test_utils.py | 34 ++++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/core/controllers/base_test.py b/core/controllers/base_test.py index a9d650d802f8..c2f442040d66 100644 --- a/core/controllers/base_test.py +++ b/core/controllers/base_test.py @@ -94,10 +94,8 @@ def test_that_no_get_results_in_500_error(self): url = re.sub('<([^/^:]+)>', 'abc123', url) # Some of these will 404 or 302. This is expected. - response = self.get_response(url, expect_errors=True, - can_have_multiple_responses=True) - self.assertIn( - response.status_int, [200, 302, 400, 401, 404], msg=url) + self.get_response_without_checking_for_errors( + url, [200, 302, 400, 401, 404]) # TODO(sll): Add similar tests for POST, PUT, DELETE. # TODO(sll): Set a self.payload attr in the BaseHandler for diff --git a/core/tests/test_utils.py b/core/tests/test_utils.py index b00316081061..e0a7090ca71f 100644 --- a/core/tests/test_utils.py +++ b/core/tests/test_utils.py @@ -483,8 +483,8 @@ def get_expected_logout_url(self, slug): return current_user_services.create_logout_url(slug) def get_response(self, url, params=None, expect_errors=False, - expected_status_int=200, expected_content_type='text/html', - can_have_multiple_responses=False): + expected_status_int=200, + expected_content_type='text/html'): """Get a response, transformed to a Python object.""" response = self.testapp.get( url, params, expect_errors=expect_errors, @@ -497,16 +497,26 @@ def get_response(self, url, params=None, expect_errors=False, # Reference URL: # https://github.com/Pylons/webtest/blob/ # bf77326420b628c9ea5431432c7e171f88c5d874/webtest/app.py#L1119 . - if not can_have_multiple_responses: - self.assertEqual(response.status_int, expected_status_int) - if not expect_errors: - self.assertTrue(response.status_int >= 200 and - response.status_int < 400) - else: - self.assertTrue(response.status_int >= 400 and - response.status_int < 600) - self.assertEqual( - response.content_type, expected_content_type) + self.assertEqual(response.status_int, expected_status_int) + if not expect_errors: + self.assertTrue(response.status_int >= 200 and + response.status_int < 400) + else: + self.assertTrue(response.status_int >= 400 and + response.status_int < 600) + self.assertEqual( + response.content_type, expected_content_type) + + return response + + def get_response_without_checking_for_errors( + self, url, expected_status_int_list, params=None): + """Get a response, transformed to a Python object and + checks for a list of status codes. + """ + response = self.testapp.get(url, params, expect_errors=True) + + self.assertIn(response.status_int, expected_status_int_list) return response From 3b12b1eb37ac1b42d74acc2cafe3d5f02b65af2b Mon Sep 17 00:00:00 2001 From: Rishav Chakraborty Date: Tue, 4 Dec 2018 01:22:59 +0530 Subject: [PATCH 05/11] Fixed Errors --- core/controllers/collection_editor_test.py | 6 +++--- core/controllers/concept_card_viewer_test.py | 3 +-- core/controllers/question_editor_test.py | 3 +-- core/controllers/reader_test.py | 6 ++---- core/controllers/resources_test.py | 18 ++++++------------ core/controllers/skill_editor_test.py | 9 +++------ core/controllers/story_editor_test.py | 3 +-- core/controllers/topic_editor_test.py | 12 ++++-------- core/controllers/topic_viewer_test.py | 3 +-- 9 files changed, 22 insertions(+), 41 deletions(-) diff --git a/core/controllers/collection_editor_test.py b/core/controllers/collection_editor_test.py index 117244b125d5..f40700d8a87e 100644 --- a/core/controllers/collection_editor_test.py +++ b/core/controllers/collection_editor_test.py @@ -103,11 +103,11 @@ def test_editable_collection_handler_get(self): # Check that non-editors cannot access the editor data handler. # This is due to them not being whitelisted. - response = self.get_response( + self.get_json( '%s/%s' % ( feconf.COLLECTION_EDITOR_DATA_URL_PREFIX, - self.COLLECTION_ID), expect_errors=True) - self.assertEqual(response.status_int, 401) + self.COLLECTION_ID), expect_errors=True, + expected_status_int=401) # Check that whitelisted users can access the data # from the editable_collection_data_handler. diff --git a/core/controllers/concept_card_viewer_test.py b/core/controllers/concept_card_viewer_test.py index 0a089c392e8a..4e66fc94848d 100644 --- a/core/controllers/concept_card_viewer_test.py +++ b/core/controllers/concept_card_viewer_test.py @@ -65,7 +65,6 @@ def test_get_concept_card(self): def test_get_concept_card_fails_when_new_structures_not_enabled(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', False): - response = self.get_response( + self.get_json( '%s/%s' % (feconf.CONCEPT_CARD_DATA_URL_PREFIX, self.skill_id), expect_errors=True, expected_status_int=404) - self.assertEqual(response.status_int, 404) diff --git a/core/controllers/question_editor_test.py b/core/controllers/question_editor_test.py index 513831371d7a..b51ee5183ac0 100644 --- a/core/controllers/question_editor_test.py +++ b/core/controllers/question_editor_test.py @@ -222,11 +222,10 @@ def test_get(self): # Check that non-admin and topic_manager cannot access the editor # data. self.login(self.NEW_USER_EMAIL) - response = self.get_response( + self.get_json( '%s/%s' % ( feconf.QUESTION_EDITOR_DATA_URL_PREFIX, self.question_id), expect_errors=True, expected_status_int=401) - self.assertEqual(response.status_int, 401) self.logout() self.login(self.ADMIN_EMAIL) diff --git a/core/controllers/reader_test.py b/core/controllers/reader_test.py index 54fd1a686ba2..51f1c41cfad3 100644 --- a/core/controllers/reader_test.py +++ b/core/controllers/reader_test.py @@ -276,17 +276,15 @@ def test_get_exploration_pretests(self): json_response_1['pretest_question_dicts'][0]['id'], json_response_2['pretest_question_dicts'][0]['id']) - response = self.get_response( + self.get_json( '%s/%s?story_id=%s' % ( feconf.EXPLORATION_PRETESTS_URL_PREFIX, exp_id_2, STORY_ID), expect_errors=True, expected_status_int=400) - self.assertEqual(response.status_int, 400) - response = self.get_response( + self.get_json( '%s/%s?story_id=%s' % ( feconf.EXPLORATION_PRETESTS_URL_PREFIX, exp_id_2, 'story'), expect_errors=True, expected_status_int=400) - self.assertEqual(response.status_int, 400) class ExplorationParametersUnitTests(test_utils.GenericTestBase): diff --git a/core/controllers/resources_test.py b/core/controllers/resources_test.py index ac69516a753d..4855f013d557 100644 --- a/core/controllers/resources_test.py +++ b/core/controllers/resources_test.py @@ -100,16 +100,12 @@ def test_non_matching_extensions_are_detected(self): self.logout() # Test that neither form of the image is stored. - response = self.get_response( + self.get_json( self._get_image_url('0', supplied_filename), - expect_errors=True, expected_status_int=404, - expected_content_type='image/jpg') - self.assertEqual(response.status_int, 404) - response = self.get_response( + expect_errors=True, expected_status_int=404) + self.get_json( self._get_image_url('0', filename_with_correct_extension), - expect_errors=True, expected_status_int=404, - expected_content_type='image/png') - self.assertEqual(response.status_int, 404) + expect_errors=True, expected_status_int=404) def test_upload_empty_image(self): """Test upload of an empty image.""" @@ -156,11 +152,9 @@ def test_upload_bad_image(self): def test_get_invalid_image(self): """Test retrieval of invalid images.""" - response = self.get_response( + self.get_json( self._get_image_url('0', 'bad_image'), - expect_errors=True, expected_status_int=404, - expected_content_type='image/bad_image') - self.assertEqual(response.status_int, 404) + expect_errors=True, expected_status_int=404) def test_bad_filenames_are_detected(self): # TODO(sll): Add more tests here. diff --git a/core/controllers/skill_editor_test.py b/core/controllers/skill_editor_test.py index 3e0e481142f4..0928e9e525ee 100644 --- a/core/controllers/skill_editor_test.py +++ b/core/controllers/skill_editor_test.py @@ -145,9 +145,8 @@ def test_skill_rights_handler_fails(self): skill_services_swap = self.swap( skill_services, 'get_skill_rights', self._mock_get_skill_rights) with skill_services_swap: - response = self.get_response(self.url, expect_errors=True, + self.get_json(self.url, expect_errors=True, expected_status_int=404) - self.assertEqual(response.status_int, 404) self.logout() @@ -181,15 +180,13 @@ def test_editable_skill_handler_get_fails(self): self.login(self.ADMIN_EMAIL) # Check GET returns 404 when new strutures' pages are not enabled. with self.swap(constants, 'ENABLE_NEW_STRUCTURES', False): - response = self.get_response(self.url, expect_errors=True, + self.get_json(self.url, expect_errors=True, expected_status_int=404) - self.assertEqual(response.status_int, 404) # Check GET returns 404 when cannot get skill by id. self._delete_skill_model_and_memcache(self.admin_id, self.skill_id) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.get_response(self.url, expect_errors=True, + self.get_json(self.url, expect_errors=True, expected_status_int=404) - self.assertEqual(response.status_int, 404) self.logout() def test_editable_skill_handler_put_succeeds(self): diff --git a/core/controllers/story_editor_test.py b/core/controllers/story_editor_test.py index 3a4ce3f4a458..9d0dfb0da526 100644 --- a/core/controllers/story_editor_test.py +++ b/core/controllers/story_editor_test.py @@ -74,11 +74,10 @@ def test_editable_story_handler_get(self): # Check that non-admins cannot access the editable story data. with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): self.login(self.NEW_USER_EMAIL) - response = self.get_response( + self.get_json( '%s/%s/%s' % ( feconf.STORY_EDITOR_DATA_URL_PREFIX, self.topic_id, self.story_id), expect_errors=True, expected_status_int=401) - self.assertEqual(response.status_int, 401) self.logout() # Check that admins can access the editable story data. diff --git a/core/controllers/topic_editor_test.py b/core/controllers/topic_editor_test.py index 11f142aac280..7242e09651a3 100644 --- a/core/controllers/topic_editor_test.py +++ b/core/controllers/topic_editor_test.py @@ -136,11 +136,10 @@ def test_get(self): self.logout() self.login(self.NEW_USER_EMAIL) - response = self.get_response( + self.get_json( '%s/%s?cursor=' % ( feconf.TOPIC_EDITOR_QUESTION_URL, self.topic_id ), expect_errors=True, expected_status_int=401) - self.assertEqual(response.status_int, 401) self.logout() @@ -151,12 +150,11 @@ def test_editable_subtopic_page_get(self): # editable subtopic data. with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): self.login(self.NEW_USER_EMAIL) - response = self.get_response( + self.get_json( '%s/%s/%s' % ( feconf.SUBTOPIC_PAGE_EDITOR_DATA_URL_PREFIX, self.topic_id, 1), expect_errors=True, expected_status_int=401) - self.assertEqual(response.status_int, 401) self.logout() # Check that topic managers not assigned to this topic can @@ -227,11 +225,10 @@ def test_editable_topic_handler_get(self): # Check that non-admins cannot access the editable topic data. with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): self.login(self.NEW_USER_EMAIL) - response = self.get_response( + self.get_json( '%s/%s' % ( feconf.TOPIC_EDITOR_DATA_URL_PREFIX, self.topic_id), expect_errors=True, expected_status_int=401) - self.assertEqual(response.status_int, 401) self.logout() # Check that admins can access the editable topic data. @@ -454,11 +451,10 @@ def test_get_topic_rights(self): self.login(self.NEW_USER_EMAIL) # Test that other users cannot access topic rights. - response = self.get_response( + self.get_json( '%s/%s' % ( feconf.TOPIC_RIGHTS_URL_PREFIX, self.topic_id), expect_errors=True, expected_status_int=401) - self.assertEqual(response.status_int, 401) self.logout() diff --git a/core/controllers/topic_viewer_test.py b/core/controllers/topic_viewer_test.py index f6e0aaf98d83..1771da957a14 100644 --- a/core/controllers/topic_viewer_test.py +++ b/core/controllers/topic_viewer_test.py @@ -100,7 +100,6 @@ def test_get(self): def test_get_fails_when_new_structures_not_enabled(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', False): - response = self.get_response( + self.get_json( '%s/%s' % (feconf.TOPIC_DATA_HANDLER, 'public_topic_name'), expect_errors=True, expected_status_int=404) - self.assertEqual(response.status_int, 404) From 014d6871a57a821ffefdc14d4b5133e1f848824b Mon Sep 17 00:00:00 2001 From: Rishav Chakraborty Date: Tue, 4 Dec 2018 01:27:29 +0530 Subject: [PATCH 06/11] Fixed lint checks --- core/controllers/skill_editor_test.py | 15 +++++++++------ core/controllers/topic_editor_test.py | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/controllers/skill_editor_test.py b/core/controllers/skill_editor_test.py index 0928e9e525ee..0546f2ea4965 100644 --- a/core/controllers/skill_editor_test.py +++ b/core/controllers/skill_editor_test.py @@ -145,8 +145,9 @@ def test_skill_rights_handler_fails(self): skill_services_swap = self.swap( skill_services, 'get_skill_rights', self._mock_get_skill_rights) with skill_services_swap: - self.get_json(self.url, expect_errors=True, - expected_status_int=404) + self.get_json( + self.url, expect_errors=True, + expected_status_int=404) self.logout() @@ -180,13 +181,15 @@ def test_editable_skill_handler_get_fails(self): self.login(self.ADMIN_EMAIL) # Check GET returns 404 when new strutures' pages are not enabled. with self.swap(constants, 'ENABLE_NEW_STRUCTURES', False): - self.get_json(self.url, expect_errors=True, - expected_status_int=404) + self.get_json( + self.url, expect_errors=True, + expected_status_int=404) # Check GET returns 404 when cannot get skill by id. self._delete_skill_model_and_memcache(self.admin_id, self.skill_id) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - self.get_json(self.url, expect_errors=True, - expected_status_int=404) + self.get_json( + self.url, expect_errors=True, + expected_status_int=404) self.logout() def test_editable_skill_handler_put_succeeds(self): diff --git a/core/controllers/topic_editor_test.py b/core/controllers/topic_editor_test.py index 7242e09651a3..411ad03ab26c 100644 --- a/core/controllers/topic_editor_test.py +++ b/core/controllers/topic_editor_test.py @@ -117,7 +117,7 @@ def test_get(self): self.logout() self.login(self.TOPIC_MANAGER_EMAIL) - response = self.get_json( + self.get_json( '%s/%s?cursor=' % ( feconf.TOPIC_EDITOR_QUESTION_URL, self.topic_id)) self.logout() From 132f541b8a2e91844c36daa244574d3490a92c54 Mon Sep 17 00:00:00 2001 From: Rishav Chakraborty Date: Fri, 21 Dec 2018 00:58:00 +0530 Subject: [PATCH 07/11] removed further redundancy --- core/controllers/admin_test.py | 40 ++--- core/controllers/base_test.py | 52 +++--- core/controllers/classifier_test.py | 20 +-- core/controllers/collection_editor_test.py | 26 ++- core/controllers/collection_viewer_test.py | 27 ++-- core/controllers/concept_card_viewer_test.py | 2 +- core/controllers/creator_dashboard_test.py | 15 +- core/controllers/editor_test.py | 149 +++++++----------- core/controllers/email_dashboard_test.py | 53 ++++--- core/controllers/feedback_test.py | 40 +++-- core/controllers/incoming_emails_test.py | 2 +- core/controllers/learner_dashboard_test.py | 2 +- core/controllers/learner_playlist_test.py | 4 +- core/controllers/library_test.py | 9 +- core/controllers/moderator_test.py | 22 +-- core/controllers/pages_test.py | 3 +- core/controllers/profile_test.py | 81 ++++------ core/controllers/question_editor_test.py | 74 ++++----- core/controllers/reader_test.py | 63 ++++---- core/controllers/resources_test.py | 56 +++---- core/controllers/skill_editor_test.py | 71 ++++----- core/controllers/story_editor_test.py | 23 ++- core/controllers/subscriptions_test.py | 10 +- core/controllers/suggestion_test.py | 32 ++-- core/controllers/topic_editor_test.py | 70 ++++---- core/controllers/topic_viewer_test.py | 15 +- .../topics_and_skills_dashboard_test.py | 22 +-- core/controllers/translator_test.py | 9 +- core/domain/acl_decorators_test.py | 133 ++++++---------- core/domain/dependency_registry_test.py | 15 +- core/domain/email_manager_test.py | 22 ++- core/domain/feedback_services_test.py | 2 +- core/domain/summary_services_test.py | 2 +- core/domain/user_services_test.py | 6 +- core/tests/test_utils.py | 125 +++++++++++---- 35 files changed, 575 insertions(+), 722 deletions(-) diff --git a/core/controllers/admin_test.py b/core/controllers/admin_test.py index 0d62cf900ec1..d506e7065272 100644 --- a/core/controllers/admin_test.py +++ b/core/controllers/admin_test.py @@ -38,27 +38,23 @@ def setUp(self): def test_admin_page_rights(self): """Test access rights to the admin page.""" - response = self.get_response('/admin', expected_status_int=302) - self.assertEqual(response.status_int, 302) + self.get_html_response('/admin', expected_status_int=302) # Login as a non-admin. self.login(self.EDITOR_EMAIL) - response = self.get_response('/admin', expect_errors=True, - expected_status_int=401) - self.assertEqual(response.status_int, 401) + self.get_html_response('/admin', expected_status_int=401) self.logout() # Login as an admin. self.login(self.ADMIN_EMAIL, is_super_admin=True) - response = self.get_response('/admin') - self.assertEqual(response.status_int, 200) + self.get_html_response('/admin') self.logout() def test_change_configuration_property(self): """Test that configuration properties can be changed.""" self.login(self.ADMIN_EMAIL, is_super_admin=True) - response = self.get_response('/admin') + response = self.get_html_response('/admin') csrf_token = self.get_csrf_token_from_response(response) response_dict = self.get_json('/adminhandler') @@ -88,11 +84,11 @@ def test_change_about_page_config_property(self): """Test that config property values are changed correctly.""" new_config_value = 'new_config_value' - response = self.get_response('/about') + response = self.get_html_response('/about') self.assertNotIn(new_config_value, response.body) self.login(self.ADMIN_EMAIL, is_super_admin=True) - response = self.get_response('/admin') + response = self.get_html_response('/admin') csrf_token = self.get_csrf_token_from_response(response) self.post_json( '/adminhandler', { @@ -102,7 +98,7 @@ def test_change_about_page_config_property(self): } }, csrf_token=csrf_token) - response = self.get_response('/about') + response = self.get_html_response('/about') self.assertIn(new_config_value, response.body) @@ -112,7 +108,7 @@ class GenerateDummyExplorationsTest(test_utils.GenericTestBase): def test_generate_count_greater_than_publish_count(self): self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.login(self.ADMIN_EMAIL, is_super_admin=True) - response = self.get_response('/admin') + response = self.get_html_response('/admin') csrf_token = self.get_csrf_token_from_response(response) self.post_json( '/adminhandler', { @@ -128,7 +124,7 @@ def test_generate_count_greater_than_publish_count(self): def test_generate_count_equal_to_publish_count(self): self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.login(self.ADMIN_EMAIL, is_super_admin=True) - response = self.get_response('/admin') + response = self.get_html_response('/admin') csrf_token = self.get_csrf_token_from_response(response) self.post_json( '/adminhandler', { @@ -144,7 +140,7 @@ def test_generate_count_equal_to_publish_count(self): def test_generate_count_less_than_publish_count(self): self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.login(self.ADMIN_EMAIL, is_super_admin=True) - response = self.get_response('/admin') + response = self.get_html_response('/admin') csrf_token = self.get_csrf_token_from_response(response) generated_exps_response = self.post_json( '/adminhandler', { @@ -152,9 +148,7 @@ def test_generate_count_less_than_publish_count(self): 'num_dummy_exps_to_generate': 2, 'num_dummy_exps_to_publish': 5 }, - csrf_token=csrf_token, - expect_errors=True, - expected_status_int=400) + csrf_token=csrf_token, expected_status_int=400) self.assertEqual(generated_exps_response['status_code'], 400) generated_exps = exp_services.get_all_exploration_summaries() published_exps = exp_services.get_recently_published_exp_summaries(5) @@ -186,12 +180,12 @@ def test_view_and_update_role(self): response_dict, {'user1': feconf.ROLE_ID_EXPLORATION_EDITOR}) # Check role correctly gets updated. - response = self.get_response(feconf.ADMIN_URL) + response = self.get_html_response(feconf.ADMIN_URL) csrf_token = self.get_csrf_token_from_response(response) response_dict = self.post_json( feconf.ADMIN_ROLE_HANDLER_URL, {'role': feconf.ROLE_ID_MODERATOR, 'username': username}, - csrf_token=csrf_token, expect_errors=False, + csrf_token=csrf_token, expected_status_int=200) self.assertEqual(response_dict, {}) @@ -211,15 +205,15 @@ def test_invalid_username_in_view_and_update_role(self): response = self.get_json( feconf.ADMIN_ROLE_HANDLER_URL, params={'method': 'username', 'username': username}, - expected_status_int=400, expect_errors=True) + expected_status_int=400) # Trying to update role of non-existent user. - response = self.get_response(feconf.ADMIN_URL) + response = self.get_html_response(feconf.ADMIN_URL) csrf_token = self.get_csrf_token_from_response(response) response = self.post_json( feconf.ADMIN_ROLE_HANDLER_URL, {'role': feconf.ROLE_ID_MODERATOR, 'username': username}, - csrf_token=csrf_token, expect_errors=True, + csrf_token=csrf_token, expected_status_int=400) @@ -296,7 +290,7 @@ def test_that_handler_raises_exception(self): response = self.get_json( '/explorationdataextractionhandler', params=payload, - expected_status_int=400, expect_errors=True) + expected_status_int=400) self.assertEqual( response['error'], diff --git a/core/controllers/base_test.py b/core/controllers/base_test.py index b6f3a5ec41ea..b9054ae73e40 100644 --- a/core/controllers/base_test.py +++ b/core/controllers/base_test.py @@ -73,12 +73,12 @@ def test_dev_indicator_appears_in_dev_and_not_in_production(self): """Test dev indicator appears in dev and not in production.""" with self.swap(constants, 'DEV_MODE', True): - response = self.get_response(feconf.LIBRARY_INDEX_URL) + response = self.get_html_response(feconf.LIBRARY_INDEX_URL) self.assertIn('
', response.body) with self.swap(constants, 'DEV_MODE', False): - response = self.get_response(feconf.LIBRARY_INDEX_URL) + response = self.get_html_response(feconf.LIBRARY_INDEX_URL) self.assertIn('
', response.body) @@ -106,27 +106,22 @@ def test_that_no_get_results_in_500_error(self): def test_requests_for_invalid_paths(self): """Test that requests for invalid paths result in a 404 error.""" - response = self.get_response('/library/extra', expect_errors=True, - expected_status_int=404) - self.assertEqual(response.status_int, 404) + self.get_html_response( + '/library/extra', expected_status_int=404) - response = self.get_response('/library/data/extra', expect_errors=True, - expected_status_int=404) - self.assertEqual(response.status_int, 404) + self.get_html_response( + '/library/data/extra', expected_status_int=404) - response = self.testapp.post( - '/library/extra', params={}, expect_errors=True) - self.assertEqual(response.status_int, 404) + self.post_json( + '/library/extra', payload={}, expected_status_int=404) - response = self.testapp.put( - '/library/extra', params={}, expect_errors=True) - self.assertEqual(response.status_int, 404) + self.put_json( + '/library/extra', payload={}, expected_status_int=404) def test_redirect_in_logged_out_states(self): """Test for a redirect in logged out state on '/'.""" - response = self.get_response('/', expected_status_int=302) - self.assertEqual(response.status_int, 302) + response = self.get_html_response('/', expected_status_int=302) self.assertIn('splash', response.headers['location']) def test_root_redirect_rules_for_logged_in_learners(self): @@ -135,8 +130,7 @@ def test_root_redirect_rules_for_logged_in_learners(self): # Since by default the homepage for all logged in users is the # learner dashboard, going to '/' should redirect to the learner # dashboard page. - response = self.get_response('/', expected_status_int=302) - self.assertEqual(response.status_int, 302) + response = self.get_html_response('/', expected_status_int=302) self.assertIn('learner_dashboard', response.headers['location']) self.logout() @@ -153,8 +147,7 @@ def test_root_redirect_rules_for_users_with_no_user_contribution_model( # Since by default the homepage for all logged in users is the # learner dashboard, going to '/' should redirect to the learner # dashboard page. - response = self.get_response('/', expected_status_int=302) - self.assertEqual(response.status_int, 302) + response = self.get_html_response('/', expected_status_int=302) self.assertIn('learner_dashboard', response.headers['location']) self.logout() @@ -167,7 +160,7 @@ def test_root_redirect_rules_for_logged_in_creators(self): # Since the default dashboard has been set as creator dashboard, going # to '/' should redirect to the creator dashboard. - response = self.get_response('/', expected_status_int=302) + response = self.get_html_response('/', expected_status_int=302) self.assertIn('creator_dashboard', response.headers['location']) def test_root_redirect_rules_for_logged_in_editors(self): @@ -197,8 +190,7 @@ def test_root_redirect_rules_for_logged_in_editors(self): # Since user has edited one exploration created by another user, # going to '/' should redirect to the dashboard page. - response = self.get_response('/', expected_status_int=302) - self.assertEqual(response.status_int, 302) + response = self.get_html_response('/', expected_status_int=302) self.assertIn('dashboard', response.headers['location']) self.logout() @@ -281,8 +273,7 @@ def setUp(self): def test_jinja_autoescaping(self): form_url = '<[angular_tag]> x{{51 * 3}}y' with self.swap(feconf, 'SITE_FEEDBACK_FORM_URL', form_url): - response = self.get_response('/fake') - self.assertEqual(response.status_int, 200) + response = self.get_html_response('/fake') self.assertIn('<[angular_tag]>', response.body) self.assertNotIn('<[angular_tag]>', response.body) @@ -323,7 +314,6 @@ def setUp(self): def test_downloadable(self): response = self.testapp.get('/mock') - self.assertEqual(response.status_int, 200) self.assertEqual( response.content_disposition, 'attachment; filename=example.pdf') @@ -339,10 +329,10 @@ def test_logout_page(self): # Logout with valid query arg. This test only validates that the login # cookies have expired after hitting the logout url. current_page = '/explore/0' - response = self.get_response(current_page) - self.assertEqual(response.status_int, 200) - response = self.get_response(current_user_services.create_logout_url( - current_page), expected_status_int=302) + response = self.get_html_response(current_page) + response = self.get_html_response( + current_user_services.create_logout_url( + current_page), expected_status_int=302) expiry_date = response.headers['Set-Cookie'].rsplit('=', 1) self.assertTrue( @@ -544,7 +534,7 @@ def test_error_response_for_get_request_of_type_json_has_json_format(self): self.testapp = webtest.TestApp(app) response = self.get_json( - '/fake', expect_errors=True, expected_status_int=500) + '/fake', expected_status_int=500) self.assertTrue(isinstance(response, dict)) diff --git a/core/controllers/classifier_test.py b/core/controllers/classifier_test.py index a5da601b445d..84745be26aa7 100644 --- a/core/controllers/classifier_test.py +++ b/core/controllers/classifier_test.py @@ -107,7 +107,7 @@ def test_trained_classifier_handler(self): # Normal end-to-end test. self.post_json( '/ml/trainedclassifierhandler', self.payload, - expect_errors=False, expected_status_int=200) + expected_status_int=200) classifier_training_jobs = ( classifier_services.get_classifier_training_jobs( self.exp_id, self.exploration.version, ['Home'])) @@ -171,7 +171,7 @@ def mock_get_classifier_training_job_by_id(_): # Post ML Job. self.post_json( '/ml/trainedclassifierhandler', self.payload, - expect_errors=True, expected_status_int=500) + expected_status_int=500) # Check that there are now emails sent. messages = self.mail_stub.get_sent_messages( @@ -189,21 +189,21 @@ def test_error_on_prod_mode_and_default_vm_id(self): with self.swap(constants, 'DEV_MODE', False): self.post_json( '/ml/trainedclassifierhandler', self.payload, - expect_errors=True, expected_status_int=401) + expected_status_int=401) def test_error_on_different_signatures(self): # Altering data to result in different signatures. self.payload['message']['job_id'] = 'different_job_id' self.post_json( '/ml/trainedclassifierhandler', self.payload, - expect_errors=True, expected_status_int=401) + expected_status_int=401) def test_error_on_invalid_message(self): # Altering message dict to result in invalid dict. self.payload['message']['job_id'] = 1 self.post_json( '/ml/trainedclassifierhandler', self.payload, - expect_errors=True, expected_status_int=400) + expected_status_int=400) class NextJobHandlerTest(test_utils.GenericTestBase): @@ -250,13 +250,13 @@ def setUp(self): def test_next_job_handler(self): json_response = self.post_json( '/ml/nextjobhandler', - self.payload, expect_errors=False, + self.payload, expected_status_int=200) self.assertEqual(json_response, self.expected_response) classifier_services.mark_training_jobs_failed([self.job_id]) json_response = self.post_json( '/ml/nextjobhandler', - self.payload, expect_errors=False, + self.payload, expected_status_int=200) self.assertEqual(json_response, {}) @@ -265,18 +265,18 @@ def test_error_on_prod_mode_and_default_vm_id(self): with self.swap(constants, 'DEV_MODE', False): self.post_json( '/ml/nextjobhandler', self.payload, - expect_errors=True, expected_status_int=401) + expected_status_int=401) def test_error_on_modified_message(self): # Altering data to result in different signatures. self.payload['message'] = 'different' self.post_json( '/ml/nextjobhandler', self.payload, - expect_errors=True, expected_status_int=401) + expected_status_int=401) def test_error_on_invalid_vm_id(self): # Altering vm_id to result in invalid signature. self.payload['vm_id'] = 1 self.post_json( '/ml/nextjobhandler', self.payload, - expect_errors=True, expected_status_int=401) + expected_status_int=401) diff --git a/core/controllers/collection_editor_test.py b/core/controllers/collection_editor_test.py index f40700d8a87e..c9f59d8c1c08 100644 --- a/core/controllers/collection_editor_test.py +++ b/core/controllers/collection_editor_test.py @@ -71,26 +71,24 @@ def test_access_collection_editor_page(self): # Check that it is possible to access a page with specific version # number. - response = self.get_json( + self.get_json( '%s/%s?v=1' % ( feconf.COLLECTION_DATA_URL_PREFIX, self.COLLECTION_ID)) # Check that non-editors cannot access the editor page. This is due # to them not being whitelisted. - response = self.get_response( + self.get_html_response( '%s/%s' % ( feconf.COLLECTION_EDITOR_URL_PREFIX, self.COLLECTION_ID), expected_status_int=302) - self.assertEqual(response.status_int, 302) # Check that whitelisted users can access and edit in the editor page. self.login(self.EDITOR_EMAIL) - response = self.get_response( + self.get_html_response( '%s/%s' % ( feconf.COLLECTION_EDITOR_URL_PREFIX, self.COLLECTION_ID)) - self.assertEqual(response.status_int, 200) json_response = self.get_json( '%s/%s' % (feconf.COLLECTION_RIGHTS_PREFIX, self.COLLECTION_ID)) @@ -106,8 +104,7 @@ def test_editable_collection_handler_get(self): self.get_json( '%s/%s' % ( feconf.COLLECTION_EDITOR_DATA_URL_PREFIX, - self.COLLECTION_ID), expect_errors=True, - expected_status_int=401) + self.COLLECTION_ID), expected_status_int=401) # Check that whitelisted users can access the data # from the editable_collection_data_handler. @@ -136,21 +133,20 @@ def test_editable_collection_handler_put_cannot_access(self): self.login(self.VIEWER_EMAIL) # Call get handler to return the csrf token. - response = self.get_response( + response = self.get_html_response( '%s/%s' % ( feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID)) csrf_token = self.get_csrf_token_from_response(response) # Ensure viewers do not have access to the PUT Handler. - json_response = self.put_json( + self.put_json( '%s/%s' % ( feconf.COLLECTION_EDITOR_DATA_URL_PREFIX, self.COLLECTION_ID), - self.json_dict, expect_errors=True, - csrf_token=csrf_token, expected_status_int=401) + self.json_dict, csrf_token=csrf_token, + expected_status_int=401) - self.assertEqual(json_response['status_code'], 401) self.logout() def test_editable_collection_handler_put_can_access(self): @@ -168,7 +164,7 @@ def test_editable_collection_handler_put_can_access(self): self.login(self.EDITOR_EMAIL) # Call get handler to return the csrf token. - response = self.get_response( + response = self.get_html_response( '%s/%s' % ( feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID)) @@ -250,7 +246,7 @@ def test_publish_unpublish_collection(self): collection_id, self.owner_id, exploration_id=exploration_id) rights_manager.publish_exploration(self.owner, exploration_id) collection = collection_services.get_collection_by_id(collection_id) - response = self.get_response( + response = self.get_html_response( '%s/%s' % ( feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID)) csrf_token = self.get_csrf_token_from_response(response) @@ -263,7 +259,7 @@ def test_publish_unpublish_collection(self): # Login as admin and unpublish the collection. self.login(self.ADMIN_EMAIL) - response = self.get_response( + response = self.get_html_response( '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID)) csrf_token = self.get_csrf_token_from_response(response) response_dict = self.put_json( diff --git a/core/controllers/collection_viewer_test.py b/core/controllers/collection_viewer_test.py index e32ee143b709..d03a8bc20318 100644 --- a/core/controllers/collection_viewer_test.py +++ b/core/controllers/collection_viewer_test.py @@ -41,17 +41,15 @@ def setUp(self): self.save_new_valid_collection(self.COLLECTION_ID, self.editor_id) def test_unpublished_collections_are_invisible_to_logged_out_users(self): - response = self.get_response( + self.get_html_response( '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID), - expect_errors=True, expected_status_int=404) - self.assertEqual(response.status_int, 404) + expected_status_int=404) def test_unpublished_collections_are_invisible_to_unconnected_users(self): self.login(self.NEW_USER_EMAIL) - response = self.get_response( + self.get_html_response( '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID), - expect_errors=True, expected_status_int=404) - self.assertEqual(response.status_int, 404) + expected_status_int=404) self.logout() def test_unpublished_collections_are_invisible_to_other_editors(self): @@ -60,42 +58,37 @@ def test_unpublished_collections_are_invisible_to_other_editors(self): self.save_new_valid_collection('cid2', self.OTHER_EDITOR_EMAIL) self.login(self.OTHER_EDITOR_EMAIL) - response = self.get_response( + self.get_html_response( '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID), - expect_errors=True, expected_status_int=404) - self.assertEqual(response.status_int, 404) + expected_status_int=404) self.logout() def test_unpublished_collections_are_visible_to_their_editors(self): self.login(self.EDITOR_EMAIL) - response = self.get_response( + self.get_html_response( '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID)) - self.assertEqual(response.status_int, 200) self.logout() def test_unpublished_collections_are_visible_to_admins(self): self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.set_admins([self.ADMIN_USERNAME]) self.login(self.ADMIN_EMAIL) - response = self.get_response( + self.get_html_response( '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID)) - self.assertEqual(response.status_int, 200) self.logout() def test_published_collections_are_visible_to_logged_out_users(self): rights_manager.publish_collection(self.editor, self.COLLECTION_ID) - response = self.get_response( + self.get_html_response( '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID)) - self.assertEqual(response.status_int, 200) def test_published_collections_are_visible_to_logged_in_users(self): rights_manager.publish_collection(self.editor, self.COLLECTION_ID) self.login(self.NEW_USER_EMAIL) - response = self.get_response( + self.get_html_response( '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID)) - self.assertEqual(response.status_int, 200) class CollectionViewerControllerEndToEndTests(test_utils.GenericTestBase): diff --git a/core/controllers/concept_card_viewer_test.py b/core/controllers/concept_card_viewer_test.py index 4e66fc94848d..f596ad86abaa 100644 --- a/core/controllers/concept_card_viewer_test.py +++ b/core/controllers/concept_card_viewer_test.py @@ -67,4 +67,4 @@ def test_get_concept_card_fails_when_new_structures_not_enabled(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', False): self.get_json( '%s/%s' % (feconf.CONCEPT_CARD_DATA_URL_PREFIX, self.skill_id), - expect_errors=True, expected_status_int=404) + expected_status_int=404) diff --git a/core/controllers/creator_dashboard_test.py b/core/controllers/creator_dashboard_test.py index 0229c114a35d..50aebc710b4b 100644 --- a/core/controllers/creator_dashboard_test.py +++ b/core/controllers/creator_dashboard_test.py @@ -59,25 +59,22 @@ class HomePageTests(test_utils.GenericTestBase): def test_logged_out_homepage(self): """Test the logged-out version of the home page.""" - response = self.get_response('/', expected_status_int=302) + response = self.get_html_response('/', expected_status_int=302) - self.assertEqual(response.status_int, 302) self.assertIn('splash', response.headers['location']) def test_notifications_dashboard_redirects_for_logged_out_users(self): """Test the logged-out view of the notifications dashboard.""" - response = self.get_response( + response = self.get_html_response( '/notifications_dashboard', expected_status_int=302) - self.assertEqual(response.status_int, 302) # This should redirect to the login page. self.assertIn('signup', response.headers['location']) self.assertIn('notifications_dashboard', response.headers['location']) self.login('reader@example.com') - response = self.get_response( + self.get_html_response( '/notifications_dashboard', expected_status_int=302) # This should redirect the user to complete signup. - self.assertEqual(response.status_int, 302) self.logout() def test_logged_in_notifications_dashboard(self): @@ -85,8 +82,7 @@ def test_logged_in_notifications_dashboard(self): self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME) self.login(self.EDITOR_EMAIL) - response = self.get_response('/notifications_dashboard') - self.assertEqual(response.status_int, 200) + self.get_html_response('/notifications_dashboard') self.logout() @@ -721,8 +717,7 @@ def test_new_exploration_ids(self): """Test generation of exploration ids.""" self.login(self.EDITOR_EMAIL) - response = self.get_response(feconf.CREATOR_DASHBOARD_URL) - self.assertEqual(response.status_int, 200) + response = self.get_html_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) exp_a_id = self.post_json( feconf.NEW_EXPLORATION_URL, {}, csrf_token=csrf_token diff --git a/core/controllers/editor_test.py b/core/controllers/editor_test.py index c773e0778fdc..27dec43dba15 100644 --- a/core/controllers/editor_test.py +++ b/core/controllers/editor_test.py @@ -134,8 +134,7 @@ def test_editor_page(self): """Test access to editor pages for the sample exploration.""" # Check that non-editors can access, but not edit, the editor page. - response = self.get_response('/create/0') - self.assertEqual(response.status_int, 200) + response = self.get_html_response('/create/0') self.assertIn('Help others learn new things.', response.body) self.assert_cannot_edit(response.body) @@ -143,9 +142,8 @@ def test_editor_page(self): self.login(self.EDITOR_EMAIL) # Check that it is now possible to access and edit the editor page. - response = self.get_response('/create/0') + response = self.get_html_response('/create/0') self.assertIn('Help others learn new things.', response.body) - self.assertEqual(response.status_int, 200) self.assert_can_edit(response.body) self.assertIn('Stats', response.body) self.assertIn('History', response.body) @@ -174,21 +172,19 @@ def test_that_default_exploration_cannot_be_published(self): """ self.login(self.EDITOR_EMAIL) - response = self.get_response(feconf.CREATOR_DASHBOARD_URL) - self.assertEqual(response.status_int, 200) + response = self.get_html_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) exp_id = self.post_json( feconf.NEW_EXPLORATION_URL, {}, csrf_token=csrf_token )[creator_dashboard.EXPLORATION_ID_KEY] - response = self.get_response('/create/%s' % exp_id) + response = self.get_html_response('/create/%s' % exp_id) csrf_token = self.get_csrf_token_from_response(response) publish_url = '%s/%s' % (feconf.EXPLORATION_STATUS_PREFIX, exp_id) self.put_json( publish_url, { 'make_public': True, - }, csrf_token=csrf_token, - expect_errors=True, expected_status_int=400) + }, csrf_token=csrf_token, expected_status_int=400) self.logout() @@ -197,7 +193,7 @@ def test_add_new_state_error_cases(self): current_version = 1 self.login(self.EDITOR_EMAIL) - response = self.get_response('/create/0') + response = self.get_html_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) def _get_payload(new_state_name, version=None): @@ -215,8 +211,7 @@ def _get_payload(new_state_name, version=None): def _put_and_expect_400_error(payload): return self.put_json( '/createhandler/data/0', payload, - csrf_token=csrf_token, expect_errors=True, - expected_status_int=400) + csrf_token=csrf_token, expected_status_int=400) # A request with no version number is invalid. response_dict = _put_and_expect_400_error(_get_payload('New state')) @@ -284,7 +279,7 @@ def test_logout_from_invalid_url(self): invalid_current_page)) self.login(self.OWNER_EMAIL) - response = self.get_response( + response = self.get_html_response( invalid_logout_url, expected_status_int=302) self.assertEqual(response.status_int, 302) response.follow() @@ -309,7 +304,7 @@ def test_logout_from_invalid_extra_url(self): invalid_current_page)) self.login(self.OWNER_EMAIL) - response = self.get_response( + response = self.get_html_response( invalid_logout_url, expected_status_int=302) self.assertEqual(response.status_int, 302) response.follow() @@ -334,7 +329,7 @@ def test_logout_from_invalid_regex_exp_id(self): invalid_current_page)) self.login(self.OWNER_EMAIL) - response = self.get_response( + response = self.get_html_response( invalid_logout_url, expected_status_int=302) self.assertEqual(response.status_int, 302) response.follow() @@ -349,7 +344,7 @@ def test_logout_from_empty_url(self): empty_redirect_logout_url = '/exploration_editor_logout?return_url=' self.login(self.OWNER_EMAIL) - response = self.get_response( + response = self.get_html_response( empty_redirect_logout_url, expected_status_int=302) self.assertEqual(response.status_int, 302) @@ -369,7 +364,7 @@ def test_logout_from_invalid_exploration_id(self): '/exploration_editor_logout?return_url=%s' % invalid_current_page) self.login(self.OWNER_EMAIL) - response = self.get_response( + response = self.get_html_response( invalid_logout_url, expected_status_int=302) self.assertEqual(response.status_int, 302) response.follow() @@ -390,10 +385,9 @@ def test_logout_from_unpublished_exploration_editor(self): current_page_url = '%s/%s' % ( feconf.EDITOR_URL_PREFIX, unpublished_exp_id) self.login(self.OWNER_EMAIL) - response = self.get_response(current_page_url) - self.assertEqual(response.status_int, 200) + response = self.get_html_response(current_page_url) - response = self.get_response( + response = self.get_html_response( '/exploration_editor_logout?return_url=%s' % current_page_url, expected_status_int=302) self.assertEqual(response.status_int, 302) @@ -415,12 +409,11 @@ def test_logout_from_published_exploration_editor(self): current_page_url = '%s/%s' % ( feconf.EDITOR_URL_PREFIX, published_exp_id) self.login(self.OWNER_EMAIL) - response = self.get_response(current_page_url) - self.assertEqual(response.status_int, 200) + response = self.get_html_response(current_page_url) rights_manager.publish_exploration(self.owner, published_exp_id) - response = self.get_response( + response = self.get_html_response( '/exploration_editor_logout?return_url=%s' % current_page_url, expected_status_int=302) self.assertEqual(response.status_int, 302) @@ -611,7 +604,7 @@ def test_exploration_download_handler_for_default_exploration(self): 'state_name': 'State 3', })], 'changes') exploration = exp_services.get_exploration_by_id(exp_id) - response = self.get_response('/create/%s' % exp_id) + response = self.get_html_response('/create/%s' % exp_id) # Check download to zip file. # Download to zip file using download handler. @@ -675,7 +668,7 @@ def test_state_yaml_handler(self): exploration.add_states(['State A', 'State 2', 'State 3']) exploration.states['State A'].update_interaction_id('TextInput') - response = self.get_response( + response = self.get_html_response( '%s/%s' % (feconf.EDITOR_URL_PREFIX, exp_id)) csrf_token = self.get_csrf_token_from_response(response) response = self.post_json('/createhandler/state_yaml/%s' % exp_id, { @@ -708,19 +701,19 @@ def test_deletion_rights_for_unpublished_exploration(self): self.login(self.EDITOR_EMAIL) self.delete_json( - '/createhandler/data/%s' % unpublished_exp_id, expect_errors=True, + '/createhandler/data/%s' % unpublished_exp_id, expected_status_int=401) self.logout() self.login(self.VIEWER_EMAIL) self.delete_json( - '/createhandler/data/%s' % unpublished_exp_id, expect_errors=True, + '/createhandler/data/%s' % unpublished_exp_id, expected_status_int=401) self.logout() self.login(self.TRANSLATOR_EMAIL) self.delete_json( - '/createhandler/data/%s' % unpublished_exp_id, expect_errors=True, + '/createhandler/data/%s' % unpublished_exp_id, expected_status_int=401) self.logout() @@ -747,25 +740,25 @@ def test_deletion_rights_for_published_exploration(self): self.login(self.EDITOR_EMAIL) self.delete_json( - '/createhandler/data/%s' % published_exp_id, expect_errors=True, + '/createhandler/data/%s' % published_exp_id, expected_status_int=401) self.logout() self.login(self.VIEWER_EMAIL) self.delete_json( - '/createhandler/data/%s' % published_exp_id, expect_errors=True, + '/createhandler/data/%s' % published_exp_id, expected_status_int=401) self.logout() self.login(self.TRANSLATOR_EMAIL) self.delete_json( - '/createhandler/data/%s' % published_exp_id, expect_errors=True, + '/createhandler/data/%s' % published_exp_id, expected_status_int=401) self.logout() self.login(self.OWNER_EMAIL) self.delete_json( - '/createhandler/data/%s' % published_exp_id, expect_errors=True, + '/createhandler/data/%s' % published_exp_id, expected_status_int=401) self.logout() @@ -893,7 +886,7 @@ def setUp(self): def test_reverting_to_old_exploration(self): """Test reverting to old exploration versions.""" # Open editor page. - response = self.get_response( + response = self.get_html_response( '%s/%s' % (feconf.EDITOR_URL_PREFIX, self.EXP_ID)) csrf_token = self.get_csrf_token_from_response(response) @@ -903,8 +896,7 @@ def test_reverting_to_old_exploration(self): '/createhandler/revert/%s' % self.EXP_ID, { 'current_version': 2, 'revert_to_version': rev_version - }, csrf_token=csrf_token, - expect_errors=True, expected_status_int=400) + }, csrf_token=csrf_token, expected_status_int=400) # Check error message. if not isinstance(rev_version, int): @@ -975,10 +967,9 @@ def test_versioning_for_default_exploration(self): self.assertNotIn('Hi, welcome to Oppia!', init_content) # v3 does not exist. - response = self.get_json( + self.get_json( '%s/%s?v=3' % (feconf.EXPLORATION_INIT_URL_PREFIX, self.EXP_ID), - expect_errors=True, expected_status_int=404) - self.assertEqual(response['status_code'], 404) + expected_status_int=404) class ExplorationEditRightsTest(BaseEditorControllerTests): @@ -999,20 +990,16 @@ def test_user_banning(self): # Joe logs in. self.login('joe@example.com') - response = self.get_response(feconf.LIBRARY_INDEX_URL) - self.assertEqual(response.status_int, 200) - response = self.get_response('/create/%s' % exp_id) - self.assertEqual(response.status_int, 200) + response = self.get_html_response(feconf.LIBRARY_INDEX_URL) + response = self.get_html_response('/create/%s' % exp_id) self.assert_can_edit(response.body) # Ban joe. self.set_banned_users(['joe']) # Test that Joe is banned (He can still access the library page). - response = self.get_response(feconf.LIBRARY_INDEX_URL) - self.assertEqual(response.status_int, 200) - response = self.get_response('/create/%s' % exp_id) - self.assertEqual(response.status_int, 200) + response = self.get_html_response(feconf.LIBRARY_INDEX_URL) + response = self.get_html_response('/create/%s' % exp_id) self.assert_cannot_edit(response.body) # Joe logs out. @@ -1020,8 +1007,7 @@ def test_user_banning(self): # Sandra logs in and is unaffected. self.login('sandra@example.com') - response = self.get_response('/create/%s' % exp_id) - self.assertEqual(response.status_int, 200) + response = self.get_html_response('/create/%s' % exp_id) self.assert_can_edit(response.body) self.logout() @@ -1061,7 +1047,7 @@ def test_for_assign_role_for_exploration(self): exploration.states['State 2'].update_interaction_id('TextInput') exploration.states['State 3'].update_interaction_id('TextInput') - response = self.get_response( + response = self.get_html_response( '%s/%s' % (feconf.EDITOR_URL_PREFIX, exp_id)) csrf_token = self.get_csrf_token_from_response(response) @@ -1096,16 +1082,14 @@ def test_for_assign_role_for_exploration(self): # Check that viewer can access editor page but cannot edit. self.login(self.VIEWER_EMAIL) - response = self.get_response('/create/%s' % exp_id) - self.assertEqual(response.status_int, 200) + response = self.get_html_response('/create/%s' % exp_id) self.assert_cannot_edit(response.body) self.assert_cannot_translate(response.body) self.logout() # Check that collaborator can access editor page and can edit. self.login(self.COLLABORATOR_EMAIL) - response = self.get_response('/create/%s' % exp_id) - self.assertEqual(response.status_int, 200) + response = self.get_html_response('/create/%s' % exp_id) self.assert_can_edit(response.body) self.assert_can_translate(response.body) csrf_token = self.get_csrf_token_from_response(response) @@ -1135,21 +1119,19 @@ def test_for_assign_role_for_exploration(self): # Check that collaborator cannot add new members. exploration = exp_services.get_exploration_by_id(exp_id) rights_url = '%s/%s' % (feconf.EXPLORATION_RIGHTS_PREFIX, exp_id) - response_dict = self.put_json( + self.put_json( rights_url, { 'version': exploration.version, 'new_member_username': self.COLLABORATOR3_USERNAME, 'new_member_role': rights_manager.ROLE_EDITOR, }, csrf_token=csrf_token, - expect_errors=True, expected_status_int=401) - self.assertEqual(response_dict['status_code'], 401) + expected_status_int=401) self.logout() # Check that collaborator2 can access editor page and can edit. self.login(self.COLLABORATOR2_EMAIL) - response = self.get_response('/create/%s' % exp_id) - self.assertEqual(response.status_int, 200) + response = self.get_html_response('/create/%s' % exp_id) self.assert_can_edit(response.body) csrf_token = self.get_csrf_token_from_response(response) @@ -1178,21 +1160,18 @@ def test_for_assign_role_for_exploration(self): # Check that collaborator2 cannot add new members. exploration = exp_services.get_exploration_by_id(exp_id) rights_url = '%s/%s' % (feconf.EXPLORATION_RIGHTS_PREFIX, exp_id) - response_dict = self.put_json( + self.put_json( rights_url, { 'version': exploration.version, 'new_member_username': self.COLLABORATOR3_USERNAME, 'new_member_role': rights_manager.ROLE_EDITOR, - }, csrf_token=csrf_token, - expect_errors=True, expected_status_int=401) - self.assertEqual(response_dict['status_code'], 401) + }, csrf_token=csrf_token, expected_status_int=401) self.logout() # Check that translator can access editor page and can only translate. self.login(self.TRANSLATOR_EMAIL) - response = self.get_response('/create/%s' % exp_id) - self.assertEqual(response.status_int, 200) + response = self.get_html_response('/create/%s' % exp_id) self.assert_cannot_edit(response.body) self.assert_can_translate(response.body) csrf_token = self.get_csrf_token_from_response(response) @@ -1200,14 +1179,12 @@ def test_for_assign_role_for_exploration(self): # Check that translator cannot add new members. exploration = exp_services.get_exploration_by_id(exp_id) rights_url = '%s/%s' % (feconf.EXPLORATION_RIGHTS_PREFIX, exp_id) - response_dict = self.put_json( + self.put_json( rights_url, { 'version': exploration.version, 'new_member_username': self.COLLABORATOR3_USERNAME, 'new_member_role': rights_manager.ROLE_EDITOR, - }, csrf_token=csrf_token, - expect_errors=True, expected_status_int=401) - self.assertEqual(response_dict['status_code'], 401) + }, csrf_token=csrf_token, expected_status_int=401) self.logout() @@ -1221,7 +1198,7 @@ def test_transfering_ownership_to_the_community(self): self.save_new_valid_exploration( exp_id, self.owner_id, title='My Exploration', end_state_name='END') - response = self.get_response('/create/%s' % exp_id) + response = self.get_html_response('/create/%s' % exp_id) csrf_token = self.get_csrf_token_from_response(response) rights_manager.publish_exploration(self.owner, exp_id) @@ -1247,8 +1224,7 @@ def test_transfering_ownership_to_the_community(self): # Check that any random user can access editor page and can edit. self.login(self.RANDOM_USER_EMAIL) - response = self.get_response('/create/%s' % exp_id) - self.assertEqual(response.status_int, 200) + response = self.get_html_response('/create/%s' % exp_id) self.assert_can_edit(response.body) self.logout() @@ -1269,7 +1245,7 @@ def test_user_exploration_emails_handler(self): exploration = exp_services.get_exploration_by_id(exp_id) - response = self.get_response( + response = self.get_html_response( '%s/%s' % (feconf.EDITOR_URL_PREFIX, exp_id)) csrf_token = self.get_csrf_token_from_response(response) @@ -1352,8 +1328,7 @@ def test_error_cases_for_email_sending(self): self.login(self.MODERATOR_EMAIL) # Go to the exploration editor page. - response = self.get_response('/create/%s' % self.EXP_ID) - self.assertEqual(response.status_int, 200) + response = self.get_html_response('/create/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) # Try to unpublish the exploration without an email body. This @@ -1362,8 +1337,7 @@ def test_error_cases_for_email_sending(self): '/createhandler/moderatorrights/%s' % self.EXP_ID, { 'email_body': None, 'version': 1, - }, csrf_token=csrf_token, - expect_errors=True, expected_status_int=400) + }, csrf_token=csrf_token, expected_status_int=400) self.assertIn( 'Moderator actions should include an email', response_dict['error']) @@ -1372,8 +1346,7 @@ def test_error_cases_for_email_sending(self): '/createhandler/moderatorrights/%s' % self.EXP_ID, { 'email_body': '', 'version': 1, - }, csrf_token=csrf_token, - expect_errors=True, expected_status_int=400) + }, csrf_token=csrf_token, expected_status_int=400) self.assertIn( 'Moderator actions should include an email', response_dict['error']) @@ -1388,7 +1361,7 @@ def test_error_cases_for_email_sending(self): self.put_json( '/createhandler/moderatorrights/%s' % self.EXP_ID, valid_payload, csrf_token=csrf_token, - expect_errors=True, expected_status_int=500) + expected_status_int=500) with self.swap(feconf, 'CAN_SEND_EMAILS', True): # Now the email gets sent with no error. @@ -1408,8 +1381,7 @@ def test_email_is_sent_correctly_when_unpublishing(self): self.login(self.MODERATOR_EMAIL) # Go to the exploration editor page. - response = self.get_response('/create/%s' % self.EXP_ID) - self.assertEqual(response.status_int, 200) + response = self.get_html_response('/create/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) new_email_body = 'Your exploration is unpublished :(' @@ -1470,8 +1442,7 @@ def test_email_functionality_cannot_be_used_by_non_moderators(self): self.login(self.EDITOR_EMAIL) # Go to the exploration editor page. - response = self.get_response('/create/%s' % self.EXP_ID) - self.assertEqual(response.status_int, 200) + response = self.get_html_response('/create/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) new_email_body = 'Your exploration is unpublished :(' @@ -1486,7 +1457,7 @@ def test_email_functionality_cannot_be_used_by_non_moderators(self): self.put_json( '/createhandler/moderatorrights/%s' % self.EXP_ID, valid_payload, csrf_token=csrf_token, - expect_errors=True, expected_status_int=401) + expected_status_int=401) self.logout() @@ -1724,7 +1695,7 @@ def setUp(self): 'is_valid': True } - response = self.get_response('/create/%s' % self.EXP_ID) + response = self.get_html_response('/create/%s' % self.EXP_ID) self.csrf_token = self.get_csrf_token_from_response(response) def test_resolve_issue_handler(self): @@ -1756,7 +1727,7 @@ def test_error_on_passing_invalid_exp_issue_dict(self): 'exp_issue_dict': self.exp_issue_dict, 'exp_version': 1 }, csrf_token=self.csrf_token, - expect_errors=True, expected_status_int=404) + expected_status_int=404) def test_error_on_passing_non_matching_exp_issue_dict(self): """Test that error is raised on passing an exploration issue dict that @@ -1770,7 +1741,7 @@ def test_error_on_passing_non_matching_exp_issue_dict(self): 'exp_issue_dict': self.exp_issue_dict, 'exp_version': 1 }, csrf_token=self.csrf_token, - expect_errors=True, expected_status_int=404) + expected_status_int=404) class EditorAutosaveTest(BaseEditorControllerTests): @@ -1836,7 +1807,7 @@ def setUp(self): self._create_exp_user_data_model_objects_for_tests() # Generate CSRF token. - response = self.get_response('/create/%s' % self.EXP_ID1) + response = self.get_html_response('/create/%s' % self.EXP_ID1) self.csrf_token = self.get_csrf_token_from_response(response) def test_exploration_loaded_with_draft_applied(self): @@ -1903,7 +1874,7 @@ def test_draft_not_updated_validation_error(self): 'change_list': self.INVALID_CHANGELIST, 'version': 2, }, csrf_token=self.csrf_token, - expect_errors=True, expected_status_int=400) + expected_status_int=400) exp_user_data = user_models.ExplorationUserDataModel.get_by_id( '%s.%s' % (self.owner_id, self.EXP_ID2)) self.assertEqual( diff --git a/core/controllers/email_dashboard_test.py b/core/controllers/email_dashboard_test.py index 6bc1fca1b5f7..386bd8abbdff 100644 --- a/core/controllers/email_dashboard_test.py +++ b/core/controllers/email_dashboard_test.py @@ -44,7 +44,7 @@ def setUp(self): def test_that_handler_works_correctly(self): self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_response('/emaildashboard')) + self.get_html_response('/emaildashboard')) self.post_json( '/emaildashboarddatahandler', { 'data': { @@ -83,15 +83,15 @@ def test_that_page_is_accessible_to_authorised_users_only(self): # Make sure that only authorised users can access query pages. self.login(self.USER_A_EMAIL) with self.assertRaisesRegexp(Exception, '401 Unauthorized'): - self.get_response('/emaildashboard') + self.get_html_response('/emaildashboard') with self.assertRaisesRegexp(Exception, '401 Unauthorized'): - self.get_response('/querystatuscheck') + self.get_html_response('/querystatuscheck') self.logout() def test_that_exception_is_raised_for_invalid_input(self): self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_response('/emaildashboard')) + self.get_html_response('/emaildashboard')) self.post_json( '/emaildashboarddatahandler', { 'data': { @@ -101,8 +101,7 @@ def test_that_exception_is_raised_for_invalid_input(self): 'created_fewer_than_n_exps': 'None', 'edited_at_least_n_exps': None, 'fake_key': 2 - }}, csrf_token=csrf_token, - expect_errors=True, expected_status_int=400) + }}, csrf_token=csrf_token, expected_status_int=400) self.post_json( '/emaildashboarddatahandler', { @@ -112,8 +111,7 @@ def test_that_exception_is_raised_for_invalid_input(self): 'created_at_least_n_exps': 'invalid_value', 'created_fewer_than_n_exps': 'None', 'edited_at_least_n_exps': None - }}, csrf_token=csrf_token, - expect_errors=True, expected_status_int=400) + }}, csrf_token=csrf_token, expected_status_int=400) self.logout() @@ -157,7 +155,7 @@ def setUp(self): def test_that_correct_emails_are_sent_to_all_users(self): self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_response('/emaildashboard')) + self.get_html_response('/emaildashboard')) self.post_json( '/emaildashboarddatahandler', { 'data': { @@ -195,7 +193,8 @@ def test_that_correct_emails_are_sent_to_all_users(self): # Send email from email dashboard result page. self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_response('/emaildashboardresult/%s' % query_model.id)) + self.get_html_response( + '/emaildashboardresult/%s' % query_model.id)) self.post_json( '/emaildashboardresult/%s' % query_model.id, { 'data': { @@ -256,10 +255,10 @@ def test_that_valid_exceptions_are_raised(self): # Check that exception is raised for incorrect query id. self.login(self.SUBMITTER_EMAIL) with self.assertRaisesRegexp(Exception, '400 Bad Request'): - self.get_response('/emaildashboardresult/%s' % 'q123') + self.get_html_response('/emaildashboardresult/%s' % 'q123') csrf_token = self.get_csrf_token_from_response( - self.get_response('/emaildashboard')) + self.get_html_response('/emaildashboard')) self.post_json( '/emaildashboarddatahandler', { 'data': { @@ -276,7 +275,8 @@ def test_that_valid_exceptions_are_raised(self): self.assertEqual( query_models[0].query_status, feconf.USER_QUERY_STATUS_PROCESSING) with self.assertRaisesRegexp(Exception, '400 Bad Request'): - self.get_response('/emaildashboardresult/%s' % query_models[0].id) + self.get_html_response( + '/emaildashboardresult/%s' % query_models[0].id) self.logout() # Complete execution of query. @@ -293,14 +293,16 @@ def test_that_valid_exceptions_are_raised(self): # Check that exception is raised for unauthorized user. self.login(self.USER_A_EMAIL) with self.assertRaisesRegexp(Exception, '401 Unauthorized'): - self.get_response('/emaildashboardresult/%s' % query_models[0].id) + self.get_html_response( + '/emaildashboardresult/%s' % query_models[0].id) self.logout() # Check that exception is raised if current user is not submitter of # that query. self.login(self.NEW_SUBMITTER_EMAIL) with self.assertRaisesRegexp(Exception, '401 Unauthorized'): - self.get_response('/emaildashboardresult/%s' % query_models[0].id) + self.get_html_response( + '/emaildashboardresult/%s' % query_models[0].id) self.logout() # Check that exception is raised for accessing query result after @@ -309,7 +311,7 @@ def test_that_valid_exceptions_are_raised(self): # Send email from email dashboard result page. self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_response( + self.get_html_response( '/emaildashboardresult/%s' % query_models[0].id)) self.post_json( '/emaildashboardresult/%s' % query_models[0].id, { @@ -326,13 +328,14 @@ def test_that_valid_exceptions_are_raised(self): query_models[0].query_status, feconf.USER_QUERY_STATUS_ARCHIVED) self.login(self.SUBMITTER_EMAIL) with self.assertRaisesRegexp(Exception, '400 Bad Request'): - self.get_response('/emaildashboardresult/%s' % query_models[0].id) + self.get_html_response( + '/emaildashboardresult/%s' % query_models[0].id) self.logout() def test_that_correct_emails_are_sent_to_max_n_recipients(self): self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_response('/emaildashboard')) + self.get_html_response('/emaildashboard')) self.post_json( '/emaildashboarddatahandler', { 'data': { @@ -356,7 +359,7 @@ def test_that_correct_emails_are_sent_to_max_n_recipients(self): # Send email from email dashboard result page. self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_response( + self.get_html_response( '/emaildashboardresult/%s' % query_models[0].id)) self.post_json( '/emaildashboardresult/%s' % query_models[0].id, { @@ -380,7 +383,7 @@ def test_that_correct_emails_are_sent_to_max_n_recipients(self): def test_that_no_emails_are_sent_if_query_is_canceled(self): self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_response('/emaildashboard')) + self.get_html_response('/emaildashboard')) self.post_json( '/emaildashboarddatahandler', { 'data': { @@ -404,7 +407,7 @@ def test_that_no_emails_are_sent_if_query_is_canceled(self): # Send email from email dashboard result page. self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_response( + self.get_html_response( '/emaildashboardresult/%s' % query_models[0].id)) self.post_json( '/emaildashboardcancelresult/%s' % query_models[0].id, {}, @@ -420,7 +423,7 @@ def test_that_no_emails_are_sent_if_query_is_canceled(self): def test_that_test_email_for_bulk_emails_is_sent(self): self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_response('/emaildashboard')) + self.get_html_response('/emaildashboard')) self.post_json( '/emaildashboarddatahandler', { 'data': { @@ -444,7 +447,7 @@ def test_that_test_email_for_bulk_emails_is_sent(self): # Check that correct test email is sent. self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_response( + self.get_html_response( '/emaildashboardresult/%s' % query_models[0].id)) self.post_json( '/emaildashboardtestbulkemailhandler/%s' % query_models[0].id, { @@ -484,7 +487,7 @@ def test_that_test_email_for_bulk_emails_is_sent(self): def test_that_test_email_is_not_sent_to_query_recipients(self): self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_response('/emaildashboard')) + self.get_html_response('/emaildashboard')) self.post_json( '/emaildashboarddatahandler', { 'data': { @@ -504,7 +507,7 @@ def test_that_test_email_is_not_sent_to_query_recipients(self): self.login(self.SUBMITTER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_response( + self.get_html_response( '/emaildashboardresult/%s' % query_models[0].id)) self.post_json( '/emaildashboardtestbulkemailhandler/%s' % query_models[0].id, { diff --git a/core/controllers/feedback_test.py b/core/controllers/feedback_test.py index ff93296aa2f6..c9c2b8acb5f2 100644 --- a/core/controllers/feedback_test.py +++ b/core/controllers/feedback_test.py @@ -54,7 +54,7 @@ def setUp(self): # The corresponding user has already registered as an editor, and has a # username. self.login(self.EDITOR_EMAIL) - response = self.get_response('/create/%s' % self.EXP_ID) + response = self.get_html_response('/create/%s' % self.EXP_ID) self.csrf_token = self.get_csrf_token_from_response(response) self.post_json('%s/%s' % ( feconf.FEEDBACK_THREADLIST_URL_PREFIX, self.EXP_ID @@ -68,12 +68,12 @@ def setUp(self): def test_invalid_exploration_ids_return_page_not_found(self): self.get_json( '%s/bad_exp_id' % feconf.FEEDBACK_THREADLIST_URL_PREFIX, - expect_errors=True, expected_status_int=404) + expected_status_int=404) def test_invalid_thread_ids_return_400_response(self): self.get_json( '%s/invalid_thread_id' % feconf.FEEDBACK_THREAD_URL_PREFIX, - expect_errors=True, expected_status_int=400) + expected_status_int=400) def test_non_logged_in_users_can_view_threads_and_messages(self): # Non-logged-in users can see the thread list. @@ -103,8 +103,7 @@ def test_non_logged_in_users_cannot_create_threads_and_messages(self): { 'subject': self.UNICODE_TEST_STRING, 'text': self.UNICODE_TEST_STRING, - }, csrf_token=self.csrf_token, - expect_errors=True, expected_status_int=401) + }, csrf_token=self.csrf_token, expected_status_int=401) thread_url = '%s/%s' % ( feconf.FEEDBACK_THREAD_URL_PREFIX, 'exploration.0.dummy_thread_id') @@ -113,8 +112,7 @@ def test_non_logged_in_users_cannot_create_threads_and_messages(self): thread_url, { 'exploration_id': '0', 'text': self.UNICODE_TEST_STRING, - }, csrf_token=self.csrf_token, - expect_errors=True, expected_status_int=401) + }, csrf_token=self.csrf_token, expected_status_int=401) class FeedbackThreadIntegrationTests(test_utils.GenericTestBase): @@ -133,7 +131,7 @@ def setUp(self): def test_create_thread(self): self.login(self.EDITOR_EMAIL) - response = self.get_response('/create/%s' % self.EXP_ID) + response = self.get_html_response('/create/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.post_json( '%s/%s' % (feconf.FEEDBACK_THREADLIST_URL_PREFIX, self.EXP_ID), { @@ -166,29 +164,27 @@ def test_create_thread(self): def test_missing_thread_subject_raises_400_error(self): self.login(self.EDITOR_EMAIL) - response = self.get_response('/create/%s' % self.EXP_ID) + response = self.get_html_response('/create/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) response_dict = self.post_json( '%s/%s' % (feconf.FEEDBACK_THREADLIST_URL_PREFIX, self.EXP_ID), { 'state_name': None, 'text': u'Thread Text ¡unicode!', - }, csrf_token=csrf_token, - expect_errors=True, expected_status_int=400) + }, csrf_token=csrf_token, expected_status_int=400) self.assertEqual( response_dict['error'], 'A thread subject must be specified.') self.logout() def test_missing_thread_text_raises_400_error(self): self.login(self.EDITOR_EMAIL) - response = self.get_response('/create/%s' % self.EXP_ID) + response = self.get_html_response('/create/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) response_dict = self.post_json( '%s/%s' % (feconf.FEEDBACK_THREADLIST_URL_PREFIX, self.EXP_ID), { 'state_name': None, 'subject': u'New Thread ¡unicode!', - }, csrf_token=csrf_token, - expect_errors=True, expected_status_int=400) + }, csrf_token=csrf_token, expected_status_int=400) self.assertEqual( response_dict['error'], 'Text for the first message in the thread must be specified.') @@ -196,7 +192,7 @@ def test_missing_thread_text_raises_400_error(self): def test_post_message_to_existing_thread(self): self.login(self.EDITOR_EMAIL) - response = self.get_response('/create/%s' % self.EXP_ID) + response = self.get_html_response('/create/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) # First, create a thread. @@ -256,7 +252,7 @@ def test_no_username_shown_for_logged_out_learners(self): exp_services.save_new_exploration(self.editor_id, exploration) rights_manager.publish_exploration(self.editor, new_exp_id) - response = self.get_response('/create/%s' % new_exp_id) + response = self.get_html_response('/create/%s' % new_exp_id) csrf_token = self.get_csrf_token_from_response(response) self.post_json( '/explorehandler/give_feedback/%s' % new_exp_id, @@ -279,7 +275,7 @@ def test_no_username_shown_for_logged_out_learners(self): def test_message_id_assignment_for_multiple_posts_to_same_thread(self): # Create a thread for others to post to. self.login(self.EDITOR_EMAIL) - response = self.get_response('/create/%s' % self.EXP_ID) + response = self.get_html_response('/create/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.post_json( '%s/%s' % (feconf.FEEDBACK_THREADLIST_URL_PREFIX, self.EXP_ID), { @@ -327,7 +323,7 @@ def _get_email(index): # Each of these users posts a new message to the same thread. for num in range(num_users): self.login(_get_email(num)) - response = self.get_response('/create/%s' % self.EXP_ID) + response = self.get_html_response('/create/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.post_json( thread_url, { @@ -409,7 +405,7 @@ def _get_message_ids_in_a_thread(self, thread_id): def test_feedback_threads(self): self.login(self.USER_EMAIL) - response = self.get_response(feconf.LIBRARY_INDEX_URL) + response = self.get_html_response(feconf.LIBRARY_INDEX_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json('%s/%s' % ( @@ -436,7 +432,7 @@ def test_feedback_threads(self): self.logout() self.login(self.OWNER_EMAIL_1) - response = self.get_response(feconf.LIBRARY_INDEX_URL) + response = self.get_html_response(feconf.LIBRARY_INDEX_URL) csrf_token = self.get_csrf_token_from_response(response) # The owner opens the feedback thread. @@ -466,7 +462,7 @@ def test_feedback_threads(self): self.logout() self.login(self.USER_EMAIL) - response = self.get_response(feconf.LIBRARY_INDEX_URL) + response = self.get_html_response(feconf.LIBRARY_INDEX_URL) csrf_token = self.get_csrf_token_from_response(response) # The user opens the feedback thread. @@ -496,7 +492,7 @@ def test_feedback_threads(self): # Another owner logs in. self.login(self.OWNER_EMAIL_2) - response = self.get_response(feconf.LIBRARY_INDEX_URL) + response = self.get_html_response(feconf.LIBRARY_INDEX_URL) csrf_token = self.get_csrf_token_from_response(response) # The second owner opens the feedback thread. diff --git a/core/controllers/incoming_emails_test.py b/core/controllers/incoming_emails_test.py index 4bc5b8b5f3bf..231443d89222 100644 --- a/core/controllers/incoming_emails_test.py +++ b/core/controllers/incoming_emails_test.py @@ -96,4 +96,4 @@ def test_that_assertion_is_raised_for_fake_reply_to_id(self): # Send email to Oppia. self.post_email( recipient_email, self.USER_A_EMAIL, 'feedback email reply', - 'New reply', expect_errors=True, expected_status_int=404) + 'New reply', expected_status_int=404) diff --git a/core/controllers/learner_dashboard_test.py b/core/controllers/learner_dashboard_test.py index a066117eb84e..310693be6905 100644 --- a/core/controllers/learner_dashboard_test.py +++ b/core/controllers/learner_dashboard_test.py @@ -252,7 +252,7 @@ def setUp(self): # Get the CSRF token and create a single thread with a single message. self.login(self.EDITOR_EMAIL) - response = self.get_response('/create/%s' % self.EXP_ID_1) + response = self.get_html_response('/create/%s' % self.EXP_ID_1) self.csrf_token = self.get_csrf_token_from_response(response) self.post_json('%s/%s' % ( feconf.FEEDBACK_THREADLIST_URL_PREFIX, self.EXP_ID_1 diff --git a/core/controllers/learner_playlist_test.py b/core/controllers/learner_playlist_test.py index d80cdbba6c5d..1fdc6ffc8be4 100644 --- a/core/controllers/learner_playlist_test.py +++ b/core/controllers/learner_playlist_test.py @@ -71,7 +71,7 @@ def setUp(self): def test_add_exploration_to_learner_playlist(self): self.login(self.VIEWER_EMAIL) - response = self.get_response(feconf.LEARNER_DASHBOARD_URL) + response = self.get_html_response(feconf.LEARNER_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) # Add one exploration to the playlist. @@ -169,7 +169,7 @@ def test_add_exploration_to_learner_playlist(self): def test_add_collection_to_learner_playlist(self): self.login(self.VIEWER_EMAIL) - response = self.get_response(feconf.LEARNER_DASHBOARD_URL) + response = self.get_html_response(feconf.LEARNER_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) # Add one collection to the playlist. diff --git a/core/controllers/library_test.py b/core/controllers/library_test.py index 78f8846c238d..009d2730a131 100644 --- a/core/controllers/library_test.py +++ b/core/controllers/library_test.py @@ -45,8 +45,7 @@ def setUp(self): def test_library_page(self): """Test access to the library page.""" - response = self.get_response(feconf.LIBRARY_INDEX_URL) - self.assertEqual(response.status_int, 200) + response = self.get_html_response(feconf.LIBRARY_INDEX_URL) response.mustcontain('Library - Oppia') def test_library_handler_demo_exploration(self): @@ -199,11 +198,9 @@ class LibraryGroupPageTests(test_utils.GenericTestBase): def test_library_group_pages(self): """Test access to the top rated and recently published pages.""" - response = self.get_response(feconf.LIBRARY_TOP_RATED_URL) - self.assertEqual(response.status_int, 200) + self.get_html_response(feconf.LIBRARY_TOP_RATED_URL) - response = self.get_response(feconf.LIBRARY_RECENTLY_PUBLISHED_URL) - self.assertEqual(response.status_int, 200) + self.get_html_response(feconf.LIBRARY_RECENTLY_PUBLISHED_URL) def test_handler_for_recently_published_library_group_page(self): """Test library handler for recently published group page.""" diff --git a/core/controllers/moderator_test.py b/core/controllers/moderator_test.py index 5ee50c78460d..c17d6b4e5cd0 100644 --- a/core/controllers/moderator_test.py +++ b/core/controllers/moderator_test.py @@ -24,31 +24,26 @@ class ModeratorPageTests(test_utils.GenericTestBase): def test_moderator_page(self): """Tests access to the Moderator page.""" # Try accessing the moderator page without logging in. - response = self.get_response('/moderator', expected_status_int=302) - self.assertEqual(response.status_int, 302) + self.get_html_response('/moderator', expected_status_int=302) # Try accessing the moderator page without being a moderator or admin. self.signup(self.VIEWER_EMAIL, self.VIEWER_USERNAME) self.login(self.VIEWER_EMAIL) - response = self.get_response('/moderator', expect_errors=True, - expected_status_int=401) - self.assertEqual(response.status_int, 401) + self.get_html_response('/moderator', expected_status_int=401) self.logout() # Try accessing the moderator page after logging in as a moderator. self.signup(self.MODERATOR_EMAIL, self.MODERATOR_USERNAME) self.set_moderators([self.MODERATOR_USERNAME]) self.login(self.MODERATOR_EMAIL) - response = self.get_response('/moderator') - self.assertEqual(response.status_int, 200) + self.get_html_response('/moderator') self.logout() # Try accessing the moderator page after logging in as an admin. self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.set_admins([self.ADMIN_USERNAME]) self.login(self.ADMIN_EMAIL) - response = self.get_response('/moderator') - self.assertEqual(response.status_int, 200) + self.get_html_response('/moderator') self.logout() @@ -73,8 +68,7 @@ def setUp(self): def test_unpublished_activities_cannot_be_added_to_featured_list(self): self.login(self.MODERATOR_EMAIL) - response = self.get_response('/moderator') - self.assertEqual(response.status_int, 200) + response = self.get_html_response('/moderator') csrf_token = self.get_csrf_token_from_response(response) # Posting a list that includes private activities results in an error. @@ -84,8 +78,7 @@ def test_unpublished_activities_cannot_be_added_to_featured_list(self): 'type': 'exploration', 'id': self.EXP_ID_2, }], - }, csrf_token=csrf_token, - expect_errors=True, expected_status_int=400) + }, csrf_token=csrf_token, expected_status_int=400) self.post_json( '/moderatorhandler/featured', { 'featured_activity_reference_dicts': [{ @@ -95,8 +88,7 @@ def test_unpublished_activities_cannot_be_added_to_featured_list(self): 'type': 'exploration', 'id': self.EXP_ID_2, }], - }, csrf_token=csrf_token, - expect_errors=True, expected_status_int=400) + }, csrf_token=csrf_token, expected_status_int=400) # Posting a list that only contains public activities succeeds. self.post_json( diff --git a/core/controllers/pages_test.py b/core/controllers/pages_test.py index 47c8ecd5ede3..3a2a1de2319d 100644 --- a/core/controllers/pages_test.py +++ b/core/controllers/pages_test.py @@ -21,8 +21,7 @@ class NoninteractivePagesTests(test_utils.GenericTestBase): def test_about_page(self): """Test the About page.""" - response = self.get_response('/about') - self.assertEqual(response.status_int, 200) + response = self.get_html_response('/about') self.assertEqual(response.content_type, 'text/html') response.mustcontain( 'I18N_ABOUT_PAGE_CREDITS_TAB_HEADING', diff --git a/core/controllers/profile_test.py b/core/controllers/profile_test.py index 67e470fd1852..72a70f740b15 100644 --- a/core/controllers/profile_test.py +++ b/core/controllers/profile_test.py @@ -29,8 +29,7 @@ class SignupTests(test_utils.GenericTestBase): def test_signup_page_does_not_have_top_right_menu(self): self.login(self.EDITOR_EMAIL) - response = self.get_response(feconf.SIGNUP_URL) - self.assertEqual(response.status_int, 200) + response = self.get_html_response(feconf.SIGNUP_URL) # Sign in can't be inside an html tag, but can appear inside js code. response.mustcontain(no=['Logout']) self.logout() @@ -39,10 +38,8 @@ def test_going_somewhere_else_while_signing_in_logs_user_out(self): exp_services.load_demo('0') self.login(self.EDITOR_EMAIL) - response = self.get_response(feconf.SIGNUP_URL) - self.assertEqual(response.status_int, 200) - response = self.get_response('/create/0', expected_status_int=302) - self.assertEqual(response.status_int, 302) + response = self.get_html_response(feconf.SIGNUP_URL) + response = self.get_html_response('/create/0', expected_status_int=302) self.assertIn('Logout', response.headers['location']) self.assertIn('create', response.headers['location']) @@ -50,20 +47,18 @@ def test_going_somewhere_else_while_signing_in_logs_user_out(self): def test_accepting_terms_is_handled_correctly(self): self.login(self.EDITOR_EMAIL) - response = self.get_response(feconf.SIGNUP_URL) + response = self.get_html_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) response_dict = self.post_json( feconf.SIGNUP_DATA_URL, {'agreed_to_terms': False}, - csrf_token=csrf_token, expect_errors=True, expected_status_int=400) - self.assertEqual(response_dict['status_code'], 400) + csrf_token=csrf_token, expected_status_int=400) self.assertIn('you will need to accept', response_dict['error']) response_dict = self.post_json( feconf.SIGNUP_DATA_URL, {'agreed_to_terms': 'Hasta la vista!'}, - csrf_token=csrf_token, expect_errors=True, expected_status_int=400) - self.assertEqual(response_dict['status_code'], 400) + csrf_token=csrf_token, expected_status_int=400) self.assertIn('you will need to accept', response_dict['error']) self.post_json( @@ -76,35 +71,31 @@ def test_accepting_terms_is_handled_correctly(self): def test_username_is_handled_correctly(self): self.login(self.EDITOR_EMAIL) - response = self.get_response(feconf.SIGNUP_URL) + response = self.get_html_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) response_dict = self.post_json( feconf.SIGNUP_DATA_URL, {'agreed_to_terms': True}, - csrf_token=csrf_token, expect_errors=True, expected_status_int=400) - self.assertEqual(response_dict['status_code'], 400) + csrf_token=csrf_token, expected_status_int=400) self.assertIn('Empty username supplied', response_dict['error']) response_dict = self.post_json( feconf.SIGNUP_DATA_URL, {'username': '', 'agreed_to_terms': True}, - csrf_token=csrf_token, expect_errors=True, expected_status_int=400) - self.assertEqual(response_dict['status_code'], 400) + csrf_token=csrf_token, expected_status_int=400) self.assertIn('Empty username supplied', response_dict['error']) response_dict = self.post_json( feconf.SIGNUP_DATA_URL, {'username': '!a!', 'agreed_to_terms': True}, - csrf_token=csrf_token, expect_errors=True, expected_status_int=400) - self.assertEqual(response_dict['status_code'], 400) + csrf_token=csrf_token, expected_status_int=400) self.assertIn( 'can only have alphanumeric characters', response_dict['error']) response_dict = self.post_json( feconf.SIGNUP_DATA_URL, {'username': self.UNICODE_TEST_STRING, 'agreed_to_terms': True}, - csrf_token=csrf_token, expect_errors=True, expected_status_int=400) - self.assertEqual(response_dict['status_code'], 400) + csrf_token=csrf_token, expected_status_int=400) self.assertIn( 'can only have alphanumeric characters', response_dict['error']) @@ -117,7 +108,7 @@ def test_username_is_handled_correctly(self): def test_default_dashboard_for_new_users(self): self.login(self.EDITOR_EMAIL) - response = self.get_response(feconf.SIGNUP_URL) + response = self.get_html_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) # This user should have the creator dashboard as default. @@ -136,7 +127,7 @@ def test_default_dashboard_for_new_users(self): self.logout() self.login(self.VIEWER_EMAIL) - response = self.get_response(feconf.SIGNUP_URL) + response = self.get_html_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) # This user should have the learner dashboard as default. @@ -161,7 +152,7 @@ def test_username_check(self): self.signup('abc@example.com', username='abc') self.login(self.EDITOR_EMAIL) - response = self.get_response(feconf.SIGNUP_URL) + response = self.get_html_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) response_dict = self.post_json( @@ -182,16 +173,14 @@ def test_username_check(self): response_dict = self.post_json( feconf.USERNAME_CHECK_DATA_URL, {'username': '!!!INVALID!!!'}, - csrf_token=csrf_token, expect_errors=True, expected_status_int=400) - self.assertEqual(response_dict['status_code'], 400) + csrf_token=csrf_token, expected_status_int=400) self.assertIn( 'can only have alphanumeric characters', response_dict['error']) response_dict = self.post_json( feconf.USERNAME_CHECK_DATA_URL, {'username': self.UNICODE_TEST_STRING}, - csrf_token=csrf_token, expect_errors=True, expected_status_int=400) - self.assertEqual(response_dict['status_code'], 400) + csrf_token=csrf_token, expected_status_int=400) self.assertIn( 'can only have alphanumeric characters', response_dict['error']) @@ -202,7 +191,7 @@ class EmailPreferencesTests(test_utils.GenericTestBase): def test_user_not_setting_email_prefs_on_signup(self): self.login(self.EDITOR_EMAIL) - response = self.get_response(feconf.SIGNUP_URL) + response = self.get_html_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( feconf.SIGNUP_DATA_URL, @@ -239,7 +228,7 @@ def test_user_not_setting_email_prefs_on_signup(self): def test_user_allowing_emails_on_signup(self): self.login(self.EDITOR_EMAIL) - response = self.get_response(feconf.SIGNUP_URL) + response = self.get_html_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( feconf.SIGNUP_DATA_URL, @@ -276,7 +265,7 @@ def test_user_allowing_emails_on_signup(self): def test_user_disallowing_emails_on_signup(self): self.login(self.EDITOR_EMAIL) - response = self.get_response(feconf.SIGNUP_URL) + response = self.get_html_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( feconf.SIGNUP_DATA_URL, @@ -320,7 +309,7 @@ def test_email_preferences_updates(self): self.signup(self.EDITOR_EMAIL, username=self.EDITOR_USERNAME) editor_id = self.get_user_id_from_email(self.EDITOR_EMAIL) self.login(self.EDITOR_EMAIL) - response = self.get_response('/preferences') + response = self.get_html_response('/preferences') csrf_token = self.get_csrf_token_from_response(response) payload = { @@ -405,11 +394,9 @@ class ProfileLinkTests(test_utils.GenericTestBase): PROFILE_PIC_URL = '/preferenceshandler/profile_picture_by_username/' def test_get_profile_picture_invalid_username(self): - response = self.get_json( - '%s%s' % (self.PROFILE_PIC_URL, self.USERNAME), expect_errors=True, - expected_status_int=404 - ) - self.assertEqual(response['status_code'], 404) + self.get_json( + '%s%s' % (self.PROFILE_PIC_URL, self.USERNAME), + expected_status_int=404) def test_get_profile_picture_valid_username(self): self.signup(self.EMAIL, self.USERNAME) @@ -427,7 +414,7 @@ class ProfileDataHandlerTests(test_utils.GenericTestBase): def test_preference_page_updates(self): self.signup(self.EDITOR_EMAIL, username=self.EDITOR_USERNAME) self.login(self.EDITOR_EMAIL) - response = self.get_response('/preferences') + response = self.get_html_response('/preferences') csrf_token = self.get_csrf_token_from_response(response) original_preferences = self.get_json('/preferenceshandler/data') self.assertEqual( @@ -455,7 +442,7 @@ def test_preference_page_updates(self): def test_profile_data_is_independent_of_currently_logged_in_user(self): self.signup(self.EDITOR_EMAIL, username=self.EDITOR_USERNAME) self.login(self.EDITOR_EMAIL) - response = self.get_response('/preferences') + response = self.get_html_response('/preferences') csrf_token = self.get_csrf_token_from_response(response) self.put_json( '/preferenceshandler/data', @@ -469,7 +456,7 @@ def test_profile_data_is_independent_of_currently_logged_in_user(self): self.signup(self.VIEWER_EMAIL, username=self.VIEWER_USERNAME) self.login(self.VIEWER_EMAIL) - response = self.get_response('/preferences') + response = self.get_html_response('/preferences') csrf_token = self.get_csrf_token_from_response(response) self.put_json( '/preferenceshandler/data', @@ -629,8 +616,7 @@ def test_save_site_language_handler(self): self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME) language_code = 'es' self.login(self.EDITOR_EMAIL) - response = self.get_response('/preferences') - self.assertEqual(response.status_int, 200) + response = self.get_html_response('/preferences') csrf_token = self.get_csrf_token_from_response(response) self.put_json( '/preferenceshandler/data', { @@ -655,8 +641,7 @@ class LongUserBioHandlerTests(test_utils.GenericTestBase): def test_userbio_within_limit(self): self.signup(self.EMAIL_A, self.USERNAME_A) self.login(self.EMAIL_A) - response = self.get_response('/preferences') - self.assertEqual(response.status_int, 200) + response = self.get_html_response('/preferences') csrf_token = self.get_csrf_token_from_response(response) self.put_json( '/preferenceshandler/data', { @@ -672,17 +657,14 @@ def test_userbio_within_limit(self): def test_user_bio_exceeds_limit(self): self.signup(self.EMAIL_B, self.USERNAME_B) self.login(self.EMAIL_B) - response = self.get_response('/preferences') - self.assertEqual(response.status_int, 200) + response = self.get_html_response('/preferences') csrf_token = self.get_csrf_token_from_response(response) user_bio_response = self.put_json( '/preferenceshandler/data', { 'update_type': 'user_bio', 'data': 'I am not within 2000 char limit' * 200 }, - csrf_token=csrf_token, - expect_errors=True, - expected_status_int=400) + csrf_token=csrf_token, expected_status_int=400) self.assertEqual(user_bio_response['status_code'], 400) self.assertIn('User bio exceeds maximum character limit: 2000', user_bio_response['error']) @@ -707,5 +689,4 @@ def test_user_info_handler(self): 'user_is_logged_in': True}, json_response) self.logout() - self.get_json('/userinfohandler', expect_errors=True, - expected_status_int=401) + self.get_json('/userinfohandler', expected_status_int=401) diff --git a/core/controllers/question_editor_test.py b/core/controllers/question_editor_test.py index b51ee5183ac0..86c84dd2ff85 100644 --- a/core/controllers/question_editor_test.py +++ b/core/controllers/question_editor_test.py @@ -70,22 +70,22 @@ def setUp(self): def test_post(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): self.login(self.NEW_USER_EMAIL) - response = self.testapp.post( + response = self.get_html_response(feconf.CREATOR_DASHBOARD_URL) + csrf_token = self.get_csrf_token_from_response(response) + self.post_json( '%s/%s' % (feconf.NEW_QUESTION_URL, self.skill_id), - expect_errors=True) - self.assertEqual(response.status_int, 401) + {}, csrf_token=csrf_token, expected_status_int=401) self.logout() self.login(self.ADMIN_EMAIL) - response = self.get_response(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) question_dict = self.question.to_dict() question_dict['id'] = None self.post_json( '%s/%s' % (feconf.NEW_QUESTION_URL, self.skill_id), { 'question_dict': question_dict - }, csrf_token=csrf_token, expect_errors=False, - expected_status_int=200) + }, csrf_token=csrf_token, expected_status_int=200) all_models = question_models.QuestionModel.get_all() questions = [ question_services.get_question_from_model(model) @@ -95,15 +95,14 @@ def test_post(self): self.logout() self.login(self.TOPIC_MANAGER_EMAIL) - response = self.get_response(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) question_dict = self.question.to_dict() question_dict['id'] = None self.post_json( '%s/%s' % (feconf.NEW_QUESTION_URL, self.skill_id), { 'question_dict': question_dict - }, csrf_token=csrf_token, expect_errors=False, - expected_status_int=200) + }, csrf_token=csrf_token) all_models = question_models.QuestionModel.get_all() questions = [ question_services.get_question_from_model(model) @@ -129,25 +128,23 @@ def setUp(self): def test_post(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): self.login(self.NEW_USER_EMAIL) - response = self.get_response(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) - response = self.testapp.post( + self.post_json( '%s/%s/%s' % ( feconf.QUESTION_SKILL_LINK_URL_PREFIX, self.question_id, self.skill_id - ), expect_errors=True) - self.assertEqual(response.status_int, 401) + ), {}, csrf_token=csrf_token, expected_status_int=401) self.logout() self.login(self.ADMIN_EMAIL) - response = self.get_response(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( '%s/%s/%s' % ( feconf.QUESTION_SKILL_LINK_URL_PREFIX, self.question_id, self.skill_id - ), {}, csrf_token=csrf_token, expect_errors=False, - expected_status_int=200) + ), {}, csrf_token=csrf_token) question_summaries, _ = ( question_services.get_question_summaries_linked_to_skills( 5, [self.skill_id], '')) @@ -156,14 +153,13 @@ def test_post(self): self.logout() self.login(self.TOPIC_MANAGER_EMAIL) - response = self.get_response(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( '%s/%s/%s' % ( feconf.QUESTION_SKILL_LINK_URL_PREFIX, self.question_id_2, self.skill_id - ), {}, csrf_token=csrf_token, expect_errors=False, - expected_status_int=200) + ), {}, csrf_token=csrf_token) question_summaries, _ = ( question_services.get_question_summaries_linked_to_skills( 5, [self.skill_id], '')) @@ -180,12 +176,11 @@ def test_delete(self): self.question_id_2, self.skill_id) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): self.login(self.NEW_USER_EMAIL) - response = self.testapp.delete( + self.delete_json( '%s/%s/%s' % ( feconf.QUESTION_SKILL_LINK_URL_PREFIX, self.question_id, self.skill_id - ), expect_errors=True) - self.assertEqual(response.status_int, 401) + ), expected_status_int=401) self.logout() self.login(self.ADMIN_EMAIL) @@ -193,7 +188,7 @@ def test_delete(self): '%s/%s/%s' % ( feconf.QUESTION_SKILL_LINK_URL_PREFIX, self.question_id, self.skill_id - ), expect_errors=False) + )) question_summaries, _ = ( question_services.get_question_summaries_linked_to_skills( 5, [self.skill_id], '')) @@ -206,7 +201,7 @@ def test_delete(self): '%s/%s/%s' % ( feconf.QUESTION_SKILL_LINK_URL_PREFIX, self.question_id_2, self.skill_id - ), expect_errors=False) + )) question_summaries, _ = ( question_services.get_question_summaries_linked_to_skills( 5, [self.skill_id], '')) @@ -225,7 +220,7 @@ def test_get(self): self.get_json( '%s/%s' % ( feconf.QUESTION_EDITOR_DATA_URL_PREFIX, self.question_id), - expect_errors=True, expected_status_int=401) + expected_status_int=401) self.logout() self.login(self.ADMIN_EMAIL) @@ -288,14 +283,13 @@ def test_put(self): payload['commit_message'] = 'update question data' self.login(self.ADMIN_EMAIL) - response = self.get_response(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) response_json = self.put_json( '%s/%s' % ( feconf.QUESTION_EDITOR_DATA_URL_PREFIX, self.question_id), payload, - csrf_token=csrf_token, - expect_errors=False) + csrf_token=csrf_token) self.assertEqual( response_json['question_dict']['language_code'], 'en') self.assertEqual( @@ -308,28 +302,22 @@ def test_put(self): '%s/%s' % ( feconf.QUESTION_EDITOR_DATA_URL_PREFIX, self.question_id), payload, - csrf_token=csrf_token, - expect_errors=True, - expected_status_int=404) + csrf_token=csrf_token, expected_status_int=404) del payload['commit_message'] payload['change_list'] = change_list self.put_json( '%s/%s' % ( feconf.QUESTION_EDITOR_DATA_URL_PREFIX, self.question_id), payload, - csrf_token=csrf_token, - expect_errors=True, - expected_status_int=404) + csrf_token=csrf_token, expected_status_int=404) payload['commit_message'] = 'update question data' self.put_json( feconf.QUESTION_EDITOR_DATA_URL_PREFIX, payload, - csrf_token=csrf_token, - expect_errors=True, - expected_status_int=404) + csrf_token=csrf_token, expected_status_int=404) self.logout() self.login(self.TOPIC_MANAGER_EMAIL) - response = self.get_response(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) payload = {} new_question_data = self._create_valid_question_data('GHI') @@ -344,9 +332,7 @@ def test_put(self): response_json = self.put_json( '%s/%s' % ( feconf.QUESTION_EDITOR_DATA_URL_PREFIX, self.question_id), - payload, - csrf_token=csrf_token, - expect_errors=False) + payload, csrf_token=csrf_token) self.assertEqual( response_json['question_dict']['language_code'], 'en') @@ -359,7 +345,7 @@ def test_put(self): # Check that the question creator can edit the question. self.login(self.EDITOR_EMAIL) - response = self.get_response(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) payload = {} new_question_data = self._create_valid_question_data('GHI') @@ -374,9 +360,7 @@ def test_put(self): response_json = self.put_json( '%s/%s' % ( feconf.QUESTION_EDITOR_DATA_URL_PREFIX, self.question_id), - payload, - csrf_token=csrf_token, - expect_errors=False) + payload, csrf_token=csrf_token) self.assertEqual( response_json['question_dict']['language_code'], 'en') diff --git a/core/controllers/reader_test.py b/core/controllers/reader_test.py index 51f1c41cfad3..8729e8f2da19 100644 --- a/core/controllers/reader_test.py +++ b/core/controllers/reader_test.py @@ -58,18 +58,16 @@ def setUp(self): category=self.UNICODE_TEST_STRING) def test_unpublished_explorations_are_invisible_to_logged_out_users(self): - response = self.get_response( + self.get_html_response( '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID), - expect_errors=True, expected_status_int=404) - self.assertEqual(response.status_int, 404) + expected_status_int=404) def test_unpublished_explorations_are_invisible_to_unconnected_users(self): self.signup(self.VIEWER_EMAIL, self.VIEWER_USERNAME) self.login(self.VIEWER_EMAIL) - response = self.get_response( + self.get_html_response( '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID), - expect_errors=True, expected_status_int=404) - self.assertEqual(response.status_int, 404) + expected_status_int=404) self.logout() def test_unpublished_explorations_are_invisible_to_other_editors(self): @@ -82,43 +80,38 @@ def test_unpublished_explorations_are_invisible_to_other_editors(self): other_editor_email, other_exploration) self.login(other_editor_email) - response = self.get_response( + self.get_html_response( '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID), - expect_errors=True, expected_status_int=404) - self.assertEqual(response.status_int, 404) + expected_status_int=404) self.logout() def test_unpublished_explorations_are_visible_to_their_editors(self): self.login(self.EDITOR_EMAIL) - response = self.get_response( + self.get_html_response( '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID)) - self.assertEqual(response.status_int, 200) self.logout() def test_unpublished_explorations_are_visible_to_admins(self): self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.set_admins([self.ADMIN_USERNAME]) self.login(self.ADMIN_EMAIL) - response = self.get_response( + self.get_html_response( '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID)) - self.assertEqual(response.status_int, 200) self.logout() def test_published_explorations_are_visible_to_logged_out_users(self): rights_manager.publish_exploration(self.editor, self.EXP_ID) - response = self.get_response( + self.get_html_response( '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID)) - self.assertEqual(response.status_int, 200) def test_published_explorations_are_visible_to_logged_in_users(self): rights_manager.publish_exploration(self.editor, self.EXP_ID) self.signup(self.VIEWER_EMAIL, self.VIEWER_USERNAME) self.login(self.VIEWER_EMAIL) - response = self.get_response( + self.get_html_response( '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID)) - self.assertEqual(response.status_int, 200) class FeedbackIntegrationTest(test_utils.GenericTestBase): @@ -279,12 +272,12 @@ def test_get_exploration_pretests(self): self.get_json( '%s/%s?story_id=%s' % ( feconf.EXPLORATION_PRETESTS_URL_PREFIX, exp_id_2, STORY_ID), - expect_errors=True, expected_status_int=400) + expected_status_int=400) self.get_json( '%s/%s?story_id=%s' % ( feconf.EXPLORATION_PRETESTS_URL_PREFIX, exp_id_2, 'story'), - expect_errors=True, expected_status_int=400) + expected_status_int=400) class ExplorationParametersUnitTests(test_utils.GenericTestBase): @@ -359,7 +352,7 @@ def test_assign_and_read_ratings(self): self.signup('user@example.com', 'user') self.login('user@example.com') csrf_token = self.get_csrf_token_from_response( - self.get_response('/explore/%s' % self.EXP_ID)) + self.get_html_response('/explore/%s' % self.EXP_ID)) # User checks rating. ratings = self.get_json('/explorehandler/rating/%s' % self.EXP_ID) @@ -401,7 +394,7 @@ def test_non_logged_in_users_cannot_rate(self): self.signup('user@example.com', 'user') self.login('user@example.com') csrf_token = self.get_csrf_token_from_response( - self.get_response('/explore/%s' % self.EXP_ID)) + self.get_html_response('/explore/%s' % self.EXP_ID)) self.logout() ratings = self.get_json('/explorehandler/rating/%s' % self.EXP_ID) @@ -413,7 +406,7 @@ def test_non_logged_in_users_cannot_rate(self): '/explorehandler/rating/%s' % self.EXP_ID, { 'user_rating': 1 }, csrf_token=csrf_token, - expected_status_int=401, expect_errors=True + expected_status_int=401 ) def test_ratings_by_different_users(self): @@ -424,7 +417,7 @@ def test_ratings_by_different_users(self): self.login('a@example.com') csrf_token = self.get_csrf_token_from_response( - self.get_response('/explore/%s' % self.EXP_ID)) + self.get_html_response('/explore/%s' % self.EXP_ID)) self.put_json( '/explorehandler/rating/%s' % self.EXP_ID, { 'user_rating': 4 @@ -434,7 +427,7 @@ def test_ratings_by_different_users(self): self.login('b@example.com') csrf_token = self.get_csrf_token_from_response( - self.get_response('/explore/%s' % self.EXP_ID)) + self.get_html_response('/explore/%s' % self.EXP_ID)) ratings = self.get_json('/explorehandler/rating/%s' % self.EXP_ID) self.assertEqual(ratings['user_rating'], None) self.put_json( @@ -505,7 +498,7 @@ def _get_recommendation_ids( exploration_id, author_recommended_ids_str, collection_id_param, include_recommendations_param)) - response = self.get_response('/explore/%s' % exploration_id) + response = self.get_html_response('/explore/%s' % exploration_id) csrf_token = self.get_csrf_token_from_response(response) summaries = self.get_json( recommendations_url, params=csrf_token)['summaries'] @@ -931,7 +924,7 @@ def test_that_emails_are_sent(self): # Login and flag exploration. self.login(self.NEW_USER_EMAIL) - response = self.get_response('/explore/%s' % self.EXP_ID) + response = self.get_html_response('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.post_json( @@ -987,7 +980,7 @@ def test_non_logged_in_users_cannot_report(self): self.login(self.NEW_USER_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_response('/explore/%s' % self.EXP_ID)) + self.get_html_response('/explore/%s' % self.EXP_ID)) self.logout() # Create report for exploration. @@ -995,7 +988,7 @@ def test_non_logged_in_users_cannot_report(self): '%s/%s' % (feconf.FLAG_EXPLORATION_URL_PREFIX, self.EXP_ID), { 'report_text': self.REPORT_TEXT, }, csrf_token=csrf_token, - expected_status_int=401, expect_errors=True) + expected_status_int=401) class LearnerProgressTest(test_utils.GenericTestBase): @@ -1072,7 +1065,7 @@ def test_independent_exp_complete_event_handler(self): """ self.login(self.USER_EMAIL) - response = self.get_response(feconf.LIBRARY_INDEX_URL) + response = self.get_html_response(feconf.LIBRARY_INDEX_URL) csrf_token = self.get_csrf_token_from_response(response) payload = { @@ -1110,7 +1103,7 @@ def test_exp_complete_event_in_collection(self): """ self.login(self.USER_EMAIL) - response = self.get_response(feconf.LIBRARY_INDEX_URL) + response = self.get_html_response(feconf.LIBRARY_INDEX_URL) csrf_token = self.get_csrf_token_from_response(response) payload = { @@ -1155,7 +1148,7 @@ def test_exp_incomplete_event_handler(self): """Test handler for leaving an exploration incomplete.""" self.login(self.USER_EMAIL) - response = self.get_response(feconf.LIBRARY_INDEX_URL) + response = self.get_html_response(feconf.LIBRARY_INDEX_URL) csrf_token = self.get_csrf_token_from_response(response) payload = { @@ -1349,7 +1342,7 @@ def setUp(self): }] } - response = self.get_response('/explore/%s' % self.exp_id) + response = self.get_html_response('/explore/%s' % self.exp_id) self.csrf_token = self.get_csrf_token_from_response(response) def test_new_playthrough_gets_stored(self): @@ -1563,7 +1556,7 @@ def test_error_without_schema_version_in_payload_dict(self): '/explorehandler/store_playthrough/%s' % (self.exp_id), payload_dict_without_schema_version, csrf_token=self.csrf_token, - expect_errors=True, expected_status_int=400) + expected_status_int=400) def test_error_on_invalid_playthrough_dict(self): """Test that passing an invalid playthrough dict raises an exception.""" @@ -1576,7 +1569,7 @@ def test_error_on_invalid_playthrough_dict(self): 'issue_schema_version': 1, 'playthrough_id': None }, csrf_token=self.csrf_token, - expect_errors=True, expected_status_int=400) + expected_status_int=400) def test_playthrough_id_is_returned(self): """Test that playthrough ID is returned when it is stored for the first @@ -1719,7 +1712,7 @@ def test_none_version_raises_exception(self): self.exp_id), { 'aggregated_stats': self.aggregated_stats, 'exp_version': None}, - expect_errors=True, expected_status_int=400) + expected_status_int=400) def test_stats_events_handler(self): """Test the handler for handling batched events.""" diff --git a/core/controllers/resources_test.py b/core/controllers/resources_test.py index 4855f013d557..01131dc6e066 100644 --- a/core/controllers/resources_test.py +++ b/core/controllers/resources_test.py @@ -49,7 +49,7 @@ def test_image_upload_and_download(self): """Test image uploading and downloading.""" self.login(self.EDITOR_EMAIL) - response = self.get_response('/create/0') + response = self.get_html_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) with open(os.path.join(feconf.TESTS_DATA_DIR, 'img.png'), @@ -71,7 +71,7 @@ def test_image_upload_and_download(self): def test_non_matching_extensions_are_detected(self): self.login(self.EDITOR_EMAIL) - response = self.get_response('/create/0') + response = self.get_html_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) filename_without_extension = 'test' @@ -89,7 +89,6 @@ def test_non_matching_extensions_are_detected(self): '%s/0' % self.IMAGE_UPLOAD_URL_PREFIX, {'filename': supplied_filename}, csrf_token=csrf_token, - expect_errors=True, expected_status_int=400, upload_files=(('image', 'unused_filename', raw_image),) ) @@ -102,16 +101,16 @@ def test_non_matching_extensions_are_detected(self): # Test that neither form of the image is stored. self.get_json( self._get_image_url('0', supplied_filename), - expect_errors=True, expected_status_int=404) + expected_status_int=404) self.get_json( self._get_image_url('0', filename_with_correct_extension), - expect_errors=True, expected_status_int=404) + expected_status_int=404) def test_upload_empty_image(self): """Test upload of an empty image.""" self.login(self.EDITOR_EMAIL) - response = self.get_response('/create/0') + response = self.get_html_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) # Upload an empty image. @@ -119,7 +118,6 @@ def test_upload_empty_image(self): '%s/0' % self.IMAGE_UPLOAD_URL_PREFIX, {'filename': 'test.png'}, csrf_token=csrf_token, - expect_errors=True, expected_status_int=400, upload_files=(('image', 'unused_filename', ''),) ) @@ -132,7 +130,7 @@ def test_upload_bad_image(self): """Test upload of a malformed image.""" self.login(self.EDITOR_EMAIL) - response = self.get_response('/create/0') + response = self.get_html_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) # Upload an invalid image. @@ -140,7 +138,6 @@ def test_upload_bad_image(self): '%s/0' % self.IMAGE_UPLOAD_URL_PREFIX, {'filename': 'test.png'}, csrf_token=csrf_token, - expect_errors=True, expected_status_int=400, upload_files=(('image', 'unused_filename', 'non_image_data'),) ) @@ -154,13 +151,13 @@ def test_get_invalid_image(self): self.get_json( self._get_image_url('0', 'bad_image'), - expect_errors=True, expected_status_int=404) + expected_status_int=404) def test_bad_filenames_are_detected(self): # TODO(sll): Add more tests here. self.login(self.EDITOR_EMAIL) - response = self.get_response('/create/0') + response = self.get_html_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) with open(os.path.join(feconf.TESTS_DATA_DIR, 'img.png'), @@ -170,7 +167,7 @@ def test_bad_filenames_are_detected(self): '%s/0' % self.IMAGE_UPLOAD_URL_PREFIX, {'filename': 'test/a.png'}, csrf_token=csrf_token, - expect_errors=True, expected_status_int=400, + expected_status_int=400, upload_files=(('image', 'unused_filename', raw_image),), ) self.assertEqual(response_dict['status_code'], 400) @@ -180,7 +177,7 @@ def test_bad_filenames_are_detected(self): def test_missing_extensions_are_detected(self): self.login(self.EDITOR_EMAIL) - response = self.get_response('/create/0') + response = self.get_html_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) with open(os.path.join(feconf.TESTS_DATA_DIR, 'img.png'), @@ -190,7 +187,7 @@ def test_missing_extensions_are_detected(self): '%s/0' % self.IMAGE_UPLOAD_URL_PREFIX, {'filename': 'test'}, csrf_token=csrf_token, - expect_errors=True, expected_status_int=400, + expected_status_int=400, upload_files=(('image', 'unused_filename', raw_image),), ) self.assertEqual(response_dict['status_code'], 400) @@ -201,7 +198,7 @@ def test_missing_extensions_are_detected(self): def test_bad_extensions_are_detected(self): self.login(self.EDITOR_EMAIL) - response = self.get_response('/create/0') + response = self.get_html_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) with open(os.path.join(feconf.TESTS_DATA_DIR, 'img.png'), @@ -211,7 +208,7 @@ def test_bad_extensions_are_detected(self): '%s/0' % self.IMAGE_UPLOAD_URL_PREFIX, {'filename': 'test.pdf'}, csrf_token=csrf_token, - expect_errors=True, expected_status_int=400, + expected_status_int=400, upload_files=(('image', 'unused_filename', raw_image),), ) self.assertEqual(response_dict['status_code'], 400) @@ -224,11 +221,10 @@ def test_request_invalid_asset_type(self): """Test that requests for invalid asset type is rejected with a 404.""" self.login(self.EDITOR_EMAIL) - response = self.testapp.get( + self.get_html_response( '/assetsdevhandler/0/assets/unknowntype/myfile', - expect_errors=True) + expected_status_int=404) self.logout() - self.assertEqual(response.status_int, 404) class AssetDevHandlerAudioTest(test_utils.GenericTestBase): @@ -252,7 +248,7 @@ def setUp(self): def test_audio_upload(self): self.login(self.EDITOR_EMAIL) - response = self.get_response('/create/0') + response = self.get_html_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) with open(os.path.join(feconf.TESTS_DATA_DIR, self.TEST_AUDIO_FILE_MP3), @@ -268,7 +264,7 @@ def test_audio_upload(self): def test_audio_upload_mpeg_container(self): self.login(self.EDITOR_EMAIL) - response = self.get_response('/create/0') + response = self.get_html_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) with open(os.path.join( @@ -287,7 +283,7 @@ def test_invalid_extension_is_detected(self): """Test that invalid extensions are caught.""" self.login(self.EDITOR_EMAIL) - response = self.get_response('/create/0') + response = self.get_html_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) filename_without_extension = 'test' @@ -302,7 +298,6 @@ def test_invalid_extension_is_detected(self): '%s/0' % (self.AUDIO_UPLOAD_URL_PREFIX), {'filename': supplied_filename}, csrf_token=csrf_token, - expect_errors=True, expected_status_int=400, upload_files=(('raw_audio_file', 'unused_filename', raw_audio),) ) @@ -318,7 +313,7 @@ def test_upload_empty_audio(self): """Test upload of empty audio.""" self.login(self.EDITOR_EMAIL) - response = self.get_response('/create/0') + response = self.get_html_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) # Upload empty audio. @@ -326,7 +321,6 @@ def test_upload_empty_audio(self): '%s/0' % self.AUDIO_UPLOAD_URL_PREFIX, {'filename': 'test.mp3'}, csrf_token=csrf_token, - expect_errors=True, expected_status_int=400, upload_files=(('raw_audio_file', 'unused_filename', ''),) ) @@ -338,13 +332,12 @@ def test_upload_bad_audio(self): """Test upload of malformed audio.""" self.login(self.EDITOR_EMAIL) - response = self.get_response('/create/0') + response = self.get_html_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) response_dict = self.post_json( '%s/0' % self.AUDIO_UPLOAD_URL_PREFIX, {'filename': 'test.mp3'}, csrf_token=csrf_token, - expect_errors=True, expected_status_int=400, upload_files=( ('raw_audio_file', 'unused_filename', 'non_audio_data'),) @@ -358,7 +351,7 @@ def test_missing_extensions_are_detected(self): """Test upload of filenames with no extensions are caught.""" self.login(self.EDITOR_EMAIL) - response = self.get_response('/create/0') + response = self.get_html_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) missing_extension_filename = 'test' @@ -369,7 +362,6 @@ def test_missing_extensions_are_detected(self): '%s/0' % (self.AUDIO_UPLOAD_URL_PREFIX), {'filename': missing_extension_filename}, csrf_token=csrf_token, - expect_errors=True, expected_status_int=400, upload_files=(('raw_audio_file', 'unused_filename', raw_audio),) ) @@ -385,7 +377,7 @@ def test_exceed_max_length_detected(self): """Test that audio file is less than max playback length.""" self.login(self.EDITOR_EMAIL) - response = self.get_response('/create/0') + response = self.get_html_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) with open(os.path.join(feconf.TESTS_DATA_DIR, @@ -396,7 +388,6 @@ def test_exceed_max_length_detected(self): '%s/0' % self.AUDIO_UPLOAD_URL_PREFIX, {'filename': 'test.mp3'}, csrf_token=csrf_token, - expect_errors=True, expected_status_int=400, upload_files=(('raw_audio_file', 'unused_filename', raw_audio),) ) @@ -412,7 +403,7 @@ def test_non_matching_extensions_are_detected(self): """ self.login(self.EDITOR_EMAIL) - response = self.get_response('/create/0') + response = self.get_html_response('/create/0') csrf_token = self.get_csrf_token_from_response(response) # Use an accepted audio extension in mismatched_filename @@ -426,7 +417,6 @@ def test_non_matching_extensions_are_detected(self): '%s/0' % self.AUDIO_UPLOAD_URL_PREFIX, {'filename': mismatched_filename}, csrf_token=csrf_token, - expect_errors=True, expected_status_int=400, upload_files=(('raw_audio_file', 'unused_filename', raw_audio),) ) diff --git a/core/controllers/skill_editor_test.py b/core/controllers/skill_editor_test.py index 0546f2ea4965..db1b9c79c96f 100644 --- a/core/controllers/skill_editor_test.py +++ b/core/controllers/skill_editor_test.py @@ -53,7 +53,8 @@ def _get_csrf_token_for_put(self): csrf_token = None url_prefix = feconf.SKILL_EDITOR_URL_PREFIX with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.get_response('%s/%s' % (url_prefix, self.skill_id)) + response = self.get_html_response( + '%s/%s' % (url_prefix, self.skill_id)) csrf_token = self.get_csrf_token_from_response(response) return csrf_token @@ -89,31 +90,25 @@ def test_access_skill_editor_page(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): # Check that non-admins cannot access the editor page. self.login(self.NEW_USER_EMAIL) - response = self.get_response( - self.url, expect_errors=True, expected_status_int=401) - self.assertEqual(response.status_int, 401) + self.get_html_response( + self.url, expected_status_int=401) self.logout() # Check that admins can access and edit in the editor page. self.login(self.ADMIN_EMAIL) - response = self.get_response(self.url) - self.assertEqual(response.status_int, 200) + self.get_html_response(self.url) self.logout() def test_skill_editor_page_fails(self): self.login(self.ADMIN_EMAIL) # Check GET returns 404 when new strutures' pages are not enabled. with self.swap(constants, 'ENABLE_NEW_STRUCTURES', False): - response = self.get_response(self.url, expect_errors=True, - expected_status_int=404) - self.assertEqual(response.status_int, 404) + self.get_html_response(self.url, expected_status_int=404) # Check GET returns 404 when cannot get skill by id. self._delete_skill_model_and_memcache(self.admin_id, self.skill_id) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.get_response(self.url, expect_errors=True, - expected_status_int=404) - self.assertEqual(response.status_int, 404) + self.get_html_response(self.url, expected_status_int=404) self.logout() @@ -145,9 +140,7 @@ def test_skill_rights_handler_fails(self): skill_services_swap = self.swap( skill_services, 'get_skill_rights', self._mock_get_skill_rights) with skill_services_swap: - self.get_json( - self.url, expect_errors=True, - expected_status_int=404) + self.get_json(self.url, expected_status_int=404) self.logout() @@ -181,15 +174,11 @@ def test_editable_skill_handler_get_fails(self): self.login(self.ADMIN_EMAIL) # Check GET returns 404 when new strutures' pages are not enabled. with self.swap(constants, 'ENABLE_NEW_STRUCTURES', False): - self.get_json( - self.url, expect_errors=True, - expected_status_int=404) + self.get_json(self.url, expected_status_int=404) # Check GET returns 404 when cannot get skill by id. self._delete_skill_model_and_memcache(self.admin_id, self.skill_id) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - self.get_json( - self.url, expect_errors=True, - expected_status_int=404) + self.get_json(self.url, expected_status_int=404) self.logout() def test_editable_skill_handler_put_succeeds(self): @@ -210,20 +199,22 @@ def test_editable_skill_handler_put_fails(self): csrf_token = self._get_csrf_token_for_put() # Check PUT returns 404 when new strutures' pages are not enabled. with self.swap(constants, 'ENABLE_NEW_STRUCTURES', False): - self.put_json(self.url, self.put_payload, csrf_token=csrf_token, - expect_errors=True, expected_status_int=404) + self.put_json( + self.url, self.put_payload, csrf_token=csrf_token, + expected_status_int=404) # Check PUT returns 400 when an exception is raised updating the # skill. update_skill_swap = self.swap( skill_services, 'update_skill', self._mock_update_skill_raise_exception) with update_skill_swap: - self.put_json(self.url, self.put_payload, csrf_token=csrf_token, - expect_errors=True, expected_status_int=400) + self.put_json( + self.url, self.put_payload, csrf_token=csrf_token, + expected_status_int=400) # Check PUT returns 404 when cannot get skill by id. self._delete_skill_model_and_memcache(self.admin_id, self.skill_id) - self.put_json(self.url, {}, csrf_token=csrf_token, - expect_errors=True, expected_status_int=404) + self.put_json( + self.url, {}, csrf_token=csrf_token, expected_status_int=404) self.logout() def test_editable_skill_handler_delete_succeeds(self): @@ -239,16 +230,14 @@ def test_editable_skill_handler_delete_fails(self): # Check DELETE returns 404 when new strutures' pages are not # enabled. with self.swap(constants, 'ENABLE_NEW_STRUCTURES', False): - self.delete_json(self.url, expect_errors=True, - expected_status_int=404) + self.delete_json(self.url, expected_status_int=404) # Check DELETE returns 500 when the skill still has associated # questions. constants_swap = self.swap(constants, 'ENABLE_NEW_STRUCTURES', True) skill_has_questions_swap = self.swap( skill_services, 'skill_has_associated_questions', lambda x: True) with constants_swap, skill_has_questions_swap: - self.delete_json(self.url, expect_errors=True, - expected_status_int=500) + self.delete_json(self.url, expected_status_int=500) self.logout() @@ -274,16 +263,19 @@ def test_skill_publish_handler_fails(self): csrf_token = self._get_csrf_token_for_put() # Check that a skill cannot be published when the payload has no # version. - self.put_json(self.url, {}, csrf_token=csrf_token, - expect_errors=True, expected_status_int=400) + self.put_json( + self.url, {}, csrf_token=csrf_token, + expected_status_int=400) # Check that a skill cannot be published when the payload's version # is different from the skill's version. - self.put_json(self.url, {'version': -1}, csrf_token=csrf_token, - expect_errors=True, expected_status_int=400) + self.put_json( + self.url, {'version': -1}, csrf_token=csrf_token, + expected_status_int=400) # Check that a non-existing skill cannot be published. url = '%s/non-existing-id' % (feconf.SKILL_PUBLISH_URL_PREFIX) - self.put_json(url, {'version': 1}, csrf_token=csrf_token, - expect_errors=True, expected_status_int=500) + self.put_json( + url, {'version': 1}, csrf_token=csrf_token, + expected_status_int=500) # Check that the status is 401 when call to publish_skill raises an # exception. @@ -292,6 +284,7 @@ def test_skill_publish_handler_fails(self): self._mock_publish_skill_raise_exception) with skill_services_swap: csrf_token = self._get_csrf_token_for_put() - self.put_json(self.url, {'version': 1}, csrf_token=csrf_token, - expect_errors=True, expected_status_int=401) + self.put_json( + self.url, {'version': 1}, csrf_token=csrf_token, + expected_status_int=401) self.logout() diff --git a/core/controllers/story_editor_test.py b/core/controllers/story_editor_test.py index 9d0dfb0da526..00707801db8c 100644 --- a/core/controllers/story_editor_test.py +++ b/core/controllers/story_editor_test.py @@ -53,21 +53,19 @@ def test_access_story_editor_page(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): # Check that non-admins cannot access the editor page. self.login(self.NEW_USER_EMAIL) - response = self.get_response( + self.get_html_response( '%s/%s/%s' % ( feconf.STORY_EDITOR_URL_PREFIX, self.topic_id, - self.story_id), expect_errors=True, expected_status_int=401) - self.assertEqual(response.status_int, 401) + self.story_id), expected_status_int=401) self.logout() # Check that admins can access and edit in the editor # page. self.login(self.ADMIN_EMAIL) - response = self.get_response( + self.get_html_response( '%s/%s/%s' % ( feconf.STORY_EDITOR_URL_PREFIX, self.topic_id, self.story_id)) - self.assertEqual(response.status_int, 200) self.logout() def test_editable_story_handler_get(self): @@ -77,7 +75,7 @@ def test_editable_story_handler_get(self): self.get_json( '%s/%s/%s' % ( feconf.STORY_EDITOR_DATA_URL_PREFIX, self.topic_id, - self.story_id), expect_errors=True, expected_status_int=401) + self.story_id), expected_status_int=401) self.logout() # Check that admins can access the editable story data. @@ -105,7 +103,7 @@ def test_editable_story_handler_put(self): } self.login(self.ADMIN_EMAIL) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.get_response( + response = self.get_html_response( '%s/%s/%s' % ( feconf.STORY_EDITOR_URL_PREFIX, self.topic_id, self.story_id)) @@ -122,13 +120,11 @@ def test_editable_story_handler_put(self): self.logout() # Check that non-admins cannot edit a story. - json_response = self.put_json( + self.put_json( '%s/%s/%s' % ( feconf.STORY_EDITOR_DATA_URL_PREFIX, self.topic_id, self.story_id), - change_cmd, csrf_token=csrf_token, expect_errors=True, - expected_status_int=401) - self.assertEqual(json_response['status_code'], 401) + change_cmd, csrf_token=csrf_token, expected_status_int=401) def test_editable_story_handler_delete(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): @@ -142,9 +138,8 @@ def test_editable_story_handler_delete(self): # Check that non-admins cannot delete a story. self.login(self.NEW_USER_EMAIL) - response = self.testapp.delete( + self.delete_json( '%s/%s/%s' % ( feconf.STORY_EDITOR_DATA_URL_PREFIX, self.topic_id, - self.story_id), expect_errors=True) - self.assertEqual(response.status_int, 401) + self.story_id), expected_status_int=401) self.logout() diff --git a/core/controllers/subscriptions_test.py b/core/controllers/subscriptions_test.py index 6f95f46134cb..4443058d670c 100644 --- a/core/controllers/subscriptions_test.py +++ b/core/controllers/subscriptions_test.py @@ -44,7 +44,7 @@ def test_subscribe_handler(self): """Test handler for new subscriptions to creators.""" self.login(self.USER_EMAIL) - response = self.get_response(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) payload = { @@ -77,7 +77,7 @@ def test_subscribe_handler(self): # Test another user subscription. self.login(self.USER2_EMAIL) - response = self.get_response(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( @@ -99,7 +99,7 @@ def test_unsubscribe_handler(self): # Add one subscription to editor. self.login(self.USER_EMAIL) - response = self.get_response(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( feconf.SUBSCRIBE_URL_PREFIX, payload, @@ -108,7 +108,7 @@ def test_unsubscribe_handler(self): # Add another subscription. self.login(self.USER2_EMAIL) - response = self.get_response(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( feconf.SUBSCRIBE_URL_PREFIX, payload, @@ -140,7 +140,7 @@ def test_unsubscribe_handler(self): # Unsubscribing another user. self.login(self.USER_EMAIL) - response = self.get_response(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( feconf.UNSUBSCRIBE_URL_PREFIX, payload, diff --git a/core/controllers/suggestion_test.py b/core/controllers/suggestion_test.py index dcb1165f4211..372e97e74389 100644 --- a/core/controllers/suggestion_test.py +++ b/core/controllers/suggestion_test.py @@ -89,7 +89,7 @@ def setUp(self): self.logout() self.login(self.AUTHOR_EMAIL) - response = self.get_response('/explore/%s' % self.EXP_ID) + response = self.get_html_response('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.post_json( @@ -114,7 +114,7 @@ def setUp(self): self.logout() self.login(self.AUTHOR_EMAIL_2) - response = self.get_response('/explore/%s' % self.EXP_ID) + response = self.get_html_response('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.post_json( @@ -160,7 +160,7 @@ def setUp(self): def test_create_suggestion(self): self.login(self.AUTHOR_EMAIL_2) - response = self.get_response('/explore/%s' % self.EXP_ID) + response = self.get_html_response('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) exploration = exp_services.get_exploration_by_id(self.EXP_ID) @@ -193,7 +193,7 @@ def test_accept_suggestion(self): # Test editor can accept successfully. self.login(self.EDITOR_EMAIL) - response = self.get_response('/explore/%s' % self.EXP_ID) + response = self.get_html_response('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) suggestion_to_accept = self.get_json( @@ -201,7 +201,7 @@ def test_accept_suggestion(self): feconf.SUGGESTION_LIST_URL_PREFIX, self.author_id))['suggestions'][0] - response = self.get_response('/explore/%s' % self.EXP_ID) + response = self.get_html_response('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.put_json('%s/exploration/%s/%s' % ( feconf.SUGGESTION_ACTION_URL_PREFIX, @@ -232,7 +232,7 @@ def test_accept_suggestion(self): feconf.SUGGESTION_LIST_URL_PREFIX, self.author_id_2))['suggestions'][0] - response = self.get_response('/explore/%s' % self.EXP_ID) + response = self.get_html_response('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.put_json('%s/exploration/%s/%s' % ( feconf.SUGGESTION_ACTION_URL_PREFIX, @@ -241,8 +241,7 @@ def test_accept_suggestion(self): 'action': u'accept', 'commit_message': u'commit message', 'review_message': u'Accepted' - }, csrf_token=csrf_token, expect_errors=True, - expected_status_int=401) + }, csrf_token=csrf_token, expected_status_int=401) self.logout() # Testing that author cannot accept own suggestion. @@ -252,7 +251,7 @@ def test_accept_suggestion(self): feconf.SUGGESTION_LIST_URL_PREFIX, self.author_id_2))['suggestions'][0] - response = self.get_response('/explore/%s' % self.EXP_ID) + response = self.get_html_response('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.put_json('%s/exploration/%s/%s' % ( feconf.SUGGESTION_ACTION_URL_PREFIX, @@ -261,15 +260,14 @@ def test_accept_suggestion(self): 'action': u'accept', 'commit_message': u'commit message', 'review_message': u'Accepted' - }, csrf_token=csrf_token, expect_errors=True, - expected_status_int=401) + }, csrf_token=csrf_token, expected_status_int=401) # Testing users with scores above threshold can accept. self.login(self.AUTHOR_EMAIL) suggestion_services.increment_score_for_user( self.author_id, 'content.Algebra', 15) - response = self.get_response('/explore/%s' % self.EXP_ID) + response = self.get_html_response('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.put_json('%s/exploration/%s/%s' % ( feconf.SUGGESTION_ACTION_URL_PREFIX, @@ -291,7 +289,7 @@ def test_accept_suggestion(self): # Testing admins can accept suggestions. self.login(self.ADMIN_EMAIL) - response = self.get_response('/explore/%s' % self.EXP_ID) + response = self.get_html_response('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) suggestion_to_accept = self.get_json( '%s?author_id=%s' % ( @@ -325,7 +323,7 @@ def test_suggestion_list_handler(self): def test_resubmit_rejected_suggestion(self): self.login(self.EDITOR_EMAIL) - response = self.get_response('/explore/%s' % self.EXP_ID) + response = self.get_html_response('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) suggestion = suggestion_services.query_suggestions( @@ -335,7 +333,7 @@ def test_resubmit_rejected_suggestion(self): self.logout() self.login(self.AUTHOR_EMAIL) - response = self.get_response('/explore/%s' % self.EXP_ID) + response = self.get_html_response('/explore/%s' % self.EXP_ID) csrf_token = self.get_csrf_token_from_response(response) self.put_json('%s/resubmit/%s' % ( @@ -395,7 +393,7 @@ def setUp(self): feconf.CURRENT_STATES_SCHEMA_VERSION) } self.login(self.AUTHOR_EMAIL) - response = self.get_response(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( @@ -442,7 +440,7 @@ def test_accept_question_suggestion(self): )['suggestions'][0] self.login(self.ADMIN_EMAIL) - response = self.get_response(feconf.CREATOR_DASHBOARD_URL) + response = self.get_html_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): self.put_json('%s/topic/%s/%s' % ( diff --git a/core/controllers/topic_editor_test.py b/core/controllers/topic_editor_test.py index 411ad03ab26c..ff0344ab29f8 100644 --- a/core/controllers/topic_editor_test.py +++ b/core/controllers/topic_editor_test.py @@ -67,7 +67,7 @@ class TopicEditorStoryHandlerTests(BaseTopicEditorControllerTests): def test_story_creation(self): self.login(self.ADMIN_EMAIL) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.get_response( + response = self.get_html_response( '%s/%s' % (feconf.TOPIC_EDITOR_URL_PREFIX, self.topic_id)) csrf_token = self.get_csrf_token_from_response(response) json_response = self.post_json( @@ -139,7 +139,7 @@ def test_get(self): self.get_json( '%s/%s?cursor=' % ( feconf.TOPIC_EDITOR_QUESTION_URL, self.topic_id - ), expect_errors=True, expected_status_int=401) + ), expected_status_int=401) self.logout() @@ -153,8 +153,7 @@ def test_editable_subtopic_page_get(self): self.get_json( '%s/%s/%s' % ( feconf.SUBTOPIC_PAGE_EDITOR_DATA_URL_PREFIX, - self.topic_id, 1), - expect_errors=True, expected_status_int=401) + self.topic_id, 1), expected_status_int=401) self.logout() # Check that topic managers not assigned to this topic can @@ -199,25 +198,22 @@ def test_access_topic_editor_page(self): # Check that non-admin and topic_manager cannot access the editor # page. self.login(self.NEW_USER_EMAIL) - response = self.get_response( + self.get_html_response( '%s/%s' % ( feconf.TOPIC_EDITOR_URL_PREFIX, self.topic_id), - expect_errors=True, expected_status_int=401) - self.assertEqual(response.status_int, 401) + expected_status_int=401) self.logout() # Check that admins can access the editor page. self.login(self.ADMIN_EMAIL) - response = self.get_response( + self.get_html_response( '%s/%s' % (feconf.TOPIC_EDITOR_URL_PREFIX, self.topic_id)) - self.assertEqual(response.status_int, 200) self.logout() # Check that any topic manager can access the editor page. self.login(self.TOPIC_MANAGER_EMAIL) - response = self.get_response( + self.get_html_response( '%s/%s' % (feconf.TOPIC_EDITOR_URL_PREFIX, self.topic_id)) - self.assertEqual(response.status_int, 200) self.logout() @@ -228,7 +224,7 @@ def test_editable_topic_handler_get(self): self.get_json( '%s/%s' % ( feconf.TOPIC_EDITOR_DATA_URL_PREFIX, self.topic_id), - expect_errors=True, expected_status_int=401) + expected_status_int=401) self.logout() # Check that admins can access the editable topic data. @@ -277,7 +273,7 @@ def test_editable_topic_handler_put(self): } self.login(self.ADMIN_EMAIL) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.get_response( + response = self.get_html_response( '%s/%s' % (feconf.TOPIC_EDITOR_URL_PREFIX, self.topic_id)) csrf_token = self.get_csrf_token_from_response(response) @@ -309,21 +305,17 @@ def test_editable_topic_handler_put(self): # Test that any topic manager cannot edit the topic. self.login(self.TOPIC_MANAGER_EMAIL) - json_response = self.put_json( + self.put_json( '%s/%s' % ( feconf.TOPIC_EDITOR_DATA_URL_PREFIX, self.topic_id), - change_cmd, csrf_token=csrf_token, expect_errors=True, - expected_status_int=401) - self.assertEqual(json_response['status_code'], 401) + change_cmd, csrf_token=csrf_token, expected_status_int=401) self.logout() # Check that non-admins and non-topic managers cannot edit a topic. - json_response = self.put_json( + self.put_json( '%s/%s' % ( feconf.TOPIC_EDITOR_DATA_URL_PREFIX, self.topic_id), - change_cmd, csrf_token=csrf_token, expect_errors=True, - expected_status_int=401) - self.assertEqual(json_response['status_code'], 401) + change_cmd, csrf_token=csrf_token, expected_status_int=401) def test_editable_topic_handler_put_for_assigned_topic_manager(self): change_cmd = { @@ -363,7 +355,7 @@ def test_editable_topic_handler_put_for_assigned_topic_manager(self): self.login(self.TOPIC_MANAGER_EMAIL) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.get_response( + response = self.get_html_response( '%s/%s' % (feconf.TOPIC_EDITOR_URL_PREFIX, self.topic_id)) csrf_token = self.get_csrf_token_from_response(response) # Check that the topic manager can edit the topic now. @@ -388,11 +380,10 @@ def test_editable_topic_handler_delete(self): # Check that non-admins cannot delete a topic. self.login(self.NEW_USER_EMAIL) - response = self.testapp.delete( + self.delete_json( '%s/%s' % ( feconf.TOPIC_EDITOR_DATA_URL_PREFIX, self.topic_id), - expect_errors=True) - self.assertEqual(response.status_int, 401) + expected_status_int=401) self.logout() @@ -402,22 +393,20 @@ def test_assign_topic_manager_role(self): """Test the assign topic manager role for a topic functionality.""" self.login(self.ADMIN_EMAIL) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.get_response( + response = self.get_html_response( '%s/%s' % (feconf.TOPIC_EDITOR_URL_PREFIX, self.topic_id)) csrf_token = self.get_csrf_token_from_response(response) # Test for when assignee does not have sufficient rights to become a # manager for a topic. - json_response = self.put_json( + self.put_json( '%s/%s/%s' % ( feconf.TOPIC_MANAGER_RIGHTS_URL_PREFIX, self.topic_id, self.new_user_id), - {}, csrf_token=csrf_token, expect_errors=True, - expected_status_int=401) - self.assertEqual(json_response['status_code'], 401) + {}, csrf_token=csrf_token, expected_status_int=401) # Test for valid case. - json_response = self.put_json( + self.put_json( '%s/%s/%s' % ( feconf.TOPIC_MANAGER_RIGHTS_URL_PREFIX, self.topic_id, self.topic_manager_id), @@ -426,13 +415,11 @@ def test_assign_topic_manager_role(self): # Test for when committer doesn't have sufficient rights to assign # someone as manager. - json_response = self.put_json( + self.put_json( '%s/%s/%s' % ( feconf.TOPIC_MANAGER_RIGHTS_URL_PREFIX, self.topic_id, self.new_user_id), - {}, csrf_token=csrf_token, expect_errors=True, - expected_status_int=401) - self.assertEqual(json_response['status_code'], 401) + {}, csrf_token=csrf_token, expected_status_int=401) class TopicRightsHandlerTests(BaseTopicEditorControllerTests): @@ -454,7 +441,7 @@ def test_get_topic_rights(self): self.get_json( '%s/%s' % ( feconf.TOPIC_RIGHTS_URL_PREFIX, self.topic_id), - expect_errors=True, expected_status_int=401) + expected_status_int=401) self.logout() @@ -464,18 +451,18 @@ def test_publish_and_unpublish_topic(self): """Test the publish and unpublish functionality.""" self.login(self.ADMIN_EMAIL) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.get_response( + response = self.get_html_response( '%s/%s' % (feconf.TOPIC_EDITOR_URL_PREFIX, self.topic_id)) csrf_token = self.get_csrf_token_from_response(response) # Test whether admin can publish and unpublish a topic. - json_response = self.put_json( + self.put_json( '%s/%s' % ( feconf.TOPIC_STATUS_URL_PREFIX, self.topic_id), {'publish_status': True}, csrf_token=csrf_token) topic_rights = topic_services.get_topic_rights(self.topic_id) self.assertTrue(topic_rights.topic_is_published) - json_response = self.put_json( + self.put_json( '%s/%s' % ( feconf.TOPIC_STATUS_URL_PREFIX, self.topic_id), {'publish_status': False}, csrf_token=csrf_token) @@ -485,10 +472,9 @@ def test_publish_and_unpublish_topic(self): self.login(self.NEW_USER_EMAIL) # Test that other users cannot access topic rights. - json_response = self.put_json( + self.put_json( '%s/%s' % ( feconf.TOPIC_STATUS_URL_PREFIX, self.topic_id), {'publish_status': False}, csrf_token=csrf_token, - expect_errors=True, expected_status_int=401) - self.assertEqual(json_response['status_code'], 401) + expected_status_int=401) self.logout() diff --git a/core/controllers/topic_viewer_test.py b/core/controllers/topic_viewer_test.py index 1771da957a14..cd1803acaeb7 100644 --- a/core/controllers/topic_viewer_test.py +++ b/core/controllers/topic_viewer_test.py @@ -59,26 +59,23 @@ class TopicViewerPageTests(BaseTopicViewerControllerTests): def test_any_user_can_access_topic_viewer_page(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.get_response( + self.get_html_response( '%s/%s' % (feconf.TOPIC_VIEWER_URL_PREFIX, 'public_topic_name')) - self.assertEqual(response.status_int, 200) def test_no_user_can_access_unpublished_topic_viewer_page(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.get_response( + self.get_html_response( '%s/%s' % ( feconf.TOPIC_VIEWER_URL_PREFIX, 'private_topic_name'), - expect_errors=True, expected_status_int=404) + expected_status_int=404) - self.assertEqual(response.status_int, 404) def test_get_fails_when_new_structures_not_enabled(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', False): - response = self.get_response( + self.get_html_response( '%s/%s' % (feconf.TOPIC_VIEWER_URL_PREFIX, 'public_topic_name'), - expect_errors=True, expected_status_int=404) - self.assertEqual(response.status_int, 404) + expected_status_int=404) class TopicPageDataHandlerTests(BaseTopicViewerControllerTests): @@ -102,4 +99,4 @@ def test_get_fails_when_new_structures_not_enabled(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', False): self.get_json( '%s/%s' % (feconf.TOPIC_DATA_HANDLER, 'public_topic_name'), - expect_errors=True, expected_status_int=404) + expected_status_int=404) diff --git a/core/controllers/topics_and_skills_dashboard_test.py b/core/controllers/topics_and_skills_dashboard_test.py index 36a4d05332ed..39ca248fe06f 100644 --- a/core/controllers/topics_and_skills_dashboard_test.py +++ b/core/controllers/topics_and_skills_dashboard_test.py @@ -51,7 +51,7 @@ def _get_csrf_token_for_put(self): csrf_token = None url_prefix = feconf.TOPICS_AND_SKILLS_DASHBOARD_URL with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): - response = self.get_response(url_prefix) + response = self.get_html_response(url_prefix) csrf_token = self.get_csrf_token_from_response(response) return csrf_token @@ -62,9 +62,7 @@ def test_get_fails_when_new_structures_not_enabled(self): self.login(self.ADMIN_EMAIL) with self.swap(constants, 'ENABLE_NEW_STRUCTURES', False): url = feconf.TOPICS_AND_SKILLS_DASHBOARD_URL - response = self.get_response(url, expect_errors=True, - expected_status_int=404) - self.assertEqual(response.status_int, 404) + self.get_html_response(url, expected_status_int=404) self.logout() @@ -81,10 +79,9 @@ def test_get(self): self.save_new_skill(skill_id_2, self.admin_id, 'Description 2') with self.swap(constants, 'ENABLE_NEW_STRUCTURES', True): self.login(self.NEW_USER_EMAIL) - response = self.get_json( - feconf.TOPICS_AND_SKILLS_DASHBOARD_DATA_URL, expect_errors=True, + self.get_json( + feconf.TOPICS_AND_SKILLS_DASHBOARD_DATA_URL, expected_status_int=401) - self.assertEqual(response['status_code'], 401) self.logout() # Check that admins can access the topics and skills dashboard data. @@ -184,8 +181,7 @@ def test_topic_creation_fails_when_new_structures_not_enabled(self): csrf_token = self._get_csrf_token_for_put() self.post_json( - self.url, {}, csrf_token=csrf_token, expect_errors=True, - expected_status_int=404) + self.url, {}, csrf_token=csrf_token, expected_status_int=404) self.logout() @@ -214,8 +210,7 @@ def test_skill_creation_fails_when_new_structures_not_enabled(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', False): csrf_token = self._get_csrf_token_for_put() self.post_json( - self.url, {}, csrf_token=csrf_token, expect_errors=True, - expected_status_int=404) + self.url, {}, csrf_token=csrf_token, expected_status_int=404) self.logout() def test_skill_creation_in_invalid_topic(self): @@ -227,7 +222,7 @@ def test_skill_creation_in_invalid_topic(self): 'linked_topic_ids': ['topic'] } json_response = self.post_json( - self.url, payload, csrf_token=csrf_token, expect_errors=True, + self.url, payload, csrf_token=csrf_token, expected_status_int=400) self.assertEqual(json_response['status_code'], 400) self.logout() @@ -306,6 +301,5 @@ def test_merge_skill_fails_when_new_structures_not_enabled(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURES', False): csrf_token = self._get_csrf_token_for_put() self.post_json( - self.url, {}, csrf_token=csrf_token, expect_errors=True, - expected_status_int=404) + self.url, {}, csrf_token=csrf_token, expected_status_int=404) self.logout() diff --git a/core/controllers/translator_test.py b/core/controllers/translator_test.py index 13024b63e175..0f0d2e06b695 100644 --- a/core/controllers/translator_test.py +++ b/core/controllers/translator_test.py @@ -67,7 +67,7 @@ def setUp(self): self.login(self.TRANSLATOR_EMAIL) # Generate CSRF token. - response = self.get_response('/create/%s' % self.EXP_ID) + response = self.get_html_response('/create/%s' % self.EXP_ID) self.csrf_token = self.get_csrf_token_from_response(response) def test_transator_can_save_valid_change_list(self): @@ -100,7 +100,7 @@ def test_translator_cannot_save_invalid_change_list(self): 'commit_message': 'Changed exp objective', 'version': 1 }, csrf_token=self.csrf_token, - expect_errors=True, expected_status_int=400) + expected_status_int=400) # Checking the response to have error. self.assertEqual( response, {'status_code': 400, @@ -160,7 +160,7 @@ def setUp(self): draft_change_list_id=1).put() # Generate CSRF token. - response = self.get_response('/create/%s' % self.EXP_ID) + response = self.get_html_response('/create/%s' % self.EXP_ID) self.csrf_token = self.get_csrf_token_from_response(response) def test_draft_updated_version_valid(self): @@ -184,8 +184,7 @@ def test_draft_not_updated_validation_error(self): '/createhandler/autosave_translation_draft/%s' % self.EXP_ID, { 'change_list': self.INVALID_DRAFT_CHANGELIST, 'version': 1, - }, csrf_token=self.csrf_token, - expect_errors=True, expected_status_int=400) + }, csrf_token=self.csrf_token, expected_status_int=400) exp_user_data = user_models.ExplorationUserDataModel.get_by_id( '%s.%s' % (self.translator_id, self.EXP_ID)) self.assertEqual( diff --git a/core/domain/acl_decorators_test.py b/core/domain/acl_decorators_test.py index 62d8ac162989..ef8391977faa 100644 --- a/core/domain/acl_decorators_test.py +++ b/core/domain/acl_decorators_test.py @@ -72,8 +72,7 @@ def test_guest_can_access_published_exploration(self): def test_guest_cannot_access_private_exploration(self): with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.private_exp_id, expect_errors=True, - expected_status_int=404) + '/mock/%s' % self.private_exp_id, expected_status_int=404) def test_admin_can_access_private_exploration(self): self.login(self.ADMIN_EMAIL) @@ -93,8 +92,7 @@ def test_logged_in_user_cannot_access_not_owned_exploration(self): self.login(self.user_email) with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.private_exp_id, expect_errors=True, - expected_status_int=404) + '/mock/%s' % self.private_exp_id, expected_status_int=404) self.logout() @@ -147,8 +145,7 @@ def test_guest_can_access_published_collection(self): def test_guest_cannot_access_private_collection(self): with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.private_col_id, expect_errors=True, - expected_status_int=404) + '/mock/%s' % self.private_col_id, expected_status_int=404) def test_admin_can_access_private_collection(self): self.login(self.ADMIN_EMAIL) @@ -168,8 +165,7 @@ def test_logged_in_user_cannot_access_not_owned_private_collection(self): self.login(self.user_email) with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.private_col_id, expect_errors=True, - expected_status_int=404) + '/mock/%s' % self.private_col_id, expected_status_int=404) self.logout() @@ -220,8 +216,7 @@ def setUp(self): def test_guest_cannot_edit_collection_via_json_handler(self): with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.published_col_id, expect_errors=True, - expected_status_int=401) + '/mock/%s' % self.published_col_id, expected_status_int=401) def test_guest_is_redirected_when_using_html_handler(self): with self.swap( @@ -235,8 +230,7 @@ def test_normal_user_cannot_edit_collection(self): self.login(self.user_email) with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.private_col_id, expect_errors=True, - expected_status_int=401) + '/mock/%s' % self.private_col_id, expected_status_int=401) self.logout() def test_owner_can_edit_owned_collection(self): @@ -250,8 +244,7 @@ def test_moderator_cannot_edit_private_collection(self): self.login(self.MODERATOR_EMAIL) with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.private_col_id, expect_errors=True, - expected_status_int=401) + '/mock/%s' % self.private_col_id, expected_status_int=401) self.logout() def test_moderator_can_edit_public_collection(self): @@ -294,8 +287,7 @@ def setUp(self): def test_banned_user_cannot_create_exploration(self): self.login(self.user_email) with self.swap(self, 'testapp', self.mock_testapp): - self.get_json( - '/mock/create', expect_errors=True, expected_status_int=401) + self.get_json('/mock/create', expected_status_int=401) self.logout() def test_normal_user_can_create_exploration(self): @@ -307,8 +299,7 @@ def test_normal_user_can_create_exploration(self): def test_guest_cannot_create_exploration_via_json_handler(self): with self.swap(self, 'testapp', self.mock_testapp): - self.get_json('/mock/create', expect_errors=True, - expected_status_int=401) + self.get_json('/mock/create', expected_status_int=401) def test_guest_is_redirected_when_using_html_handler(self): with self.swap( @@ -344,8 +335,7 @@ def setUp(self): def test_guest_cannot_create_collection_via_json_handler(self): with self.swap(self, 'testapp', self.mock_testapp): - self.get_json( - '/mock/create', expect_errors=True, expected_status_int=401) + self.get_json('/mock/create', expected_status_int=401) def test_guest_is_redirected_when_using_html_handler(self): with self.swap( @@ -357,8 +347,7 @@ def test_guest_is_redirected_when_using_html_handler(self): def test_normal_user_cannot_create_collection(self): self.login(self.EDITOR_EMAIL) with self.swap(self, 'testapp', self.mock_testapp): - self.get_json( - '/mock/create', expect_errors=True, expected_status_int=401) + self.get_json('/mock/create', expected_status_int=401) self.logout() def test_collection_editor_can_create_collection(self): @@ -401,8 +390,7 @@ def setUp(self): def test_banned_user_cannot_access_editor_dashboard(self): self.login(self.user_email) with self.swap(self, 'testapp', self.mock_testapp): - self.get_json( - '/mock/access', expect_errors=True, expected_status_int=401) + self.get_json('/mock/access', expected_status_int=401) self.logout() def test_normal_user_can_access_editor_dashboard(self): @@ -448,10 +436,10 @@ def test_guest_cannot_comment_on_feedback_threads_via_json_handler(self): with self.swap(self, 'testapp', self.mock_testapp): self.get_json( '/mock/exploration.%s.thread1' % self.private_exp_id, - expect_errors=True, expected_status_int=401) + expected_status_int=401) self.get_json( '/mock/exploration.%s.thread1' % self.published_exp_id, - expect_errors=True, expected_status_int=401) + expected_status_int=401) def test_guest_is_redirected_when_using_html_handler(self): with self.swap( @@ -633,8 +621,7 @@ def setUp(self): def test_moderator_cannot_access_email_dashboard(self): self.login(self.MODERATOR_EMAIL) with self.swap(self, 'testapp', self.mock_testapp): - self.get_json( - '/mock/', expect_errors=True, expected_status_int=401) + self.get_json('/mock/', expected_status_int=401) self.logout() def test_admin_can_access_email_dashboard(self): @@ -673,8 +660,7 @@ def setUp(self): def test_guest_cannot_give_rating(self): with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.exp_id, expect_errors=True, - expected_status_int=401) + '/mock/%s' % self.exp_id, expected_status_int=401) def test_normal_user_can_give_rating(self): self.login(self.user_email) @@ -708,7 +694,7 @@ def setUp(self): def test_normal_user_cannot_access_moderator_page(self): self.login(self.user_email) with self.swap(self, 'testapp', self.mock_testapp): - self.get_json('/mock/', expect_errors=True, expected_status_int=401) + self.get_json('/mock/', expected_status_int=401) self.logout() def test_admin_can_access_moderator_page(self): @@ -743,8 +729,7 @@ def setUp(self): def test_guest_cannot_flag_exploration(self): with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.exp_id, expect_errors=True, - expected_status_int=401) + '/mock/%s' % self.exp_id, expected_status_int=401) def test_normal_user_can_flag_exploration(self): self.login(self.user_email) @@ -776,7 +761,7 @@ def setUp(self): def test_guest_cannot_subscribe_to_users(self): with self.swap(self, 'testapp', self.mock_testapp): - self.get_json('/mock/', expect_errors=True, expected_status_int=401) + self.get_json('/mock/', expected_status_int=401) def test_normal_user_can_subscribe_to_users(self): self.login(self.user_email) @@ -811,7 +796,7 @@ def setUp(self): def test_normal_user_cannot_send_moderator_emails(self): self.login(self.user_email) with self.swap(self, 'testapp', self.mock_testapp): - self.get_json('/mock/', expect_errors=True, expected_status_int=401) + self.get_json('/mock/', expected_status_int=401) self.logout() def test_admin_can_send_moderator_emails(self): @@ -879,8 +864,7 @@ def test_banned_user_cannot_translate_exploration(self): self.login(self.banned_user_email) with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.private_exp_id_1, expect_errors=True, - expected_status_int=401) + '/mock/%s' % self.private_exp_id_1, expected_status_int=401) self.logout() def test_owner_can_translate_exploration(self): @@ -901,8 +885,7 @@ def test_moderator_cannot_translate_private_exploration(self): self.login(self.MODERATOR_EMAIL) with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.private_exp_id_1, expect_errors=True, - expected_status_int=401) + '/mock/%s' % self.private_exp_id_1, expected_status_int=401) self.logout() def test_admin_can_translate_private_exploration(self): @@ -923,8 +906,7 @@ def test_translator_can_only_translate_assigned_public_exploration(self): # is not assigned for. with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.published_exp_id_2, expect_errors=True, - expected_status_int=401) + '/mock/%s' % self.published_exp_id_2, expected_status_int=401) self.logout() def test_translator_can_only_translate_assigned_private_exploration(self): @@ -938,24 +920,21 @@ def test_translator_can_only_translate_assigned_private_exploration(self): # is not assigned for. with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.private_exp_id_2, expect_errors=True, - expected_status_int=401) + '/mock/%s' % self.private_exp_id_2, expected_status_int=401) self.logout() def test_user_without_translator_role_of_exploration_cannot_translate_public_exploration(self): # pylint: disable=line-too-long self.login(self.user_email) with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.published_exp_id_1, expect_errors=True, - expected_status_int=401) + '/mock/%s' % self.published_exp_id_1, expected_status_int=401) self.logout() def test_user_without_translator_role_of_exploration_cannot_translate_private_exploration(self): # pylint: disable=line-too-long self.login(self.user_email) with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.private_exp_id_1, expect_errors=True, - expected_status_int=401) + '/mock/%s' % self.private_exp_id_1, expected_status_int=401) self.logout() @@ -998,8 +977,7 @@ def test_banned_user_cannot_edit_exploration(self): self.login(self.user_email) with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.private_exp_id, expect_errors=True, - expected_status_int=401) + '/mock/%s' % self.private_exp_id, expected_status_int=401) self.logout() def test_owner_can_edit_exploration(self): @@ -1020,8 +998,7 @@ def test_moderator_cannot_edit_private_exploration(self): self.login(self.MODERATOR_EMAIL) with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.private_exp_id, expect_errors=True, - expected_status_int=401) + '/mock/%s' % self.private_exp_id, expected_status_int=401) self.logout() def test_admin_can_edit_private_exploration(self): @@ -1060,8 +1037,7 @@ def setUp(self): def test_banned_user_cannot_update_preferences(self): self.login(self.banned_user_email) with self.swap(self, 'testapp', self.mock_testapp): - self.get_json( - '/mock/', expect_errors=True, expected_status_int=401) + self.get_json('/mock/', expected_status_int=401) self.logout() def test_normal_user_can_manage_preferences(self): @@ -1119,16 +1095,14 @@ def test_owner_cannot_delete_published_exploration(self): self.login(self.OWNER_EMAIL) with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.published_exp_id, expect_errors=True, - expected_status_int=401) + '/mock/%s' % self.published_exp_id, expected_status_int=401) self.logout() def test_moderator_cannot_delete_private_exploration(self): self.login(self.MODERATOR_EMAIL) with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.private_exp_id, expect_errors=True, - expected_status_int=401) + '/mock/%s' % self.private_exp_id, expected_status_int=401) self.logout() @@ -1161,8 +1135,7 @@ def test_banned_user_cannot_suggest_changes(self): self.login(self.banned_user_email) with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.exploration_id, expect_errors=True, - expected_status_int=401) + '/mock/%s' % self.exploration_id, expected_status_int=401) self.logout() def test_normal_user_can_suggest_changes(self): @@ -1201,13 +1174,13 @@ def setUp(self): def test_banned_user_cannot_suggest_changes(self): self.login(self.banned_user_email) with self.swap(self, 'testapp', self.mock_testapp): - self.get_json('/mock', expect_errors=True, expected_status_int=401) + self.get_json('/mock', expected_status_int=401) self.logout() def test_normal_user_can_suggest_changes(self): self.login(self.user_email) with self.swap(self, 'testapp', self.mock_testapp): - self.get_json('/mock', expected_status_int=200) + self.get_json('/mock') self.logout() @@ -1262,9 +1235,7 @@ def setUp(self): def test_author_can_resubmit_suggestion(self): self.login(self.author_email) with self.swap(self, 'testapp', self.mock_testapp): - response = self.get_json( - '/mock/%s' % self.suggestion_id, expect_errors=False, - expected_status_int=200) + response = self.get_json('/mock/%s' % self.suggestion_id) self.assertEqual(response['suggestion_id'], self.suggestion_id) self.logout() @@ -1272,8 +1243,7 @@ def test_non_author_cannot_resubmit_suggestion(self): self.login(self.user_email) with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.suggestion_id, expect_errors=True, - expected_status_int=401) + '/mock/%s' % self.suggestion_id, expected_status_int=401) self.logout() @@ -1319,16 +1289,14 @@ def test_already_published_exploration_cannot_be_published(self): self.login(self.ADMIN_EMAIL) with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.public_exp_id, expect_errors=True, - expected_status_int=401) + '/mock/%s' % self.public_exp_id, expected_status_int=401) self.logout() def test_moderator_cannot_publish_private_exploration(self): self.login(self.MODERATOR_EMAIL) with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.private_exp_id, expect_errors=True, - expected_status_int=401) + '/mock/%s' % self.private_exp_id, expected_status_int=401) self.logout() def test_admin_can_publish_any_exploration(self): @@ -1376,8 +1344,7 @@ def test_moderator_cannot_modify_roles_of_unowned_exploration(self): self.login(self.MODERATOR_EMAIL) with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.private_exp_id, expect_errors=True, - expected_status_int=401) + '/mock/%s' % self.private_exp_id, expected_status_int=401) self.logout() def test_admin_can_modify_roles_of_any_exploration(self): @@ -1458,7 +1425,7 @@ def test_owner_cannot_unpublish_public_collection(self): with self.swap(self, 'testapp', self.mock_testapp): self.get_json( '/mock_unpublish/%s' % self.published_col_id, - expect_errors=True, expected_status_int=401) + expected_status_int=401) self.logout() def test_moderator_can_unpublish_public_collection(self): @@ -1480,7 +1447,7 @@ def test_admin_cannot_publish_already_published_collection(self): self.login(self.ADMIN_EMAIL) with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock_publish/%s' % self.published_col_id, expect_errors=True, + '/mock_publish/%s' % self.published_col_id, expected_status_int=401) self.logout() @@ -1513,8 +1480,7 @@ def setUp(self): def test_banned_user_is_redirected(self): self.login(self.banned_user_email) with self.swap(self, 'testapp', self.mock_testapp): - self.get_json( - '/mock/', expect_errors=True, expected_status_int=401) + self.get_json('/mock/', expected_status_int=401) self.logout() def test_exploration_editor_can_access_learner_dashboard(self): @@ -1578,8 +1544,7 @@ def test_normal_user_cannot_edit_topic(self): self.login(self.viewer_email) with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.topic_id, expect_errors=True, - expected_status_int=401) + '/mock/%s' % self.topic_id, expected_status_int=401) self.logout() @@ -1641,16 +1606,14 @@ def test_admin_can_not_edit_other_private_skill(self): self.login(self.second_admin_email) with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.skill_id, expect_errors=True, - expected_status_int=401) + '/mock/%s' % self.skill_id, expected_status_int=401) self.logout() def test_topic_manager_can_not_edit_private_skill(self): self.login(self.manager_email) with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.skill_id, expect_errors=True, - expected_status_int=401) + '/mock/%s' % self.skill_id, expected_status_int=401) self.logout() def test_topic_manager_can_edit_public_skill(self): @@ -1666,8 +1629,7 @@ def test_normal_user_can_not_edit_public_skill(self): self.login(self.viewer_email) with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.skill_id, expect_errors=True, - expected_status_int=401) + '/mock/%s' % self.skill_id, expected_status_int=401) class EditQuestionDecoratorTests(test_utils.GenericTestBase): @@ -1725,6 +1687,5 @@ def test_any_user_cannot_edit_question(self): self.login('b@example.com') with self.swap(self, 'testapp', self.mock_testapp): self.get_json( - '/mock/%s' % self.question_id, expect_errors=True, - expected_status_int=401) + '/mock/%s' % self.question_id, expected_status_int=401) self.logout() diff --git a/core/domain/dependency_registry_test.py b/core/domain/dependency_registry_test.py index 7c020154ab6e..6e693ae84317 100644 --- a/core/domain/dependency_registry_test.py +++ b/core/domain/dependency_registry_test.py @@ -39,12 +39,10 @@ class DependencyControllerTests(test_utils.GenericTestBase): """Tests for dependency loading on user-facing pages.""" def test_no_dependencies_in_non_exploration_pages(self): - response = self.get_response(feconf.LIBRARY_INDEX_URL) - self.assertEqual(response.status_int, 200) + response = self.get_html_response(feconf.LIBRARY_INDEX_URL) response.mustcontain(no=['skulpt']) - response = self.get_response('/about') - self.assertEqual(response.status_int, 200) + response = self.get_html_response('/about') response.mustcontain(no=['skulpt']) def test_dependencies_loaded_in_exploration_editor(self): @@ -65,8 +63,7 @@ def test_dependencies_loaded_in_exploration_editor(self): # However, Skulpt is loaded in the exploration editor anyway, since # all dependencies are loaded in the exploration editor. - response = self.get_response('/create/0') - self.assertEqual(response.status_int, 200) + response = self.get_html_response('/create/0') response.mustcontain('skulpt') self.logout() @@ -85,8 +82,7 @@ def test_dependency_does_not_load_in_exploration_not_containing_it(self): self.assertNotIn('skulpt', all_dependency_ids) # Thus, Skulpt is not loaded in the exploration reader. - response = self.get_response('/explore/%s' % exp_id) - self.assertEqual(response.status_int, 200) + response = self.get_html_response('/explore/%s' % exp_id) response.mustcontain(no=['skulpt']) def test_dependency_loads_in_exploration_containing_it(self): @@ -103,6 +99,5 @@ def test_dependency_loads_in_exploration_containing_it(self): self.assertIn('skulpt', all_dependency_ids) # Thus, Skulpt is loaded in the exploration reader. - response = self.get_response('/explore/%s' % exp_id) - self.assertEqual(response.status_int, 200) + response = self.get_html_response('/explore/%s' % exp_id) response.mustcontain('skulpt') diff --git a/core/domain/email_manager_test.py b/core/domain/email_manager_test.py index 6b9bb723d664..4fb6f06b6682 100644 --- a/core/domain/email_manager_test.py +++ b/core/domain/email_manager_test.py @@ -162,7 +162,7 @@ def test_role_email_is_sent_when_editor_assigns_role(self): with self.can_send_emails_ctx, self.can_send_editor_role_email_ctx: self.login(self.EDITOR_EMAIL) - response = self.get_response('%s/%s' % ( + response = self.get_html_response('%s/%s' % ( feconf.EDITOR_URL_PREFIX, self.exploration.id)) csrf_token = self.get_csrf_token_from_response(response) self.put_json('%s/%s' % ( @@ -515,7 +515,7 @@ def test_email_not_sent_if_config_does_not_permit_it(self): self.new_email_content) self.login(self.EDITOR_EMAIL) - response = self.get_response(feconf.SIGNUP_URL) + response = self.get_html_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( @@ -545,7 +545,7 @@ def _log_error_for_tests(error_message): self.assertEqual(log_new_error_counter.times_called, 0) self.login(self.EDITOR_EMAIL) - response = self.get_response(feconf.SIGNUP_URL) + response = self.get_html_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) # No user-facing error should surface. @@ -592,7 +592,7 @@ def _log_error_for_tests(error_message): self.assertEqual(log_new_error_counter.times_called, 0) self.login(self.EDITOR_EMAIL) - response = self.get_response(feconf.SIGNUP_URL) + response = self.get_html_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) # No user-facing error should surface. @@ -637,7 +637,7 @@ def _log_error_for_tests(error_message): self.assertEqual(log_new_error_counter.times_called, 0) self.login(self.EDITOR_EMAIL) - response = self.get_response(feconf.SIGNUP_URL) + response = self.get_html_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) # No user-facing error should surface. @@ -669,7 +669,7 @@ def test_contents_of_signup_email_are_correct(self): 'Email Sender') self.login(self.EDITOR_EMAIL) - response = self.get_response(feconf.SIGNUP_URL) + response = self.get_html_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( @@ -702,7 +702,7 @@ def test_email_only_sent_once_for_repeated_signups_by_same_user(self): self.new_email_content) self.login(self.EDITOR_EMAIL) - response = self.get_response(feconf.SIGNUP_URL) + response = self.get_html_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( @@ -736,7 +736,7 @@ def test_email_only_sent_if_signup_was_successful(self): self.new_email_content) self.login(self.EDITOR_EMAIL) - response = self.get_response(feconf.SIGNUP_URL) + response = self.get_html_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( @@ -745,9 +745,7 @@ def test_email_only_sent_if_signup_was_successful(self): 'agreed_to_terms': True, 'username': 'BadUsername!!!' }, - csrf_token=csrf_token, - expect_errors=True, - expected_status_int=400) + csrf_token=csrf_token, expected_status_int=400) # Check that no email was sent. messages = self.mail_stub.get_sent_messages(to=self.EDITOR_EMAIL) @@ -780,7 +778,7 @@ def test_record_of_sent_email_is_written_to_datastore(self): self.assertEqual(len(all_models), 0) self.login(self.EDITOR_EMAIL) - response = self.get_response(feconf.SIGNUP_URL) + response = self.get_html_response(feconf.SIGNUP_URL) csrf_token = self.get_csrf_token_from_response(response) self.post_json( diff --git a/core/domain/feedback_services_test.py b/core/domain/feedback_services_test.py index 2333de403e4d..4ef4eb18a6cf 100644 --- a/core/domain/feedback_services_test.py +++ b/core/domain/feedback_services_test.py @@ -940,7 +940,7 @@ def test_that_emails_are_not_sent_if_already_seen(self): self.login(self.EDITOR_EMAIL) csrf_token = self.get_csrf_token_from_response( - self.get_response('/create/%s' % self.exploration.id)) + self.get_html_response('/create/%s' % self.exploration.id)) self.post_json( '%s/%s' % ( feconf.FEEDBACK_THREAD_VIEW_EVENT_URL, thread_id), diff --git a/core/domain/summary_services_test.py b/core/domain/summary_services_test.py index c28e21c1652a..b50cd5688199 100644 --- a/core/domain/summary_services_test.py +++ b/core/domain/summary_services_test.py @@ -258,7 +258,7 @@ def setUp(self): super(LibraryGroupsTest, self).setUp() self.login(self.ADMIN_EMAIL, is_super_admin=True) - response = self.get_response('/admin') + response = self.get_html_response('/admin') csrf_token = self.get_csrf_token_from_response(response) with self.swap( diff --git a/core/domain/user_services_test.py b/core/domain/user_services_test.py index 7aa09e5f3496..dac6cdf4831a 100644 --- a/core/domain/user_services_test.py +++ b/core/domain/user_services_test.py @@ -945,7 +945,7 @@ def test_legacy_user(self): # After logging in and requesting a URL, the last_logged_in property is # set. self.login(self.VIEWER_EMAIL) - self.get_response(feconf.LIBRARY_INDEX_URL) + self.get_html_response(feconf.LIBRARY_INDEX_URL) self.assertIsNotNone( user_services.get_user_settings(self.viewer_id).last_logged_in) self.logout() @@ -982,7 +982,7 @@ def utcnow(cls): with self.swap(datetime, 'datetime', MockDatetime11Hours): self.login(self.VIEWER_EMAIL) - self.get_response(feconf.LIBRARY_INDEX_URL) + self.get_html_response(feconf.LIBRARY_INDEX_URL) self.assertEqual( user_services.get_user_settings(self.viewer_id).last_logged_in, previous_last_logged_in_datetime) @@ -990,7 +990,7 @@ def utcnow(cls): with self.swap(datetime, 'datetime', MockDatetime13Hours): self.login(self.VIEWER_EMAIL) - self.get_response(feconf.LIBRARY_INDEX_URL) + self.get_html_response(feconf.LIBRARY_INDEX_URL) self.assertGreater( user_services.get_user_settings(self.viewer_id).last_logged_in, previous_last_logged_in_datetime) diff --git a/core/tests/test_utils.py b/core/tests/test_utils.py index 6d073cdca962..c10883844e56 100644 --- a/core/tests/test_utils.py +++ b/core/tests/test_utils.py @@ -483,12 +483,32 @@ def get_expected_logout_url(self, slug): """Returns the expected logout URL.""" return current_user_services.create_logout_url(slug) - def get_response(self, url, params=None, expect_errors=False, - expected_status_int=200, - expected_content_type='text/html'): - """Get a response, transformed to a Python object.""" + def get_response( + self, url, expected_content_type, params=None, + expected_status_int=200): + """Get a response, transformed to a Python object. + + Args: + url: str. The URL to fetch the response. + + expected_content_type: str. The content type to expect. + + params: str or dict. A query string, or a dictionary that will be + encoded into a query string. + + expected_status_int: int. The integer status code to expect. Will + be 200 if not specified. + + Returns: + webtest.TestResponse. The test response. + """ + have_errors = False + if expected_status_int >= 400 and ( + expected_status_int < 600): + have_errors = True + response = self.testapp.get( - url, params, expect_errors=expect_errors, + url, params, expect_errors=have_errors, status=expected_status_int) # Testapp takes in a status parameter which is the expected status of @@ -499,7 +519,7 @@ def get_response(self, url, params=None, expect_errors=False, # https://github.com/Pylons/webtest/blob/ # bf77326420b628c9ea5431432c7e171f88c5d874/webtest/app.py#L1119 . self.assertEqual(response.status_int, expected_status_int) - if not expect_errors: + if not have_errors: self.assertTrue(response.status_int >= 200 and response.status_int < 400) else: @@ -510,10 +530,43 @@ def get_response(self, url, params=None, expect_errors=False, return response + def get_html_response(self, url, params=None, expected_status_int=200): + """Get a HTML response, transformed to a Python object. + + Args: + url: str. The URL to fetch the response. + + params: str or dict. A query string, or a dictionary that will be + encoded into a query string. + + expected_status_int: int. The integer status code to expect. Will + be 200 if not specified. + + Returns: + webtest.TestResponse. The test response. + """ + response = self.get_response( + url, 'text/html', params=params, + expected_status_int=expected_status_int) + + return response + def get_response_without_checking_for_errors( self, url, expected_status_int_list, params=None): """Get a response, transformed to a Python object and checks for a list of status codes. + + Args: + url: str. The URL to fetch the response. + + expected_status_int_list: list(int). A list of integer status + code to expect. + + params: str or dict. A query string, or a dictionary that will be + encoded into a query string. + + Returns: + webtest.TestResponse. The test response. """ response = self.testapp.get(url, params, expect_errors=True) @@ -521,7 +574,7 @@ def get_response_without_checking_for_errors( return response - def _parse_json_response(self, json_response, expect_errors=False): + def _parse_json_response(self, json_response, expect_errors): """Convert a JSON server response to an object (such as a dict).""" if not expect_errors: self.assertTrue( @@ -537,11 +590,14 @@ def _parse_json_response(self, json_response, expect_errors=False): return json.loads(json_response.body[len(feconf.XSSI_PREFIX):]) - def get_json(self, url, params=None, expect_errors=False, - expected_status_int=200): + def get_json(self, url, params=None, expected_status_int=200): """Get a JSON response, transformed to a Python object.""" + have_errors = False + if expected_status_int >= 400 and ( + expected_status_int < 600): + have_errors = True json_response = self.testapp.get( - url, params, expect_errors=expect_errors, + url, params, expect_errors=have_errors, status=expected_status_int) # Testapp takes in a status parameter which is the expected status of @@ -552,19 +608,22 @@ def get_json(self, url, params=None, expect_errors=False, # https://github.com/Pylons/webtest/blob/ # bf77326420b628c9ea5431432c7e171f88c5d874/webtest/app.py#L1119 . self.assertEqual(json_response.status_int, expected_status_int) - return self._parse_json_response( - json_response, expect_errors=expect_errors) + return self._parse_json_response(json_response, have_errors) - def post_json(self, url, payload, csrf_token=None, expect_errors=False, + def post_json(self, url, payload, csrf_token=None, expected_status_int=200, upload_files=None): """Post an object to the server by JSON; return the received object.""" data = {'payload': json.dumps(payload)} if csrf_token: data['csrf_token'] = csrf_token + have_errors = False + if expected_status_int >= 400 and ( + expected_status_int < 600): + have_errors = True json_response = self._send_post_request( self.testapp, url, data, - expect_errors=expect_errors, + expect_errors=have_errors, expected_status_int=expected_status_int, upload_files=upload_files) # Testapp takes in a status parameter which is the expected status of @@ -574,16 +633,18 @@ def post_json(self, url, payload, csrf_token=None, expect_errors=False, # Reference URL: # https://github.com/Pylons/webtest/blob/ # bf77326420b628c9ea5431432c7e171f88c5d874/webtest/app.py#L1119 . - self.assertEqual(json_response.status_int, expected_status_int) - return self._parse_json_response( - json_response, expect_errors=expect_errors) + self.assertEqual(json_response.status_int, expected_status_int) + return self._parse_json_response(json_response, have_errors) - def delete_json(self, url, params='', expect_errors=False, - expected_status_int=200): + def delete_json(self, url, params='', expected_status_int=200): """Delete object on the server using a JSON call.""" + have_errors = False + if expected_status_int >= 400 and ( + expected_status_int < 600): + have_errors = True json_response = self.testapp.delete( - url, params, expect_errors=expect_errors, + url, params, expect_errors=have_errors, status=expected_status_int) # Testapp takes in a status parameter which is the expected status of @@ -594,11 +655,11 @@ def delete_json(self, url, params='', expect_errors=False, # https://github.com/Pylons/webtest/blob/ # bf77326420b628c9ea5431432c7e171f88c5d874/webtest/app.py#L1119 . self.assertEqual(json_response.status_int, expected_status_int) - return self._parse_json_response( - json_response, expect_errors=expect_errors) + return self._parse_json_response(json_response, have_errors) def _send_post_request( - self, app, url, data, expect_errors=False, expected_status_int=200, + self, app, url, data, expect_errors, + expected_status_int=200, upload_files=None, headers=None): json_response = app.post( str(url), data, expect_errors=expect_errors, @@ -641,15 +702,18 @@ def post_email( expect_errors=expect_errors, expected_status_int=expected_status_int) - def put_json(self, url, payload, csrf_token=None, expect_errors=False, - expected_status_int=200): + def put_json(self, url, payload, csrf_token=None, expected_status_int=200): """Put an object to the server by JSON; return the received object.""" data = {'payload': json.dumps(payload)} if csrf_token: data['csrf_token'] = csrf_token + have_errors = False + if expected_status_int >= 400 and ( + expected_status_int < 600): + have_errors = True json_response = self.testapp.put( - str(url), data, expect_errors=expect_errors) + str(url), data, expect_errors=have_errors) # Testapp takes in a status parameter which is the expected status of # the response. However this expected status is verified only when @@ -659,8 +723,7 @@ def put_json(self, url, payload, csrf_token=None, expect_errors=False, # https://github.com/Pylons/webtest/blob/ # bf77326420b628c9ea5431432c7e171f88c5d874/webtest/app.py#L1119 . self.assertEqual(json_response.status_int, expected_status_int) - return self._parse_json_response( - json_response, expect_errors=expect_errors) + return self._parse_json_response(json_response, have_errors) def get_csrf_token_from_response(self, response): """Retrieve the CSRF token from a GET response.""" @@ -680,7 +743,7 @@ def signup(self, email, username): # external calls being made to Gravatar when running the backend # tests. with self.urlfetch_mock(): - response = self.get_response(feconf.SIGNUP_URL) + response = self.get_html_response(feconf.SIGNUP_URL) self.assertEqual(response.status_int, 200) csrf_token = self.get_csrf_token_from_response(response) response = self.testapp.post( @@ -701,7 +764,7 @@ def set_config_property(self, config_obj, new_config_value): self._stash_current_user_env() self.login('tmpsuperadmin@example.com', is_super_admin=True) - response = self.get_response('/admin') + response = self.get_html_response('/admin') csrf_token = self.get_csrf_token_from_response(response) self.post_json( '/adminhandler', { @@ -724,7 +787,7 @@ def set_user_role(self, username, user_role): self._stash_current_user_env() self.login('tmpsuperadmin@example.com', is_super_admin=True) - response = self.get_response('/admin') + response = self.get_html_response('/admin') csrf_token = self.get_csrf_token_from_response(response) self.post_json( '/adminrolehandler', { From ab08985d994e5675eb2b8c1ecfb09ce057332729 Mon Sep 17 00:00:00 2001 From: Rishav Chakraborty Date: Fri, 21 Dec 2018 01:40:22 +0530 Subject: [PATCH 08/11] Lint checks --- core/controllers/classifier_test.py | 6 ++--- core/controllers/custom_landing_pages_test.py | 25 ++++++------------- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/core/controllers/classifier_test.py b/core/controllers/classifier_test.py index b28753e8e767..d5387a717c10 100644 --- a/core/controllers/classifier_test.py +++ b/core/controllers/classifier_test.py @@ -210,7 +210,7 @@ def test_error_on_invalid_classifier_data_in_message(self): self.payload['message']['classifier_data_with_floats_stringified'] = 1 self.post_json( '/ml/trainedclassifierhandler', self.payload, - expect_errors=True, expected_status_int=400) + expected_status_int=400) def test_error_on_failed_training_job_status(self): classifier_training_job_model = ( @@ -222,7 +222,7 @@ def test_error_on_failed_training_job_status(self): self.post_json( '/ml/trainedclassifierhandler', self.payload, - expect_errors=True, expected_status_int=500) + expected_status_int=500) def test_error_on_exception_in_store_classifier_data(self): classifier_training_job_model = ( @@ -233,7 +233,7 @@ def test_error_on_exception_in_store_classifier_data(self): self.post_json( '/ml/trainedclassifierhandler', self.payload, - expect_errors=True, expected_status_int=500) + expected_status_int=500) class NextJobHandlerTest(test_utils.GenericTestBase): diff --git a/core/controllers/custom_landing_pages_test.py b/core/controllers/custom_landing_pages_test.py index 309685737f1f..babf8ed28a11 100644 --- a/core/controllers/custom_landing_pages_test.py +++ b/core/controllers/custom_landing_pages_test.py @@ -24,19 +24,16 @@ def test_fraction_landing_page_without_viewer_type(self): """Test for showing the landing page for fractions, without any viewer type should redirect to teacher type. """ - response = self.testapp.get(feconf.FRACTIONS_LANDING_PAGE_URL) - self.assertEqual(response.status_int, 302) - self.assertEqual(response.content_type, 'text/html') + response = self.get_html_response( + feconf.FRACTIONS_LANDING_PAGE_URL, expected_status_int=302) response.mustcontain('/fractions_landing/teachers') def test_fraction_landing_page_with_viewer_type(self): """Test for showing the landing page for fractions, with student viewer type should respond student type. """ - response = self.testapp.get( + response = self.get_html_response( '%s?viewerType=student' % (feconf.FRACTIONS_LANDING_PAGE_URL)) - self.assertEqual(response.status_int, 200) - self.assertEqual(response.content_type, 'text/html') response.mustcontain('/fractions_landing/student') @@ -45,27 +42,19 @@ class StewardsLandingPageTest(test_utils.GenericTestBase): volunteers, or NGOs). """ def test_nonprofits_landing_page(self): - response = self.testapp.get(feconf.CUSTOM_NONPROFITS_LANDING_PAGE_URL) - self.assertEqual(response.status_int, 200) - self.assertEqual(response.content_type, 'text/html') + response = self.get_html_response(feconf.CUSTOM_NONPROFITS_LANDING_PAGE_URL) response.mustcontain( 'Let\'s work together to make compelling educational') def test_parents_landing_page(self): - response = self.testapp.get(feconf.CUSTOM_PARENTS_LANDING_PAGE_URL) - self.assertEqual(response.status_int, 200) - self.assertEqual(response.content_type, 'text/html') + response = self.get_html_response(feconf.CUSTOM_PARENTS_LANDING_PAGE_URL) response.mustcontain( 'Help your child learn with our free, engaging lessons') def test_teachers_landing_page(self): - response = self.testapp.get(feconf.CUSTOM_TEACHERS_LANDING_PAGE_URL) - self.assertEqual(response.status_int, 200) - self.assertEqual(response.content_type, 'text/html') + response = self.get_html_response(feconf.CUSTOM_TEACHERS_LANDING_PAGE_URL) response.mustcontain('Oppia\'s free, personalized lessons are a great') def test_volunteers_landing_page(self): - response = self.testapp.get(feconf.CUSTOM_VOLUNTEERS_LANDING_PAGE_URL) - self.assertEqual(response.status_int, 200) - self.assertEqual(response.content_type, 'text/html') + response = self.get_html_response(feconf.CUSTOM_VOLUNTEERS_LANDING_PAGE_URL) response.mustcontain('Help improve access to high-quality education') From 1288bd5941f4ab6c8d621bfcfdfdca9c8dc1324a Mon Sep 17 00:00:00 2001 From: Rishav Chakraborty Date: Fri, 21 Dec 2018 01:45:47 +0530 Subject: [PATCH 09/11] Lint checks --- core/controllers/custom_landing_pages_test.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/controllers/custom_landing_pages_test.py b/core/controllers/custom_landing_pages_test.py index babf8ed28a11..87e7771dae17 100644 --- a/core/controllers/custom_landing_pages_test.py +++ b/core/controllers/custom_landing_pages_test.py @@ -42,19 +42,23 @@ class StewardsLandingPageTest(test_utils.GenericTestBase): volunteers, or NGOs). """ def test_nonprofits_landing_page(self): - response = self.get_html_response(feconf.CUSTOM_NONPROFITS_LANDING_PAGE_URL) + response = self.get_html_response( + feconf.CUSTOM_NONPROFITS_LANDING_PAGE_URL) response.mustcontain( 'Let\'s work together to make compelling educational') def test_parents_landing_page(self): - response = self.get_html_response(feconf.CUSTOM_PARENTS_LANDING_PAGE_URL) + response = self.get_html_response( + feconf.CUSTOM_PARENTS_LANDING_PAGE_URL) response.mustcontain( 'Help your child learn with our free, engaging lessons') def test_teachers_landing_page(self): - response = self.get_html_response(feconf.CUSTOM_TEACHERS_LANDING_PAGE_URL) + response = self.get_html_response( + feconf.CUSTOM_TEACHERS_LANDING_PAGE_URL) response.mustcontain('Oppia\'s free, personalized lessons are a great') def test_volunteers_landing_page(self): - response = self.get_html_response(feconf.CUSTOM_VOLUNTEERS_LANDING_PAGE_URL) + response = self.get_html_response( + feconf.CUSTOM_VOLUNTEERS_LANDING_PAGE_URL) response.mustcontain('Help improve access to high-quality education') From dddb91c7090f21778dc9ccb2e646b2b1ba76103f Mon Sep 17 00:00:00 2001 From: Rishav Chakraborty Date: Sun, 6 Jan 2019 21:01:43 +0530 Subject: [PATCH 10/11] made params only dict type --- core/controllers/editor_test.py | 5 +- core/controllers/reader_test.py | 6 +- core/controllers/resources_test.py | 5 +- core/tests/test_utils.py | 123 +++++++++++++++++------------ 4 files changed, 78 insertions(+), 61 deletions(-) diff --git a/core/controllers/editor_test.py b/core/controllers/editor_test.py index a01cd3462ed0..1df342bbd802 100644 --- a/core/controllers/editor_test.py +++ b/core/controllers/editor_test.py @@ -613,11 +613,10 @@ def test_exploration_download_handler_for_default_exploration(self): # Check download to zip file. # Download to zip file using download handler. download_url = '/createhandler/download/%s' % exp_id - response = self.get_response(download_url, - expected_content_type='text/plain') + response = self.get_custom_response( + download_url, expected_content_type='text/plain') # Check downloaded zip file. - self.assertEqual(response.headers['Content-Type'], 'text/plain') filename = 'oppia-ThetitleforZIPdownloadhandlertest!-v2.zip' self.assertEqual(response.headers['Content-Disposition'], 'attachment; filename=%s' % str(filename)) diff --git a/core/controllers/reader_test.py b/core/controllers/reader_test.py index 3a2f6b32664b..609056ef2562 100644 --- a/core/controllers/reader_test.py +++ b/core/controllers/reader_test.py @@ -500,10 +500,8 @@ def _get_recommendation_ids( exploration_id, author_recommended_ids_str, collection_id_param, include_recommendations_param)) - response = self.get_html_response('/explore/%s' % exploration_id) - csrf_token = self.get_csrf_token_from_response(response) - summaries = self.get_json( - recommendations_url, params=csrf_token)['summaries'] + self.get_html_response('/explore/%s' % exploration_id) + summaries = self.get_json(recommendations_url)['summaries'] return self._get_exploration_ids_from_summaries(summaries) # TODO(bhenning): Add tests for ensuring system explorations are properly diff --git a/core/controllers/resources_test.py b/core/controllers/resources_test.py index e9adc640da78..9da9ca0c5a32 100644 --- a/core/controllers/resources_test.py +++ b/core/controllers/resources_test.py @@ -66,8 +66,9 @@ def test_image_upload_and_download(self): self.logout() - response = self.get_response(self._get_image_url('0', filename), - expected_content_type='image/png') + response = self.get_custom_response( + self._get_image_url('0', filename), + expected_content_type='image/png') self.assertEqual(response.body, raw_image) def test_non_matching_extensions_are_detected(self): diff --git a/core/tests/test_utils.py b/core/tests/test_utils.py index c10883844e56..e16b4b66469b 100644 --- a/core/tests/test_utils.py +++ b/core/tests/test_utils.py @@ -483,32 +483,30 @@ def get_expected_logout_url(self, slug): """Returns the expected logout URL.""" return current_user_services.create_logout_url(slug) - def get_response( + def _get_response( self, url, expected_content_type, params=None, expected_status_int=200): """Get a response, transformed to a Python object. Args: url: str. The URL to fetch the response. - expected_content_type: str. The content type to expect. - - params: str or dict. A query string, or a dictionary that will be - encoded into a query string. - + params: dict. A dictionary that will be encoded into a query string. expected_status_int: int. The integer status code to expect. Will - be 200 if not specified. + be 200 if not specified. Returns: webtest.TestResponse. The test response. """ - have_errors = False - if expected_status_int >= 400 and ( - expected_status_int < 600): - have_errors = True + if params: + self.assertTrue(isinstance(params, dict)) + + expect_errors = False + if expected_status_int >= 400: + expect_errors = True response = self.testapp.get( - url, params, expect_errors=have_errors, + url, params, expect_errors=expect_errors, status=expected_status_int) # Testapp takes in a status parameter which is the expected status of @@ -519,12 +517,11 @@ def get_response( # https://github.com/Pylons/webtest/blob/ # bf77326420b628c9ea5431432c7e171f88c5d874/webtest/app.py#L1119 . self.assertEqual(response.status_int, expected_status_int) - if not have_errors: + if not expect_errors: self.assertTrue(response.status_int >= 200 and response.status_int < 400) else: - self.assertTrue(response.status_int >= 400 and - response.status_int < 600) + self.assertTrue(response.status_int >= 400) self.assertEqual( response.content_type, expected_content_type) @@ -535,18 +532,40 @@ def get_html_response(self, url, params=None, expected_status_int=200): Args: url: str. The URL to fetch the response. + params: dict. A dictionary that will be encoded into a query string. + expected_status_int: int. The integer status code to expect. Will + be 200 if not specified. + + Returns: + webtest.TestResponse. The test response. + """ + response = self._get_response( + url, 'text/html', params=params, + expected_status_int=expected_status_int) + + return response - params: str or dict. A query string, or a dictionary that will be - encoded into a query string. + def get_custom_response( + self, url, expected_content_type, params=None, + expected_status_int=200): + """Get a response other than HTML or JSON, transformed to a Python + object. + Args: + url: str. The URL to fetch the response. + expected_content_type: str. The content type to expect. + params: dict. A dictionary that will be encoded into a query string. expected_status_int: int. The integer status code to expect. Will - be 200 if not specified. + be 200 if not specified. Returns: webtest.TestResponse. The test response. """ - response = self.get_response( - url, 'text/html', params=params, + self.assertNotIn( + expected_content_type, ['text/html', 'application/json']) + + response = self._get_response( + url, expected_content_type, params=params, expected_status_int=expected_status_int) return response @@ -558,16 +577,16 @@ def get_response_without_checking_for_errors( Args: url: str. The URL to fetch the response. - expected_status_int_list: list(int). A list of integer status - code to expect. - - params: str or dict. A query string, or a dictionary that will be - encoded into a query string. + code to expect. + params: dict. A dictionary that will be encoded into a query string. Returns: webtest.TestResponse. The test response. """ + if params: + self.assertTrue(isinstance(params, dict)) + response = self.testapp.get(url, params, expect_errors=True) self.assertIn(response.status_int, expected_status_int_list) @@ -581,9 +600,7 @@ def _parse_json_response(self, json_response, expect_errors): json_response.status_int >= 200 and json_response.status_int < 400) else: - self.assertTrue( - json_response.status_int >= 400 and - json_response.status_int < 600) + self.assertTrue(json_response.status_int >= 400) self.assertEqual( json_response.content_type, 'application/json') self.assertTrue(json_response.body.startswith(feconf.XSSI_PREFIX)) @@ -592,12 +609,14 @@ def _parse_json_response(self, json_response, expect_errors): def get_json(self, url, params=None, expected_status_int=200): """Get a JSON response, transformed to a Python object.""" - have_errors = False - if expected_status_int >= 400 and ( - expected_status_int < 600): - have_errors = True + if params: + self.assertTrue(isinstance(params, dict)) + + expect_errors = False + if expected_status_int >= 400: + expect_errors = True json_response = self.testapp.get( - url, params, expect_errors=have_errors, + url, params, expect_errors=expect_errors, status=expected_status_int) # Testapp takes in a status parameter which is the expected status of @@ -608,7 +627,7 @@ def get_json(self, url, params=None, expected_status_int=200): # https://github.com/Pylons/webtest/blob/ # bf77326420b628c9ea5431432c7e171f88c5d874/webtest/app.py#L1119 . self.assertEqual(json_response.status_int, expected_status_int) - return self._parse_json_response(json_response, have_errors) + return self._parse_json_response(json_response, expect_errors) def post_json(self, url, payload, csrf_token=None, expected_status_int=200, upload_files=None): @@ -617,13 +636,12 @@ def post_json(self, url, payload, csrf_token=None, if csrf_token: data['csrf_token'] = csrf_token - have_errors = False - if expected_status_int >= 400 and ( - expected_status_int < 600): - have_errors = True + expect_errors = False + if expected_status_int >= 400: + expect_errors = True json_response = self._send_post_request( self.testapp, url, data, - expect_errors=have_errors, + expect_errors=expect_errors, expected_status_int=expected_status_int, upload_files=upload_files) # Testapp takes in a status parameter which is the expected status of @@ -635,16 +653,18 @@ def post_json(self, url, payload, csrf_token=None, # bf77326420b628c9ea5431432c7e171f88c5d874/webtest/app.py#L1119 . self.assertEqual(json_response.status_int, expected_status_int) - return self._parse_json_response(json_response, have_errors) + return self._parse_json_response(json_response, expect_errors) def delete_json(self, url, params='', expected_status_int=200): """Delete object on the server using a JSON call.""" - have_errors = False - if expected_status_int >= 400 and ( - expected_status_int < 600): - have_errors = True + if params: + self.assertTrue(isinstance(params, dict)) + + expect_errors = False + if expected_status_int >= 400: + expect_errors = True json_response = self.testapp.delete( - url, params, expect_errors=have_errors, + url, params, expect_errors=expect_errors, status=expected_status_int) # Testapp takes in a status parameter which is the expected status of @@ -655,7 +675,7 @@ def delete_json(self, url, params='', expected_status_int=200): # https://github.com/Pylons/webtest/blob/ # bf77326420b628c9ea5431432c7e171f88c5d874/webtest/app.py#L1119 . self.assertEqual(json_response.status_int, expected_status_int) - return self._parse_json_response(json_response, have_errors) + return self._parse_json_response(json_response, expect_errors) def _send_post_request( self, app, url, data, expect_errors, @@ -708,12 +728,11 @@ def put_json(self, url, payload, csrf_token=None, expected_status_int=200): if csrf_token: data['csrf_token'] = csrf_token - have_errors = False - if expected_status_int >= 400 and ( - expected_status_int < 600): - have_errors = True + expect_errors = False + if expected_status_int >= 400: + expect_errors = True json_response = self.testapp.put( - str(url), data, expect_errors=have_errors) + str(url), data, expect_errors=expect_errors) # Testapp takes in a status parameter which is the expected status of # the response. However this expected status is verified only when @@ -723,7 +742,7 @@ def put_json(self, url, payload, csrf_token=None, expected_status_int=200): # https://github.com/Pylons/webtest/blob/ # bf77326420b628c9ea5431432c7e171f88c5d874/webtest/app.py#L1119 . self.assertEqual(json_response.status_int, expected_status_int) - return self._parse_json_response(json_response, have_errors) + return self._parse_json_response(json_response, expect_errors) def get_csrf_token_from_response(self, response): """Retrieve the CSRF token from a GET response.""" From 08b12236dc5c01bac5a563aa251fc65ad62c4131 Mon Sep 17 00:00:00 2001 From: Rishav Chakraborty Date: Sun, 6 Jan 2019 21:31:37 +0530 Subject: [PATCH 11/11] Minor changes --- core/controllers/editor_test.py | 3 +-- core/controllers/reader_test.py | 1 - core/controllers/resources_test.py | 3 +-- core/tests/test_utils.py | 6 +++--- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/core/controllers/editor_test.py b/core/controllers/editor_test.py index 1df342bbd802..c2ec554ce809 100644 --- a/core/controllers/editor_test.py +++ b/core/controllers/editor_test.py @@ -613,8 +613,7 @@ def test_exploration_download_handler_for_default_exploration(self): # Check download to zip file. # Download to zip file using download handler. download_url = '/createhandler/download/%s' % exp_id - response = self.get_custom_response( - download_url, expected_content_type='text/plain') + response = self.get_custom_response(download_url, 'text/plain') # Check downloaded zip file. filename = 'oppia-ThetitleforZIPdownloadhandlertest!-v2.zip' diff --git a/core/controllers/reader_test.py b/core/controllers/reader_test.py index 609056ef2562..ebc0902b5d33 100644 --- a/core/controllers/reader_test.py +++ b/core/controllers/reader_test.py @@ -500,7 +500,6 @@ def _get_recommendation_ids( exploration_id, author_recommended_ids_str, collection_id_param, include_recommendations_param)) - self.get_html_response('/explore/%s' % exploration_id) summaries = self.get_json(recommendations_url)['summaries'] return self._get_exploration_ids_from_summaries(summaries) diff --git a/core/controllers/resources_test.py b/core/controllers/resources_test.py index 9da9ca0c5a32..25699fbe3a61 100644 --- a/core/controllers/resources_test.py +++ b/core/controllers/resources_test.py @@ -67,8 +67,7 @@ def test_image_upload_and_download(self): self.logout() response = self.get_custom_response( - self._get_image_url('0', filename), - expected_content_type='image/png') + self._get_image_url('0', filename), 'image/png') self.assertEqual(response.body, raw_image) def test_non_matching_extensions_are_detected(self): diff --git a/core/tests/test_utils.py b/core/tests/test_utils.py index e16b4b66469b..ef11f1e21553 100644 --- a/core/tests/test_utils.py +++ b/core/tests/test_utils.py @@ -498,7 +498,7 @@ def _get_response( Returns: webtest.TestResponse. The test response. """ - if params: + if params is not None: self.assertTrue(isinstance(params, dict)) expect_errors = False @@ -584,7 +584,7 @@ def get_response_without_checking_for_errors( Returns: webtest.TestResponse. The test response. """ - if params: + if params is not None: self.assertTrue(isinstance(params, dict)) response = self.testapp.get(url, params, expect_errors=True) @@ -609,7 +609,7 @@ def _parse_json_response(self, json_response, expect_errors): def get_json(self, url, params=None, expected_status_int=200): """Get a JSON response, transformed to a Python object.""" - if params: + if params is not None: self.assertTrue(isinstance(params, dict)) expect_errors = False