-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #4829: Reduce code redundancy in backend testing #5838
Changes from 1 commit
3c32fb5
846a5d8
982d983
ba2eafc
a04ffb5
3b12b1e
014d687
132f541
df8412f
ab08985
1288bd5
acd0c1a
dddb91c
08b1223
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,26 +38,28 @@ def setUp(self): | |
def test_admin_page_rights(self): | ||
"""Test access rights to the admin page.""" | ||
|
||
response = self.testapp.get('/admin') | ||
response = self.get_html('/admin', expect_errors=True, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and below, prefer breaking after '(' if contents of parens span multiple lines. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
expected_status_int=302) | ||
self.assertEqual(response.status_int, 302) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You probably don't need lines like this one, given that it's already checked above. Ditto below and elsewhere (unless checking status_int is the only thing in the test). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
# Login as a non-admin. | ||
self.login(self.EDITOR_EMAIL) | ||
response = self.testapp.get('/admin', expect_errors=True) | ||
response = self.get_html('/admin', expect_errors=True, | ||
expected_status_int=401) | ||
self.assertEqual(response.status_int, 401) | ||
self.logout() | ||
|
||
# Login as an admin. | ||
self.login(self.ADMIN_EMAIL, is_super_admin=True) | ||
response = self.testapp.get('/admin') | ||
response = self.get_html('/admin') | ||
self.assertEqual(response.status_int, 200) | ||
self.logout() | ||
|
||
def test_change_configuration_property(self): | ||
"""Test that configuration properties can be changed.""" | ||
|
||
self.login(self.ADMIN_EMAIL, is_super_admin=True) | ||
response = self.testapp.get('/admin') | ||
response = self.get_html('/admin') | ||
csrf_token = self.get_csrf_token_from_response(response) | ||
|
||
response_dict = self.get_json('/adminhandler') | ||
|
@@ -87,11 +89,11 @@ def test_change_about_page_config_property(self): | |
"""Test that config property values are changed correctly.""" | ||
new_config_value = 'new_config_value' | ||
|
||
response = self.testapp.get('/about') | ||
response = self.get_html('/about') | ||
self.assertNotIn(new_config_value, response.body) | ||
|
||
self.login(self.ADMIN_EMAIL, is_super_admin=True) | ||
response = self.testapp.get('/admin') | ||
response = self.get_html('/admin') | ||
csrf_token = self.get_csrf_token_from_response(response) | ||
self.post_json( | ||
'/adminhandler', { | ||
|
@@ -101,7 +103,7 @@ def test_change_about_page_config_property(self): | |
} | ||
}, csrf_token=csrf_token) | ||
|
||
response = self.testapp.get('/about') | ||
response = self.get_html('/about') | ||
self.assertIn(new_config_value, response.body) | ||
|
||
|
||
|
@@ -111,7 +113,7 @@ class GenerateDummyExplorationsTest(test_utils.GenericTestBase): | |
def test_generate_count_greater_than_publish_count(self): | ||
self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) | ||
self.login(self.ADMIN_EMAIL, is_super_admin=True) | ||
response = self.testapp.get('/admin') | ||
response = self.get_html('/admin') | ||
csrf_token = self.get_csrf_token_from_response(response) | ||
self.post_json( | ||
'/adminhandler', { | ||
|
@@ -127,7 +129,7 @@ def test_generate_count_greater_than_publish_count(self): | |
def test_generate_count_equal_to_publish_count(self): | ||
self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) | ||
self.login(self.ADMIN_EMAIL, is_super_admin=True) | ||
response = self.testapp.get('/admin') | ||
response = self.get_html('/admin') | ||
csrf_token = self.get_csrf_token_from_response(response) | ||
self.post_json( | ||
'/adminhandler', { | ||
|
@@ -143,7 +145,7 @@ def test_generate_count_equal_to_publish_count(self): | |
def test_generate_count_less_than_publish_count(self): | ||
self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) | ||
self.login(self.ADMIN_EMAIL, is_super_admin=True) | ||
response = self.testapp.get('/admin') | ||
response = self.get_html('/admin') | ||
csrf_token = self.get_csrf_token_from_response(response) | ||
generated_exps_response = self.post_json( | ||
'/adminhandler', { | ||
|
@@ -185,7 +187,7 @@ def test_view_and_update_role(self): | |
response_dict, {'user1': feconf.ROLE_ID_EXPLORATION_EDITOR}) | ||
|
||
# Check role correctly gets updated. | ||
response = self.testapp.get(feconf.ADMIN_URL) | ||
response = self.get_html(feconf.ADMIN_URL) | ||
csrf_token = self.get_csrf_token_from_response(response) | ||
response_dict = self.post_json( | ||
feconf.ADMIN_ROLE_HANDLER_URL, | ||
|
@@ -213,7 +215,7 @@ def test_invalid_username_in_view_and_update_role(self): | |
expected_status_int=400, expect_errors=True) | ||
|
||
# Trying to update role of non-existent user. | ||
response = self.testapp.get(feconf.ADMIN_URL) | ||
response = self.get_html(feconf.ADMIN_URL) | ||
csrf_token = self.get_csrf_token_from_response(response) | ||
response = self.post_json( | ||
feconf.ADMIN_ROLE_HANDLER_URL, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and elsewhere, status codes beginning with 2 or 3 should not be considered errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that's the case then should'nt the condition here change to assert both 2xx and 3xx codes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think so. Thanks for catching that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done