Skip to content
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

[Django Upgrade] [ENG-4072] The Rest - Part 2 #10072

Merged
10 changes: 5 additions & 5 deletions admin_tests/preprints/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ def test_get_object(self, req, preprint, plain_view):
def test_no_user_permissions_raises_error(self, user, preprint, plain_view):
request = RequestFactory().get(reverse('preprints:preprint', kwargs={'guid': preprint._id}))
request.user = user
resp = plain_view.as_view()(request, guid=preprint._id)
assert resp._headers['location'][1] == f'/accounts/login/?next=/preprints/{preprint._id}/'
with pytest.raises(PermissionDenied):
plain_view.as_view()(request, guid=preprint._id)
Comment on lines -106 to +107
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When there is no permission or when permission is insufficient, django admin either redirect user to login page ( if the user is not authenticated) or raise the permission error (if authenticated). OSFUser set is_authenticated to True all the time and thus the correct behavior is raising exceptions.


def test_get_flagged_spam(self, superuser, preprint, ham_preprint, spam_preprint, flagged_preprint):
request = RequestFactory().get(reverse('preprints:flagged-spam'))
Expand Down Expand Up @@ -175,16 +175,16 @@ def test_confirm_ham(self, preprint, superuser, mock_akismet):
assert preprint.spam_status == SpamStatus.HAM
assert preprint.is_public

def test_correct_view_permissions(self, user, preprint, plain_view):
def test_valid_but_insufficient_view_permissions(self, user, preprint, plain_view):
view_permission = Permission.objects.get(codename='view_preprint')
user.user_permissions.add(view_permission)
user.save()

request = RequestFactory().get(reverse('preprints:preprint', kwargs={'guid': preprint._id}))
request.user = user

response = plain_view.as_view()(request, guid=preprint._id)
assert response.status_code == 302
with pytest.raises(PermissionDenied):
plain_view.as_view()(request, guid=preprint._id)
Comment on lines -178 to +187
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, also renamed the test name to avoid confusion.


def test_change_preprint_provider(self, user, preprint, plain_view):
change_permission = Permission.objects.get(codename='change_preprint')
Expand Down