test_3_1_admin.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import pytest
  2. from io import BytesIO
  3. from uuid import uuid4
  4. from lakesuperior.api import resource as rsrc_api
  5. @pytest.mark.usefixtures('client_class')
  6. @pytest.mark.usefixtures('db')
  7. class TestAdminApi:
  8. """
  9. Test admin endpoint.
  10. """
  11. def test_fixity_check_ok(self):
  12. """
  13. Verify that fixity check passes for a non-corrupted resource.
  14. """
  15. uid = uuid4()
  16. content = uuid4().bytes
  17. path = f'/ldp/{uid}'
  18. fix_path = f'/admin/{uid}/fixity'
  19. self.client.put(
  20. path, data=content, headers={'content-type': 'text/plain'})
  21. assert self.client.get(fix_path).status_code == 200
  22. def test_fixity_check_corrupt(self):
  23. """
  24. Verify that fixity check fails for a corrupted resource.
  25. """
  26. uid = uuid4()
  27. content = uuid4().bytes
  28. path = f'/ldp/{uid}'
  29. fix_path = f'/admin/{uid}/fixity'
  30. self.client.put(
  31. path, data=content, headers={'content-type': 'text/plain'})
  32. rsrc = rsrc_api.get(f'/{uid}')
  33. with open(rsrc.local_path, 'wb') as fh:
  34. fh.write(uuid4().bytes)
  35. assert self.client.get(fix_path).status_code == 412
  36. def test_fixity_check_missing(self):
  37. """
  38. Verify that fixity check is not performed on a missing resource.
  39. """
  40. uid = uuid4()
  41. content = uuid4().bytes
  42. path = f'/ldp/{uid}'
  43. fix_path = f'/admin/{uid}/fixity'
  44. assert self.client.get(fix_path).status_code == 404
  45. self.client.put(
  46. path, data=content, headers={'content-type': 'text/plain'})
  47. self.client.delete(path)
  48. assert self.client.get(fix_path).status_code == 410