Skip to content

Commit

Permalink
Fix File Detail tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Walz authored and Jon Walz committed Jul 15, 2024
1 parent 1eeb452 commit 7c24977
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions api_tests/files/views/test_file_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@

SessionStore = import_module(django_conf_settings.SESSION_ENGINE).SessionStore

from addons.base.views import _get_authenticated_resource
from framework.exceptions import HTTPError

# stolen from^W^Winspired by DRF
# rest_framework.fields.DateTimeField.to_representation
def _dt_to_iso8601(value):
Expand Down Expand Up @@ -705,6 +708,48 @@ def test_load_and_property(self, app, user, file):
expect_errors=True, auth=user.auth,
).status_code == 405

def test_retracted_file_returns_410(self, app, user, file_url, file):
resource = RegistrationFactory(is_public=True)
retraction = resource.retract_registration(
user=resource.creator,
justification='Justification for retraction',
save=True,
moderator_initiated=False
)

retraction.accept()
resource.save()
resource.refresh_from_db()

file.target = resource
file.save()

res = app.get(file_url, auth=user.auth, expect_errors=True)
assert res.status_code == 410

def test_get_authenticated_resource_retracted(self):
resource = RegistrationFactory(is_public=True)

assert resource.is_retracted is False

retraction = resource.retract_registration(
user=resource.creator,
justification='Justification for retraction',
save=True,
moderator_initiated=False
)

retraction.accept()
resource.save()
resource.refresh_from_db()

assert resource.is_retracted is True

with pytest.raises(HTTPError) as excinfo:
_get_authenticated_resource(resource._id)

assert excinfo.value.code == 410


@pytest.mark.django_db
class TestFileTagging:
Expand Down

0 comments on commit 7c24977

Please sign in to comment.