Default Action Tests for Read-Only Mode
Review Request #8861 — Created March 31, 2017 and submitted
Read-only mode is a setting an admin can enable to prevent writes to
the database. This can be used when the site is under maintenence or
being upgraded. This commit adds testing for changes to the action
buttons visible in the tabs of a review request.
Run pytests - all pass except some known errors
Description | From | Last Updated |
---|---|---|
Can you move this to the top of the imports, since mock is part of the Python Standard Library? And … |
szhang | |
Do we want to refactor this into a mixin that does common tests for actions that respect read-only mode? |
brennie | |
You didn't make these changes, but shouldn't the docstrings for the tests involving anonymous users says ...with anonymous user instead … |
szhang | |
I noticed in the tests above that they specify that the user is authenticated. Perhaps you could mention that as … |
szhang | |
Closing quote on next line. |
brennie | |
LIkewise. |
brennie | |
I think you should be more specific with the condition for the unit test here. So, you should include a … |
szhang | |
I think you forgot to add periods at the end of your comments with these changes. Same with the other … |
szhang | |
We have test users from the test-users fixture. You can do: self.request.user = User.objects.get(username='doc') This user is not a superuser … |
brennie | |
Same here (mention the permission?). |
szhang | |
See above comment about user fixture. |
brennie | |
This probably does not really matter, but I think in the previous code you put 'perms' before 'request'. Probably should … |
JO joycezhou47 | |
Same here (mention the permission?). |
szhang | |
Same here (mention the permission?). |
szhang | |
Closing quote on next line. |
brennie | |
We are trying to move away from Mock (as it is a rather heavy dependency), although I understand that previous … |
brennie | |
Missing a period. |
brennie | |
Closing quote on next line. |
brennie | |
See my previous comment about the user fixture. |
brennie | |
See my previous comment about the user fixture. You can use the admin user here. |
brennie | |
We have an admin user: admin = User.objects.get(username='admin') review_request = self.create_review_request( create_repository=True, submitter=admin) self.request.user = admin |
brennie | |
Two blank line between imports and first declaration. |
brennie | |
Missing docstring. |
brennie | |
Missing docstring. |
brennie | |
This should indicate in its name that its a mixin of tests, e.g., ReadOnlyActionTestsMixin. Missing docstring. |
brennie | |
When you do: class Foo: @add_fixtures(['..']) def test_foo(self): pass it is actually equivalent to: class Foo: def test_foo(self): pass test_foo … |
brennie | |
Instead of doing this every test, how about... |
brennie | |
Use ~reviewboard.reviews.actions.BaseReviewRequestAction and it will render the link with the text of only "BaseReviewRequestAction". |
brennie | |
we do: try: self.siteconfig.set('site_read_only', True) self.siteconfig.save() #... rest of test finally: self.siteconfig.set('site_read_only', defaults.get('site_read_only')) self.siteconfig.save() This prevents some unnecessary siteconfig saving … |
brennie |
- Diff:
-
Revision 2 (+472 -126)
Checks run (3 succeeded)
-
-
Can you move this to the top of the imports, since
mock
is part of the Python Standard Library?And a blank line in-between that and the django/djblets imports, of course.
-
You didn't make these changes, but shouldn't the docstrings for the tests involving anonymous users says
...with anonymous user
instead of...with authenticated user
?Same below.
-
I noticed in the tests above that they specify that the user is authenticated. Perhaps you could mention that as well?
Same with the test directly below.
-
I think you should be more specific with the condition for the unit test here.
So, you should include a mention about the
can_change_status
permission. Something likeTesting CloseMenuAction.should_render for user with can_change_status permission but in read-only mode
Same with some tests below.
-
I think you forgot to add periods at the end of your comments with these changes.
Same with the other comments in your changes.
-
-
-
-
-
Do we want to refactor this into a mixin that does common tests for actions that respect read-only mode?
-
-
-
We have test users from the
test-users
fixture. You can do:self.request.user = User.objects.get(username='doc')
This user is not a superuser (username
admin
is). -
-
-
We are trying to move away from
Mock
(as it is a rather heavy dependency), although I understand that previous tests in this file are using it.Ideally all of these would be replaced with a fake resolver match class:
class FakeResolverMatch(object): def __init__(self, url_name): self.url_name = url_name
This will ultimately result in fewer lines of code.
-
-
-
-
-
We have an admin user:
admin = User.objects.get(username='admin') review_request = self.create_review_request( create_repository=True, submitter=admin) self.request.user = admin
- Diff:
-
Revision 3 (+253 -154)
Checks run (2 succeeded, 1 failed with error)
-
-
-
-
-
This should indicate in its name that its a mixin of tests, e.g.,
ReadOnlyActionTestsMixin
.Missing docstring.
-
When you do:
class Foo: @add_fixtures(['..']) def test_foo(self): pass
it is actually equivalent to:
class Foo: def test_foo(self): pass test_foo = add_fixtures(['..'])(test_foo)
so you should actually replace the functions on the instance:
self.test_should_render_with_user_in_read_only = _add_fixtures(self.test_should_render_with_user_in_read_only) self.test_should_render_with_superuser_in_read_only = _add_fixtures(self.test_should_render_with_superuser_in_read_only)
-
-
Use
~reviewboard.reviews.actions.BaseReviewRequestAction
and it will render the link with the text of only "BaseReviewRequestAction". -
we do:
try: self.siteconfig.set('site_read_only', True) self.siteconfig.save() #... rest of test finally: self.siteconfig.set('site_read_only', defaults.get('site_read_only')) self.siteconfig.save()
This prevents some unnecessary siteconfig saving when nothing has changed.
Same for the below test.
- Diff:
-
Revision 4 (+284 -154)