test_admin_api.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import pdb
  2. import pytest
  3. from rdflib import Graph, URIRef
  4. from lakesuperior import env
  5. from lakesuperior.api import resource as rsrc_api
  6. from lakesuperior.api import admin as admin_api
  7. from lakesuperior.dictionaries.namespaces import ns_collection as nsc
  8. @pytest.mark.usefixtures('db')
  9. class TestAdminApi:
  10. """
  11. Test admin operations.
  12. """
  13. def test_check_refint_ok(self):
  14. """
  15. Check that referential integrity is OK.
  16. """
  17. uid1 = '/test_refint1'
  18. uid2 = '/test_refint2'
  19. gr = Graph().parse(
  20. data='<> <http://ex.org/ns#p1> <info:fcres{}> .'.format(uid1),
  21. format='turtle', publicID=nsc['fcres'][uid2])
  22. rsrc_api.create_or_replace(uid1, graph=gr)
  23. assert admin_api.integrity_check() == set()
  24. def test_check_refint_corrupt(self):
  25. """
  26. Corrupt the data store and verify that the missing triple is detected.
  27. """
  28. brk_uid = '/test_refint1'
  29. brk_uri = nsc['fcres'][brk_uid]
  30. store = env.app_globals.rdf_store
  31. with store.txn_ctx(True):
  32. store.remove((URIRef('info:fcres/test_refint1'), None, None))
  33. check_res = admin_api.integrity_check()
  34. assert check_res != set()
  35. assert len(check_res) == 4
  36. check_trp = {trp[0] for trp in check_res}
  37. assert {trp[2] for trp in check_trp} == {brk_uri}
  38. assert (nsc['fcres']['/'], nsc['ldp'].contains, brk_uri) in check_trp
  39. assert (
  40. nsc['fcres']['/test_refint2'],
  41. URIRef('http://ex.org/ns#p1'), brk_uri) in check_trp