test_3_1_admin.py 1.8 KB

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