diff --git a/core/controllers/admin_test.py b/core/controllers/admin_test.py
index b3468bd55119..d506e7065272 100644
--- a/core/controllers/admin_test.py
+++ b/core/controllers/admin_test.py
@@ -38,26 +38,23 @@ def setUp(self):
def test_admin_page_rights(self):
"""Test access rights to the admin page."""
- response = self.testapp.get('/admin')
- 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.testapp.get('/admin', expect_errors=True)
- 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.testapp.get('/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.testapp.get('/admin')
+ response = self.get_html_response('/admin')
csrf_token = self.get_csrf_token_from_response(response)
response_dict = self.get_json('/adminhandler')
@@ -87,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.testapp.get('/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.testapp.get('/admin')
+ response = self.get_html_response('/admin')
csrf_token = self.get_csrf_token_from_response(response)
self.post_json(
'/adminhandler', {
@@ -101,7 +98,7 @@ def test_change_about_page_config_property(self):
}
}, csrf_token=csrf_token)
- response = self.testapp.get('/about')
+ response = self.get_html_response('/about')
self.assertIn(new_config_value, response.body)
@@ -111,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.testapp.get('/admin')
+ response = self.get_html_response('/admin')
csrf_token = self.get_csrf_token_from_response(response)
self.post_json(
'/adminhandler', {
@@ -127,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.testapp.get('/admin')
+ response = self.get_html_response('/admin')
csrf_token = self.get_csrf_token_from_response(response)
self.post_json(
'/adminhandler', {
@@ -143,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.testapp.get('/admin')
+ response = self.get_html_response('/admin')
csrf_token = self.get_csrf_token_from_response(response)
generated_exps_response = self.post_json(
'/adminhandler', {
@@ -151,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)
@@ -185,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.testapp.get(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, {})
@@ -210,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.testapp.get(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)
@@ -295,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 4b7102c4cf6d..679c5f04301b 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.testapp.get(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.testapp.get(feconf.LIBRARY_INDEX_URL)
+ response = self.get_html_response(feconf.LIBRARY_INDEX_URL)
self.assertIn('
',
response.body)
@@ -95,9 +95,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)
- 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
@@ -107,25 +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.testapp.get('/library/extra', expect_errors=True)
- self.assertEqual(response.status_int, 404)
+ self.get_html_response(
+ '/library/extra', expected_status_int=404)
- response = self.testapp.get('/library/data/extra', expect_errors=True)
- 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.testapp.get('/')
- 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):
@@ -134,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.testapp.get('/')
- self.assertEqual(response.status_int, 302)
+ response = self.get_html_response('/', expected_status_int=302)
self.assertIn('learner_dashboard', response.headers['location'])
self.logout()
@@ -152,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.testapp.get('/')
- self.assertEqual(response.status_int, 302)
+ response = self.get_html_response('/', expected_status_int=302)
self.assertIn('learner_dashboard', response.headers['location'])
self.logout()
@@ -166,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.testapp.get('/')
+ 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):
@@ -196,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.testapp.get('/')
- self.assertEqual(response.status_int, 302)
+ response = self.get_html_response('/', expected_status_int=302)
self.assertIn('dashboard', response.headers['location'])
self.logout()
@@ -280,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.testapp.get('/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)
@@ -322,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')
@@ -338,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.testapp.get(current_page)
- self.assertEqual(response.status_int, 200)
- response = self.testapp.get(current_user_services.create_logout_url(
- current_page))
+ 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(
@@ -552,7 +543,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 e1ca9148ab95..d5387a717c10 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,28 +189,28 @@ 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_job_id_in_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)
def test_error_on_invalid_classifier_data_in_message(self):
# Altering message dict to result in invalid dict.
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):
@@ -280,13 +280,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, {})
@@ -295,18 +295,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 61fc5608a5a4..c9f59d8c1c08 100644
--- a/core/controllers/collection_editor_test.py
+++ b/core/controllers/collection_editor_test.py
@@ -71,27 +71,24 @@ def test_access_collection_editor_page(self):
# Check that it is possible to access a page with specific version
# number.
- response = self.testapp.get(
+ self.get_json(
'%s/%s?v=1' % (
feconf.COLLECTION_DATA_URL_PREFIX,
self.COLLECTION_ID))
- self.assertEqual(response.status_int, 200)
# Check that non-editors cannot access the editor page. This is due
# to them not being whitelisted.
- response = self.testapp.get(
+ self.get_html_response(
'%s/%s' % (
feconf.COLLECTION_EDITOR_URL_PREFIX,
- self.COLLECTION_ID))
- self.assertEqual(response.status_int, 302)
+ self.COLLECTION_ID), expected_status_int=302)
# Check that whitelisted users can access and edit in the editor page.
self.login(self.EDITOR_EMAIL)
- response = self.testapp.get(
+ 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))
@@ -104,11 +101,10 @@ 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(
+ 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), expected_status_int=401)
# Check that whitelisted users can access the data
# from the editable_collection_data_handler.
@@ -137,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.testapp.get(
+ 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):
@@ -169,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.testapp.get(
+ response = self.get_html_response(
'%s/%s' % (
feconf.COLLECTION_URL_PREFIX,
self.COLLECTION_ID))
@@ -251,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.testapp.get(
+ response = self.get_html_response(
'%s/%s' % (
feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID))
csrf_token = self.get_csrf_token_from_response(response)
@@ -264,7 +259,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_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 9f2f83d1cf0b..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.testapp.get(
+ self.get_html_response(
'%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID),
- expect_errors=True)
- 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.testapp.get(
+ self.get_html_response(
'%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID),
- expect_errors=True)
- self.assertEqual(response.status_int, 404)
+ expected_status_int=404)
self.logout()
def test_unpublished_collections_are_invisible_to_other_editors(self):
@@ -60,44 +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.testapp.get(
+ self.get_html_response(
'%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID),
- expect_errors=True)
- 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.testapp.get(
+ 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.testapp.get(
+ 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.testapp.get(
- '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID),
- expect_errors=True)
- self.assertEqual(response.status_int, 200)
+ self.get_html_response(
+ '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID))
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(
- '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID),
- expect_errors=True)
- self.assertEqual(response.status_int, 200)
+ self.get_html_response(
+ '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID))
class CollectionViewerControllerEndToEndTests(test_utils.GenericTestBase):
diff --git a/core/controllers/concept_card_viewer_test.py b/core/controllers/concept_card_viewer_test.py
index efb7f359219a..aa35594f6796 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_STRUCTURE_PLAYERS', False):
- response = self.testapp.get(
+ self.get_json(
'%s/%s' % (feconf.CONCEPT_CARD_DATA_URL_PREFIX, self.skill_id),
- expect_errors=True)
- self.assertEqual(response.status_int, 404)
+ expected_status_int=404)
diff --git a/core/controllers/creator_dashboard_test.py b/core/controllers/creator_dashboard_test.py
index a7abf0c95ab5..cae2153be5d8 100644
--- a/core/controllers/creator_dashboard_test.py
+++ b/core/controllers/creator_dashboard_test.py
@@ -59,23 +59,22 @@ class HomePageTests(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_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.testapp.get('/notifications_dashboard')
- self.assertEqual(response.status_int, 302)
+ response = self.get_html_response(
+ '/notifications_dashboard', expected_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')
+ 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):
@@ -83,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.testapp.get('/notifications_dashboard')
- self.assertEqual(response.status_int, 200)
+ self.get_html_response('/notifications_dashboard')
self.logout()
@@ -720,8 +718,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)
- 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/custom_landing_pages_test.py b/core/controllers/custom_landing_pages_test.py
index 309685737f1f..87e7771dae17 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,23 @@ 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')
diff --git a/core/controllers/editor_test.py b/core/controllers/editor_test.py
index 18bb67892247..c2ec554ce809 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.testapp.get('/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.testapp.get('/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.testapp.get(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.testapp.get('/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.testapp.get('/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):
@@ -219,8 +215,7 @@ 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'))
@@ -288,7 +283,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_response(
+ invalid_logout_url, expected_status_int=302)
self.assertEqual(response.status_int, 302)
response.follow()
self.assertEqual(response.status_int, 302)
@@ -312,7 +308,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_response(
+ invalid_logout_url, expected_status_int=302)
self.assertEqual(response.status_int, 302)
response.follow()
self.assertEqual(response.status_int, 302)
@@ -336,7 +333,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_response(
+ invalid_logout_url, expected_status_int=302)
self.assertEqual(response.status_int, 302)
response.follow()
self.assertEqual(response.status_int, 302)
@@ -350,7 +348,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_response(
+ empty_redirect_logout_url, expected_status_int=302)
self.assertEqual(response.status_int, 302)
response.follow()
@@ -369,7 +368,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_response(
+ invalid_logout_url, expected_status_int=302)
self.assertEqual(response.status_int, 302)
response.follow()
self.assertEqual(response.status_int, 302)
@@ -389,11 +389,11 @@ 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)
- self.assertEqual(response.status_int, 200)
+ response = self.get_html_response(current_page_url)
- response = self.testapp.get(
- '/exploration_editor_logout?return_url=%s' % current_page_url)
+ response = self.get_html_response(
+ '/exploration_editor_logout?return_url=%s' % current_page_url,
+ expected_status_int=302)
self.assertEqual(response.status_int, 302)
response = response.follow()
self.assertEqual(response.status_int, 302)
@@ -413,13 +413,13 @@ 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)
- 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.testapp.get(
- '/exploration_editor_logout?return_url=%s' % current_page_url)
+ response = self.get_html_response(
+ '/exploration_editor_logout?return_url=%s' % current_page_url,
+ expected_status_int=302)
self.assertEqual(response.status_int, 302)
response = response.follow()
self.assertEqual(response.status_int, 302)
@@ -608,15 +608,14 @@ 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_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_custom_response(download_url, '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))
@@ -671,7 +670,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_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, {
@@ -704,19 +703,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()
@@ -743,25 +742,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()
@@ -794,7 +793,7 @@ def mock_logging_function(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
@@ -820,8 +819,7 @@ def mock_logging_function(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],
@@ -841,8 +839,7 @@ def mock_logging_function(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],
@@ -891,7 +888,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_response(
'%s/%s' % (feconf.EDITOR_URL_PREFIX, self.EXP_ID))
csrf_token = self.get_csrf_token_from_response(response)
@@ -901,8 +898,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):
@@ -973,10 +969,9 @@ def test_versioning_for_default_exploration(self):
self.assertNotIn('Hi, welcome to Oppia!', init_content)
# v3 does not exist.
- response = self.testapp.get(
+ self.get_json(
'%s/%s?v=3' % (feconf.EXPLORATION_INIT_URL_PREFIX, self.EXP_ID),
- expect_errors=True)
- self.assertEqual(response.status_int, 404)
+ expected_status_int=404)
class ExplorationEditRightsTest(BaseEditorControllerTests):
@@ -997,21 +992,16 @@ def test_user_banning(self):
# Joe logs in.
self.login('joe@example.com')
- response = self.testapp.get(feconf.LIBRARY_INDEX_URL)
- self.assertEqual(response.status_int, 200)
- response = self.testapp.get('/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.testapp.get(
- feconf.LIBRARY_INDEX_URL, expect_errors=True)
- self.assertEqual(response.status_int, 200)
- response = self.testapp.get('/create/%s' % exp_id, expect_errors=True)
- 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.
@@ -1019,8 +1009,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)
- self.assertEqual(response.status_int, 200)
+ response = self.get_html_response('/create/%s' % exp_id)
self.assert_can_edit(response.body)
self.logout()
@@ -1060,7 +1049,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_response(
'%s/%s' % (feconf.EDITOR_URL_PREFIX, exp_id))
csrf_token = self.get_csrf_token_from_response(response)
@@ -1095,16 +1084,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.testapp.get('/create/%s' % exp_id, expect_errors=True)
- 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.testapp.get('/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)
@@ -1134,21 +1121,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.testapp.get('/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)
@@ -1177,21 +1162,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.testapp.get('/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)
@@ -1199,14 +1181,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()
@@ -1220,7 +1200,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_response('/create/%s' % exp_id)
csrf_token = self.get_csrf_token_from_response(response)
rights_manager.publish_exploration(self.owner, exp_id)
@@ -1246,8 +1226,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)
- self.assertEqual(response.status_int, 200)
+ response = self.get_html_response('/create/%s' % exp_id)
self.assert_can_edit(response.body)
self.logout()
@@ -1268,7 +1247,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_response(
'%s/%s' % (feconf.EDITOR_URL_PREFIX, exp_id))
csrf_token = self.get_csrf_token_from_response(response)
@@ -1351,8 +1330,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)
- 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
@@ -1361,8 +1339,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'])
@@ -1371,8 +1348,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'])
@@ -1387,7 +1363,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.
@@ -1407,8 +1383,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)
- 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 :('
@@ -1469,8 +1444,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)
- 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 :('
@@ -1485,7 +1459,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()
@@ -1723,7 +1697,7 @@ def setUp(self):
'is_valid': True
}
- response = self.testapp.get('/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):
@@ -1755,7 +1729,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
@@ -1769,7 +1743,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):
@@ -1837,7 +1811,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_response('/create/%s' % self.EXP_ID1)
self.csrf_token = self.get_csrf_token_from_response(response)
def test_exploration_loaded_with_draft_applied(self):
@@ -1904,7 +1878,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 b7abb6118c30..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.testapp.get('/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.testapp.get('/emaildashboard')
+ self.get_html_response('/emaildashboard')
with self.assertRaisesRegexp(Exception, '401 Unauthorized'):
- self.testapp.get('/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.testapp.get('/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.testapp.get('/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.testapp.get('/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.testapp.get('/emaildashboardresult/%s' % 'q123')
+ self.get_html_response('/emaildashboardresult/%s' % 'q123')
csrf_token = self.get_csrf_token_from_response(
- self.testapp.get('/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.testapp.get('/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.testapp.get('/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.testapp.get('/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.testapp.get(
+ 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.testapp.get('/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.testapp.get('/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.testapp.get(
+ 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.testapp.get('/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.testapp.get(
+ 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.testapp.get('/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.testapp.get(
+ 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.testapp.get('/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.testapp.get(
+ 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 c6245315da6b..60b6034256e0 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_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.testapp.get('/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.testapp.get('/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.testapp.get('/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.testapp.get('/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.testapp.get('/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.testapp.get('/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.testapp.get('/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, {
@@ -415,7 +411,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_response(feconf.LIBRARY_INDEX_URL)
csrf_token = self.get_csrf_token_from_response(response)
self.post_json('%s/%s' % (
@@ -442,7 +438,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_response(feconf.LIBRARY_INDEX_URL)
csrf_token = self.get_csrf_token_from_response(response)
# The owner opens the feedback thread.
@@ -472,7 +468,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_response(feconf.LIBRARY_INDEX_URL)
csrf_token = self.get_csrf_token_from_response(response)
# The user opens the feedback thread.
@@ -502,7 +498,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_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 14168bb5400e..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.testapp.get('/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 aa7f35c1fa88..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.testapp.get(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.testapp.get(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 67ba35761db2..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.testapp.get(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.testapp.get(feconf.LIBRARY_TOP_RATED_URL)
- self.assertEqual(response.status_int, 200)
+ self.get_html_response(feconf.LIBRARY_TOP_RATED_URL)
- response = self.testapp.get(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 0ad33d01388d..c17d6b4e5cd0 100644
--- a/core/controllers/moderator_test.py
+++ b/core/controllers/moderator_test.py
@@ -24,30 +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.testapp.get('/moderator')
- 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.testapp.get('/moderator', expect_errors=True)
- 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.testapp.get('/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.testapp.get('/moderator')
- self.assertEqual(response.status_int, 200)
+ self.get_html_response('/moderator')
self.logout()
@@ -72,8 +68,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')
- 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.
@@ -83,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': [{
@@ -94,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 d68a0410617a..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.testapp.get('/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 3a91bec8278c..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.testapp.get(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.testapp.get(feconf.SIGNUP_URL)
- self.assertEqual(response.status_int, 200)
- response = self.testapp.get('/create/0')
- 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.testapp.get(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.testapp.get(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.testapp.get(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.testapp.get(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.testapp.get(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.testapp.get(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.testapp.get(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.testapp.get(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.testapp.get('/preferences')
+ response = self.get_html_response('/preferences')
csrf_token = self.get_csrf_token_from_response(response)
payload = {
@@ -405,10 +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.testapp.get(
- '%s%s' % (self.PROFILE_PIC_URL, self.USERNAME), expect_errors=True
- )
- self.assertEqual(response.status_int, 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)
@@ -426,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.testapp.get('/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(
@@ -454,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.testapp.get('/preferences')
+ response = self.get_html_response('/preferences')
csrf_token = self.get_csrf_token_from_response(response)
self.put_json(
'/preferenceshandler/data',
@@ -468,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.testapp.get('/preferences')
+ response = self.get_html_response('/preferences')
csrf_token = self.get_csrf_token_from_response(response)
self.put_json(
'/preferenceshandler/data',
@@ -628,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.testapp.get('/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', {
@@ -654,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.testapp.get('/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', {
@@ -671,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.testapp.get('/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'])
@@ -706,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 e9c9fa5ecbe2..baf5d08fad46 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_STRUCTURE_EDITORS', 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.testapp.get(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.testapp.get(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_STRUCTURE_EDITORS', True):
self.login(self.NEW_USER_EMAIL)
- response = self.testapp.get(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.testapp.get(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.testapp.get(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_STRUCTURE_EDITORS', 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], ''))
@@ -230,11 +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(
+ self.get_json(
'%s/%s' % (
feconf.QUESTION_EDITOR_DATA_URL_PREFIX, self.question_id),
- expect_errors=True)
- self.assertEqual(response.status_int, 401)
+ expected_status_int=401)
self.logout()
self.login(self.ADMIN_EMAIL)
@@ -312,14 +306,13 @@ 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_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(
@@ -332,28 +325,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.testapp.get(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')
@@ -368,9 +355,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')
@@ -383,7 +368,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_response(feconf.CREATOR_DASHBOARD_URL)
csrf_token = self.get_csrf_token_from_response(response)
payload = {}
new_question_data = self._create_valid_question_data('GHI')
@@ -398,9 +383,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 b59dd4db8764..ebc0902b5d33 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.testapp.get(
+ self.get_html_response(
'%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID),
- expect_errors=True)
- 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.testapp.get(
+ self.get_html_response(
'%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID),
- expect_errors=True)
- self.assertEqual(response.status_int, 404)
+ expected_status_int=404)
self.logout()
def test_unpublished_explorations_are_invisible_to_other_editors(self):
@@ -82,45 +80,38 @@ def test_unpublished_explorations_are_invisible_to_other_editors(self):
other_editor_email, other_exploration)
self.login(other_editor_email)
- response = self.testapp.get(
+ self.get_html_response(
'%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID),
- expect_errors=True)
- 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.testapp.get(
+ 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.testapp.get(
+ 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.testapp.get(
- '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID),
- expect_errors=True)
- self.assertEqual(response.status_int, 200)
+ self.get_html_response(
+ '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID))
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.testapp.get(
- '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID),
- expect_errors=True)
- self.assertEqual(response.status_int, 200)
+ self.get_html_response(
+ '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID))
class FeedbackIntegrationTest(test_utils.GenericTestBase):
@@ -278,17 +269,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.testapp.get(
+ self.get_json(
'%s/%s?story_id=%s' % (
feconf.EXPLORATION_PRETESTS_URL_PREFIX, exp_id_2, story_id),
- expect_errors=True)
- self.assertEqual(response.status_int, 400)
+ expected_status_int=400)
- response = self.testapp.get(
+ self.get_json(
'%s/%s?story_id=%s' % (
feconf.EXPLORATION_PRETESTS_URL_PREFIX, exp_id_2, 'story'),
- expect_errors=True)
- self.assertEqual(response.status_int, 400)
+ expected_status_int=400)
class ExplorationParametersUnitTests(test_utils.GenericTestBase):
@@ -363,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.testapp.get('/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)
@@ -405,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.testapp.get('/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)
@@ -417,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):
@@ -428,7 +417,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_response('/explore/%s' % self.EXP_ID))
self.put_json(
'/explorehandler/rating/%s' % self.EXP_ID, {
'user_rating': 4
@@ -438,7 +427,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_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(
@@ -511,10 +500,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)
- csrf_token = self.get_csrf_token_from_response(response)
- summaries = self.get_json(
- recommendations_url, params=csrf_token)['summaries']
+ 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
@@ -945,7 +931,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_response('/explore/%s' % self.EXP_ID)
csrf_token = self.get_csrf_token_from_response(response)
self.post_json(
@@ -1001,7 +987,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_response('/explore/%s' % self.EXP_ID))
self.logout()
# Create report for exploration.
@@ -1009,7 +995,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):
@@ -1086,7 +1072,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_response(feconf.LIBRARY_INDEX_URL)
csrf_token = self.get_csrf_token_from_response(response)
payload = {
@@ -1124,7 +1110,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_response(feconf.LIBRARY_INDEX_URL)
csrf_token = self.get_csrf_token_from_response(response)
payload = {
@@ -1169,7 +1155,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_response(feconf.LIBRARY_INDEX_URL)
csrf_token = self.get_csrf_token_from_response(response)
payload = {
@@ -1363,7 +1349,7 @@ def setUp(self):
}]
}
- response = self.testapp.get('/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):
@@ -1577,7 +1563,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."""
@@ -1590,7 +1576,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
@@ -1733,7 +1719,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 c71368030a0d..25699fbe3a61 100644
--- a/core/controllers/resources_test.py
+++ b/core/controllers/resources_test.py
@@ -50,7 +50,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_response('/create/0')
csrf_token = self.get_csrf_token_from_response(response)
with open(os.path.join(feconf.TESTS_DATA_DIR, 'img.png'),
@@ -66,13 +66,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_custom_response(
+ self._get_image_url('0', filename), 'image/png')
self.assertEqual(response.body, raw_image)
def test_non_matching_extensions_are_detected(self):
self.login(self.EDITOR_EMAIL)
- response = self.testapp.get('/create/0')
+ response = self.get_html_response('/create/0')
csrf_token = self.get_csrf_token_from_response(response)
filename_without_extension = 'test'
@@ -90,7 +90,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),)
)
@@ -101,20 +100,18 @@ def test_non_matching_extensions_are_detected(self):
self.logout()
# Test that neither form of the image is stored.
- response = self.testapp.get(
+ self.get_json(
self._get_image_url('0', supplied_filename),
- expect_errors=True)
- self.assertEqual(response.status_int, 404)
- response = self.testapp.get(
+ expected_status_int=404)
+ self.get_json(
self._get_image_url('0', filename_with_correct_extension),
- expect_errors=True)
- self.assertEqual(response.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.testapp.get('/create/0')
+ response = self.get_html_response('/create/0')
csrf_token = self.get_csrf_token_from_response(response)
# Upload an empty image.
@@ -122,7 +119,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', ''),)
)
@@ -135,7 +131,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_response('/create/0')
csrf_token = self.get_csrf_token_from_response(response)
# Upload an invalid image.
@@ -143,7 +139,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'),)
)
@@ -155,16 +150,15 @@ def test_upload_bad_image(self):
def test_get_invalid_image(self):
"""Test retrieval of invalid images."""
- response = self.testapp.get(
+ self.get_json(
self._get_image_url('0', 'bad_image'),
- expect_errors=True)
- self.assertEqual(response.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.testapp.get('/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'),
@@ -174,7 +168,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)
@@ -184,7 +178,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_response('/create/0')
csrf_token = self.get_csrf_token_from_response(response)
with open(os.path.join(feconf.TESTS_DATA_DIR, 'img.png'),
@@ -194,7 +188,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)
@@ -205,7 +199,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_response('/create/0')
csrf_token = self.get_csrf_token_from_response(response)
with open(os.path.join(feconf.TESTS_DATA_DIR, 'img.png'),
@@ -215,7 +209,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)
@@ -228,11 +222,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):
@@ -256,7 +249,7 @@ def setUp(self):
def test_audio_upload(self):
self.login(self.EDITOR_EMAIL)
- response = self.testapp.get('/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),
@@ -272,7 +265,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_response('/create/0')
csrf_token = self.get_csrf_token_from_response(response)
with open(os.path.join(
@@ -291,7 +284,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_response('/create/0')
csrf_token = self.get_csrf_token_from_response(response)
filename_without_extension = 'test'
@@ -306,7 +299,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),)
)
@@ -322,7 +314,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_response('/create/0')
csrf_token = self.get_csrf_token_from_response(response)
# Upload empty audio.
@@ -330,7 +322,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', ''),)
)
@@ -342,13 +333,12 @@ 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_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'),)
@@ -362,7 +352,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_response('/create/0')
csrf_token = self.get_csrf_token_from_response(response)
missing_extension_filename = 'test'
@@ -373,7 +363,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),)
)
@@ -389,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_response('/create/0')
csrf_token = self.get_csrf_token_from_response(response)
with open(os.path.join(feconf.TESTS_DATA_DIR,
@@ -400,7 +389,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),)
)
@@ -416,7 +404,7 @@ def test_non_matching_extensions_are_detected(self):
"""
self.login(self.EDITOR_EMAIL)
- response = self.testapp.get('/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
@@ -430,7 +418,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 5d3e80648946..6dca850b28f5 100644
--- a/core/controllers/skill_editor_test.py
+++ b/core/controllers/skill_editor_test.py
@@ -54,7 +54,8 @@ def _get_csrf_token_for_put(self):
csrf_token = None
url_prefix = feconf.SKILL_EDITOR_URL_PREFIX
with self.swap(constants, 'ENABLE_NEW_STRUCTURE_EDITORS', True):
- response = self.testapp.get('%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
@@ -96,29 +97,25 @@ def test_access_skill_editor_page(self):
with self.swap(constants, 'ENABLE_NEW_STRUCTURE_EDITORS', 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)
- 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.testapp.get(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_STRUCTURE_EDITORS', False):
- response = self.testapp.get(self.url, expect_errors=True)
- 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_STRUCTURE_EDITORS', True):
- response = self.testapp.get(self.url, expect_errors=True)
- self.assertEqual(response.status_int, 404)
+ self.get_html_response(self.url, expected_status_int=404)
self.logout()
@@ -150,8 +147,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:
- response = self.testapp.get(self.url, expect_errors=True)
- self.assertEqual(response.status_int, 404)
+ self.get_json(self.url, expected_status_int=404)
self.logout()
@@ -185,13 +181,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_STRUCTURE_EDITORS', False):
- response = self.testapp.get(self.url, expect_errors=True)
- self.assertEqual(response.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_STRUCTURE_EDITORS', True):
- response = self.testapp.get(self.url, expect_errors=True)
- self.assertEqual(response.status_int, 404)
+ self.get_json(self.url, expected_status_int=404)
self.logout()
def test_editable_skill_handler_put_succeeds(self):
@@ -212,20 +206,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_STRUCTURE_EDITORS', 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):
@@ -241,8 +237,7 @@ 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_STRUCTURE_EDITORS', 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(
@@ -250,8 +245,7 @@ def test_editable_skill_handler_delete_fails(self):
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()
@@ -277,16 +271,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.
@@ -295,6 +292,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 dcee4036db3e..09e92264c588 100644
--- a/core/controllers/story_editor_test.py
+++ b/core/controllers/story_editor_test.py
@@ -53,32 +53,29 @@ def test_access_story_editor_page(self):
with self.swap(constants, 'ENABLE_NEW_STRUCTURE_EDITORS', True):
# Check that non-admins cannot access the editor page.
self.login(self.NEW_USER_EMAIL)
- response = self.testapp.get(
+ self.get_html_response(
'%s/%s/%s' % (
feconf.STORY_EDITOR_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()
# Check that admins can access and edit in the editor
# page.
self.login(self.ADMIN_EMAIL)
- response = self.testapp.get(
+ 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):
# Check that non-admins cannot access the editable story data.
with self.swap(constants, 'ENABLE_NEW_STRUCTURE_EDITORS', True):
self.login(self.NEW_USER_EMAIL)
- response = self.testapp.get(
+ self.get_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()
# Check that admins can access the editable story data.
@@ -106,7 +103,7 @@ def test_editable_story_handler_put(self):
}
self.login(self.ADMIN_EMAIL)
with self.swap(constants, 'ENABLE_NEW_STRUCTURE_EDITORS', True):
- response = self.testapp.get(
+ response = self.get_html_response(
'%s/%s/%s' % (
feconf.STORY_EDITOR_URL_PREFIX, self.topic_id,
self.story_id))
@@ -123,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_STRUCTURE_EDITORS', True):
@@ -143,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 aeb0eee50158..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.testapp.get(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.testapp.get(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.testapp.get(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.testapp.get(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.testapp.get(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 7fe7149e0ffc..9a0db5ac580d 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_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.testapp.get('/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.testapp.get('/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.testapp.get('/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.testapp.get('/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.testapp.get('/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.testapp.get('/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.testapp.get('/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.testapp.get('/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.testapp.get('/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.testapp.get('/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.testapp.get(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.testapp.get(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_STRUCTURE_PLAYERS', 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 b0b0532b128f..60c647f9841d 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_STRUCTURE_EDITORS', True):
- response = self.testapp.get(
+ 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(
@@ -117,10 +117,9 @@ def test_get(self):
self.logout()
self.login(self.TOPIC_MANAGER_EMAIL)
- response = self.testapp.get(
+ self.get_json(
'%s/%s?cursor=' % (
feconf.TOPIC_EDITOR_QUESTION_URL, self.topic_id))
- self.assertEqual(response.status_int, 200)
self.logout()
topic_services.assign_role(
@@ -137,11 +136,10 @@ def test_get(self):
self.logout()
self.login(self.NEW_USER_EMAIL)
- response = self.testapp.get(
+ self.get_json(
'%s/%s?cursor=' % (
feconf.TOPIC_EDITOR_QUESTION_URL, self.topic_id
- ), expect_errors=True)
- self.assertEqual(response.status_int, 401)
+ ), expected_status_int=401)
self.logout()
@@ -152,12 +150,10 @@ def test_editable_subtopic_page_get(self):
# editable subtopic data.
with self.swap(constants, 'ENABLE_NEW_STRUCTURE_EDITORS', True):
self.login(self.NEW_USER_EMAIL)
- response = self.testapp.get(
+ self.get_json(
'%s/%s/%s' % (
feconf.SUBTOPIC_PAGE_EDITOR_DATA_URL_PREFIX,
- self.topic_id, 1),
- expect_errors=True)
- self.assertEqual(response.status_int, 401)
+ self.topic_id, 1), expected_status_int=401)
self.logout()
# Check that topic managers not assigned to this topic can
@@ -202,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.testapp.get(
+ self.get_html_response(
'%s/%s' % (
feconf.TOPIC_EDITOR_URL_PREFIX, self.topic_id),
- expect_errors=True)
- 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.testapp.get(
+ 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.testapp.get(
+ self.get_html_response(
'%s/%s' % (feconf.TOPIC_EDITOR_URL_PREFIX, self.topic_id))
- self.assertEqual(response.status_int, 200)
self.logout()
@@ -228,11 +221,10 @@ def test_editable_topic_handler_get(self):
# Check that non-admins cannot access the editable topic data.
with self.swap(constants, 'ENABLE_NEW_STRUCTURE_EDITORS', True):
self.login(self.NEW_USER_EMAIL)
- response = self.testapp.get(
+ self.get_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()
# Check that admins can access the editable topic data.
@@ -281,7 +273,7 @@ def test_editable_topic_handler_put(self):
}
self.login(self.ADMIN_EMAIL)
with self.swap(constants, 'ENABLE_NEW_STRUCTURE_EDITORS', True):
- response = self.testapp.get(
+ response = self.get_html_response(
'%s/%s' % (feconf.TOPIC_EDITOR_URL_PREFIX, self.topic_id))
csrf_token = self.get_csrf_token_from_response(response)
@@ -313,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 = {
@@ -367,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_STRUCTURE_EDITORS', True):
- response = self.testapp.get(
+ 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.
@@ -392,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()
@@ -406,38 +393,33 @@ 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_STRUCTURE_EDITORS', True):
- response = self.testapp.get(
+ 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),
- {}, 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
# 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):
@@ -456,11 +438,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(
+ self.get_json(
'%s/%s' % (
feconf.TOPIC_RIGHTS_URL_PREFIX, self.topic_id),
- expect_errors=True)
- self.assertEqual(response.status_int, 401)
+ expected_status_int=401)
self.logout()
@@ -470,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_STRUCTURE_EDITORS', True):
- response = self.testapp.get(
+ 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)
@@ -491,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 9305b5fe567a..9e87cfa65290 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_STRUCTURE_PLAYERS', True):
- response = self.testapp.get(
+ 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_STRUCTURE_PLAYERS', True):
- response = self.testapp.get(
+ self.get_html_response(
'%s/%s' % (
feconf.TOPIC_VIEWER_URL_PREFIX, 'private_topic_name'),
- 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_STRUCTURE_PLAYERS', False):
- response = self.testapp.get(
+ self.get_html_response(
'%s/%s' % (feconf.TOPIC_VIEWER_URL_PREFIX, 'public_topic_name'),
- expect_errors=True)
- self.assertEqual(response.status_int, 404)
+ expected_status_int=404)
class TopicPageDataHandlerTests(BaseTopicViewerControllerTests):
@@ -100,7 +97,6 @@ def test_get(self):
def test_get_fails_when_new_structures_not_enabled(self):
with self.swap(constants, 'ENABLE_NEW_STRUCTURE_PLAYERS', False):
- response = self.testapp.get(
+ self.get_json(
'%s/%s' % (feconf.TOPIC_DATA_HANDLER, 'public_topic_name'),
- expect_errors=True)
- self.assertEqual(response.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 3f79fbb2c8cc..e1f181f908f4 100644
--- a/core/controllers/topics_and_skills_dashboard_test.py
+++ b/core/controllers/topics_and_skills_dashboard_test.py
@@ -52,7 +52,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_STRUCTURE_EDITORS', True):
- response = self.testapp.get(url_prefix)
+ response = self.get_html_response(url_prefix)
csrf_token = self.get_csrf_token_from_response(response)
return csrf_token
@@ -63,8 +63,7 @@ def test_get_fails_when_new_structures_not_enabled(self):
self.login(self.ADMIN_EMAIL)
with self.swap(constants, 'ENABLE_NEW_STRUCTURE_EDITORS', False):
url = feconf.TOPICS_AND_SKILLS_DASHBOARD_URL
- response = self.testapp.get(url, expect_errors=True)
- self.assertEqual(response.status_int, 404)
+ self.get_html_response(url, expected_status_int=404)
self.logout()
@@ -81,9 +80,9 @@ def test_get(self):
self.save_new_skill(skill_id_2, self.admin_id, 'Description 2')
with self.swap(constants, 'ENABLE_NEW_STRUCTURE_EDITORS', 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)
+ self.get_json(
+ feconf.TOPICS_AND_SKILLS_DASHBOARD_DATA_URL,
+ expected_status_int=401)
self.logout()
# Check that admins can access the topics and skills dashboard data.
@@ -183,8 +182,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()
@@ -213,8 +211,7 @@ def test_skill_creation_fails_when_new_structures_not_enabled(self):
with self.swap(constants, 'ENABLE_NEW_STRUCTURE_EDITORS', 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):
@@ -226,7 +223,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()
@@ -305,6 +302,5 @@ def test_merge_skill_fails_when_new_structures_not_enabled(self):
with self.swap(constants, 'ENABLE_NEW_STRUCTURE_EDITORS', 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 8b7f5a5674ac..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.testapp.get('/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.testapp.get('/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 4b2d526a6abb..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.testapp.get(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.testapp.get('/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.testapp.get('/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.testapp.get('/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.testapp.get('/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 3544e027835e..5fc2ff1ab54a 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.testapp.get('%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.testapp.get(feconf.SIGNUP_URL)
+ response = self.get_html_response(feconf.SIGNUP_URL)
csrf_token = self.get_csrf_token_from_response(response)
self.post_json(
@@ -546,7 +546,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_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.testapp.get(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.
@@ -640,7 +640,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_response(feconf.SIGNUP_URL)
csrf_token = self.get_csrf_token_from_response(response)
# No user-facing error should surface.
@@ -672,7 +672,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_response(feconf.SIGNUP_URL)
csrf_token = self.get_csrf_token_from_response(response)
self.post_json(
@@ -705,7 +705,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_response(feconf.SIGNUP_URL)
csrf_token = self.get_csrf_token_from_response(response)
self.post_json(
@@ -739,7 +739,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_response(feconf.SIGNUP_URL)
csrf_token = self.get_csrf_token_from_response(response)
self.post_json(
@@ -748,9 +748,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)
@@ -783,7 +781,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_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 635bf814adb2..946260952c5c 100644
--- a/core/domain/feedback_services_test.py
+++ b/core/domain/feedback_services_test.py
@@ -946,7 +946,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_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 fe337b83ac80..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.testapp.get('/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 7b8de506535f..306cc6f3bae9 100644
--- a/core/domain/user_services_test.py
+++ b/core/domain/user_services_test.py
@@ -948,7 +948,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_response(feconf.LIBRARY_INDEX_URL)
self.assertIsNotNone(
user_services.get_user_settings(self.viewer_id).last_logged_in)
self.logout()
@@ -989,7 +989,7 @@ def utcnow(cls):
with self.swap(datetime, 'datetime', MockDatetime11Hours):
self.login(self.VIEWER_EMAIL)
- self.testapp.get(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)
@@ -997,7 +997,7 @@ def utcnow(cls):
with self.swap(datetime, 'datetime', MockDatetime13Hours):
self.login(self.VIEWER_EMAIL)
- self.testapp.get(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 14c57e0fbece..ef11f1e21553 100644
--- a/core/tests/test_utils.py
+++ b/core/tests/test_utils.py
@@ -483,21 +483,138 @@ def get_expected_logout_url(self, slug):
"""Returns the expected logout URL."""
return current_user_services.create_logout_url(slug)
- def _parse_json_response(self, json_response, expect_errors=False):
+ 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: 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.
+ """
+ if params is not None:
+ self.assertTrue(isinstance(params, dict))
+
+ expect_errors = False
+ if expected_status_int >= 400:
+ expect_errors = True
+
+ 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(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)
+ self.assertEqual(
+ response.content_type, expected_content_type)
+
+ 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: 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
+
+ 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.
+
+ Returns:
+ webtest.TestResponse. The test response.
+ """
+ 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
+
+ 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: dict. A dictionary that will be encoded into a query string.
+
+ Returns:
+ webtest.TestResponse. The test response.
+ """
+ if params is not None:
+ self.assertTrue(isinstance(params, dict))
+
+ response = self.testapp.get(url, params, expect_errors=True)
+
+ self.assertIn(response.status_int, expected_status_int_list)
+
+ return response
+
+ 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(
- json_response.status_int < 400 and
- json_response.status_int >= 200)
+ json_response.status_int >= 200 and
+ json_response.status_int < 400)
+ else:
+ self.assertTrue(json_response.status_int >= 400)
self.assertEqual(
json_response.content_type, 'application/json')
self.assertTrue(json_response.body.startswith(feconf.XSSI_PREFIX))
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."""
+ if params is not None:
+ 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=expect_errors,
status=expected_status_int)
@@ -510,16 +627,18 @@ 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, expect_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
+ expect_errors = False
+ if expected_status_int >= 400:
+ expect_errors = True
json_response = self._send_post_request(
self.testapp, url, data,
expect_errors=expect_errors,
@@ -532,14 +651,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, expect_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."""
+ 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=expect_errors,
status=expected_status_int)
@@ -552,11 +675,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, expect_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,
@@ -599,13 +722,15 @@ 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
+ expect_errors = False
+ if expected_status_int >= 400:
+ expect_errors = True
json_response = self.testapp.put(
str(url), data, expect_errors=expect_errors)
@@ -617,8 +742,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, expect_errors)
def get_csrf_token_from_response(self, response):
"""Retrieve the CSRF token from a GET response."""
@@ -638,7 +762,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_response(feconf.SIGNUP_URL)
self.assertEqual(response.status_int, 200)
csrf_token = self.get_csrf_token_from_response(response)
response = self.testapp.post(
@@ -659,7 +783,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_response('/admin')
csrf_token = self.get_csrf_token_from_response(response)
self.post_json(
'/adminhandler', {
@@ -682,7 +806,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_response('/admin')
csrf_token = self.get_csrf_token_from_response(response)
self.post_json(
'/adminrolehandler', {