test_resource_api.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. import pdb
  2. import pytest
  3. from io import BytesIO
  4. from uuid import uuid4
  5. from rdflib import Graph, Literal, URIRef
  6. from lakesuperior import env
  7. from lakesuperior.api import resource as rsrc_api
  8. from lakesuperior.dictionaries.namespaces import ns_collection as nsc
  9. from lakesuperior.exceptions import (
  10. IncompatibleLdpTypeError, InvalidResourceError, ResourceNotExistsError,
  11. TombstoneError)
  12. from lakesuperior.globals import RES_CREATED, RES_UPDATED
  13. from lakesuperior.model.ldpr import Ldpr
  14. from lakesuperior.store.ldp_rs.lmdb_triplestore import SimpleGraph, Imr
  15. @pytest.fixture(scope='module')
  16. def random_uuid():
  17. return str(uuid.uuid4())
  18. @pytest.fixture
  19. def dc_rdf():
  20. return b'''
  21. PREFIX dcterms: <http://purl.org/dc/terms/>
  22. PREFIX ldp: <http://www.w3.org/ns/ldp#>
  23. <> dcterms:title "Direct Container" ;
  24. ldp:membershipResource <info:fcres/member> ;
  25. ldp:hasMemberRelation dcterms:relation .
  26. '''
  27. @pytest.fixture
  28. def ic_rdf():
  29. return b'''
  30. PREFIX dcterms: <http://purl.org/dc/terms/>
  31. PREFIX ldp: <http://www.w3.org/ns/ldp#>
  32. PREFIX ore: <http://www.openarchives.org/ore/terms/>
  33. <> dcterms:title "Indirect Container" ;
  34. ldp:membershipResource <info:fcres/top_container> ;
  35. ldp:hasMemberRelation dcterms:relation ;
  36. ldp:insertedContentRelation ore:proxyFor .
  37. '''
  38. @pytest.mark.usefixtures('db')
  39. class TestResourceCRUD:
  40. '''
  41. Test interaction with the Resource API.
  42. '''
  43. def test_nodes_exist(self):
  44. """
  45. Verify whether nodes exist or not.
  46. """
  47. assert rsrc_api.exists('/') is True
  48. assert rsrc_api.exists('/{}'.format(uuid4())) is False
  49. def test_get_root_node_metadata(self):
  50. """
  51. Get the root node metadata.
  52. The ``dcterms:title`` property should NOT be included.
  53. """
  54. gr = rsrc_api.get_metadata('/')
  55. assert isinstance(gr, SimpleGraph)
  56. assert len(gr) == 9
  57. assert gr[gr.uri : nsc['rdf'].type : nsc['ldp'].Resource ]
  58. assert not gr[gr.uri : nsc['dcterms'].title : "Repository Root"]
  59. def test_get_root_node(self):
  60. """
  61. Get the root node.
  62. The ``dcterms:title`` property should be included.
  63. """
  64. rsrc = rsrc_api.get('/')
  65. assert isinstance(rsrc, Ldpr)
  66. gr = rsrc.imr
  67. assert len(gr) == 10
  68. assert gr[gr.uri : nsc['rdf'].type : nsc['ldp'].Resource ]
  69. assert gr[
  70. gr.uri : nsc['dcterms'].title : Literal('Repository Root')]
  71. def test_get_nonexisting_node(self):
  72. """
  73. Get a non-existing node.
  74. """
  75. with pytest.raises(ResourceNotExistsError):
  76. gr = rsrc_api.get('/{}'.format(uuid4()))
  77. def test_create_ldp_rs(self):
  78. """
  79. Create an RDF resource (LDP-RS) from a provided graph.
  80. """
  81. uid = '/rsrc_from_graph'
  82. uri = nsc['fcres'][uid]
  83. gr = Graph().parse(
  84. data='<> a <http://ex.org/type#A> .', format='turtle',
  85. publicID=uri)
  86. evt = rsrc_api.create_or_replace(uid, graph=gr)
  87. rsrc = rsrc_api.get(uid)
  88. assert rsrc.imr[
  89. rsrc.uri : nsc['rdf'].type : URIRef('http://ex.org/type#A')]
  90. assert rsrc.imr[
  91. rsrc.uri : nsc['rdf'].type : nsc['ldp'].RDFSource]
  92. def test_create_ldp_nr(self):
  93. """
  94. Create a non-RDF resource (LDP-NR).
  95. """
  96. uid = '/{}'.format(uuid4())
  97. data = b'Hello. This is some dummy content.'
  98. rsrc_api.create_or_replace(
  99. uid, stream=BytesIO(data), mimetype='text/plain')
  100. rsrc = rsrc_api.get(uid)
  101. assert rsrc.content.read() == data
  102. def test_replace_rsrc(self):
  103. uid = '/test_replace'
  104. uri = nsc['fcres'][uid]
  105. gr1 = Graph().parse(
  106. data='<> a <http://ex.org/type#A> .', format='turtle',
  107. publicID=uri)
  108. evt = rsrc_api.create_or_replace(uid, graph=gr1)
  109. assert evt == RES_CREATED
  110. rsrc = rsrc_api.get(uid)
  111. assert rsrc.imr[
  112. rsrc.uri : nsc['rdf'].type : URIRef('http://ex.org/type#A')]
  113. assert rsrc.imr[
  114. rsrc.uri : nsc['rdf'].type : nsc['ldp'].RDFSource]
  115. gr2 = Graph().parse(
  116. data='<> a <http://ex.org/type#B> .', format='turtle',
  117. publicID=uri)
  118. #pdb.set_trace()
  119. evt = rsrc_api.create_or_replace(uid, graph=gr2)
  120. assert evt == RES_UPDATED
  121. rsrc = rsrc_api.get(uid)
  122. assert not rsrc.imr[
  123. rsrc.uri : nsc['rdf'].type : URIRef('http://ex.org/type#A')]
  124. assert rsrc.imr[
  125. rsrc.uri : nsc['rdf'].type : URIRef('http://ex.org/type#B')]
  126. assert rsrc.imr[
  127. rsrc.uri : nsc['rdf'].type : nsc['ldp'].RDFSource]
  128. def test_replace_incompatible_type(self):
  129. """
  130. Verify replacing resources with incompatible type.
  131. Replacing a LDP-NR with a LDP-RS, or vice versa, should fail.
  132. """
  133. uid_rs = '/test_incomp_rs'
  134. uid_nr = '/test_incomp_nr'
  135. data = b'mock binary content'
  136. gr = Graph().parse(
  137. data='<> a <http://ex.org/type#A> .', format='turtle',
  138. publicID=nsc['fcres'][uid_rs])
  139. rsrc_api.create_or_replace(uid_rs, graph=gr)
  140. rsrc_api.create_or_replace(
  141. uid_nr, stream=BytesIO(data), mimetype='text/plain')
  142. with pytest.raises(IncompatibleLdpTypeError):
  143. rsrc_api.create_or_replace(uid_nr, graph=gr)
  144. with pytest.raises(IncompatibleLdpTypeError):
  145. rsrc_api.create_or_replace(
  146. uid_rs, stream=BytesIO(data), mimetype='text/plain')
  147. with pytest.raises(IncompatibleLdpTypeError):
  148. rsrc_api.create_or_replace(uid_nr)
  149. def test_delta_update(self):
  150. """
  151. Update a resource with two sets of add and remove triples.
  152. """
  153. uid = '/test_delta_patch'
  154. uri = nsc['fcres'][uid]
  155. init_trp = {
  156. (URIRef(uri), nsc['rdf'].type, nsc['foaf'].Person),
  157. (URIRef(uri), nsc['foaf'].name, Literal('Joe Bob')),
  158. }
  159. remove_trp = {
  160. (URIRef(uri), nsc['rdf'].type, nsc['foaf'].Person),
  161. }
  162. add_trp = {
  163. (URIRef(uri), nsc['rdf'].type, nsc['foaf'].Organization),
  164. }
  165. gr = Graph()
  166. gr += init_trp
  167. rsrc_api.create_or_replace(uid, graph=gr)
  168. rsrc_api.update_delta(uid, remove_trp, add_trp)
  169. rsrc = rsrc_api.get(uid)
  170. assert rsrc.imr[
  171. rsrc.uri : nsc['rdf'].type : nsc['foaf'].Organization]
  172. assert rsrc.imr[rsrc.uri : nsc['foaf'].name : Literal('Joe Bob')]
  173. assert not rsrc.imr[
  174. rsrc.uri : nsc['rdf'].type : nsc['foaf'].Person]
  175. def test_delta_update_wildcard(self):
  176. """
  177. Update a resource using wildcard modifiers.
  178. """
  179. uid = '/test_delta_patch_wc'
  180. uri = nsc['fcres'][uid]
  181. init_trp = {
  182. (URIRef(uri), nsc['rdf'].type, nsc['foaf'].Person),
  183. (URIRef(uri), nsc['foaf'].name, Literal('Joe Bob')),
  184. (URIRef(uri), nsc['foaf'].name, Literal('Joe Average Bob')),
  185. (URIRef(uri), nsc['foaf'].name, Literal('Joe 12oz Bob')),
  186. }
  187. remove_trp = {
  188. (URIRef(uri), nsc['foaf'].name, None),
  189. }
  190. add_trp = {
  191. (URIRef(uri), nsc['foaf'].name, Literal('Joan Knob')),
  192. }
  193. gr = Graph()
  194. gr += init_trp
  195. rsrc_api.create_or_replace(uid, graph=gr)
  196. rsrc_api.update_delta(uid, remove_trp, add_trp)
  197. rsrc = rsrc_api.get(uid)
  198. assert rsrc.imr[
  199. rsrc.uri : nsc['rdf'].type : nsc['foaf'].Person]
  200. assert rsrc.imr[rsrc.uri : nsc['foaf'].name : Literal('Joan Knob')]
  201. assert not rsrc.imr[rsrc.uri : nsc['foaf'].name : Literal('Joe Bob')]
  202. assert not rsrc.imr[
  203. rsrc.uri : nsc['foaf'].name : Literal('Joe Average Bob')]
  204. assert not rsrc.imr[
  205. rsrc.uri : nsc['foaf'].name : Literal('Joe 12oz Bob')]
  206. def test_sparql_update(self):
  207. """
  208. Update a resource using a SPARQL Update string.
  209. Use a mix of relative and absolute URIs.
  210. """
  211. uid = '/test_sparql'
  212. rdf_data = b'<> <http://purl.org/dc/terms/title> "Original title." .'
  213. update_str = '''DELETE {
  214. <> <http://purl.org/dc/terms/title> "Original title." .
  215. } INSERT {
  216. <> <http://purl.org/dc/terms/title> "Title #2." .
  217. <info:fcres/test_sparql>
  218. <http://purl.org/dc/terms/title> "Title #3." .
  219. <#h1> <http://purl.org/dc/terms/title> "This is a hash." .
  220. } WHERE {
  221. }'''
  222. rsrc_api.create_or_replace(uid, rdf_data=rdf_data, rdf_fmt='turtle')
  223. ver_uid = rsrc_api.create_version(uid, 'v1').split('fcr:versions/')[-1]
  224. rsrc = rsrc_api.update(uid, update_str)
  225. assert (
  226. (rsrc.uri, nsc['dcterms'].title, Literal('Original title.'))
  227. not in set(rsrc.imr))
  228. assert (
  229. (rsrc.uri, nsc['dcterms'].title, Literal('Title #2.'))
  230. in set(rsrc.imr))
  231. assert (
  232. (rsrc.uri, nsc['dcterms'].title, Literal('Title #3.'))
  233. in set(rsrc.imr))
  234. assert ((
  235. URIRef(str(rsrc.uri) + '#h1'),
  236. nsc['dcterms'].title, Literal('This is a hash.'))
  237. in set(rsrc.imr))
  238. def test_create_ldp_dc_post(self, dc_rdf):
  239. """
  240. Create an LDP Direct Container via POST.
  241. """
  242. rsrc_api.create_or_replace('/member')
  243. dc_uid = rsrc_api.create(
  244. '/', 'test_dc_post', rdf_data=dc_rdf, rdf_fmt='turtle')
  245. dc_rsrc = rsrc_api.get(dc_uid)
  246. member_rsrc = rsrc_api.get('/member')
  247. assert nsc['ldp'].Container in dc_rsrc.ldp_types
  248. assert nsc['ldp'].DirectContainer in dc_rsrc.ldp_types
  249. def test_create_ldp_dc_put(self, dc_rdf):
  250. """
  251. Create an LDP Direct Container via PUT.
  252. """
  253. dc_uid = '/test_dc_put01'
  254. rsrc_api.create_or_replace(
  255. dc_uid, rdf_data=dc_rdf, rdf_fmt='turtle')
  256. dc_rsrc = rsrc_api.get(dc_uid)
  257. member_rsrc = rsrc_api.get('/member')
  258. assert nsc['ldp'].Container in dc_rsrc.ldp_types
  259. assert nsc['ldp'].DirectContainer in dc_rsrc.ldp_types
  260. def test_add_dc_member(self, dc_rdf):
  261. """
  262. Add members to a direct container and verify special properties.
  263. """
  264. dc_uid = '/test_dc_put02'
  265. rsrc_api.create_or_replace(
  266. dc_uid, rdf_data=dc_rdf, rdf_fmt='turtle')
  267. dc_rsrc = rsrc_api.get(dc_uid)
  268. child_uid = rsrc_api.create(dc_uid, None)
  269. member_rsrc = rsrc_api.get('/member')
  270. assert member_rsrc.imr[
  271. member_rsrc.uri: nsc['dcterms'].relation: nsc['fcres'][child_uid]]
  272. def test_indirect_container(self, ic_rdf):
  273. """
  274. Create an indirect container verify special properties.
  275. """
  276. cont_uid = '/top_container'
  277. ic_uid = '{}/test_ic'.format(cont_uid)
  278. member_uid = '{}/ic_member'.format(ic_uid)
  279. target_uid = '/ic_target'
  280. ic_member_rdf = b'''
  281. PREFIX ore: <http://www.openarchives.org/ore/terms/>
  282. <> ore:proxyFor <info:fcres/ic_target> .'''
  283. rsrc_api.create_or_replace(cont_uid)
  284. rsrc_api.create_or_replace(target_uid)
  285. rsrc_api.create_or_replace(ic_uid, rdf_data=ic_rdf, rdf_fmt='turtle')
  286. rsrc_api.create_or_replace(
  287. member_uid, rdf_data=ic_member_rdf, rdf_fmt='turtle')
  288. ic_rsrc = rsrc_api.get(ic_uid)
  289. assert nsc['ldp'].Container in ic_rsrc.ldp_types
  290. assert nsc['ldp'].IndirectContainer in ic_rsrc.ldp_types
  291. assert nsc['ldp'].DirectContainer not in ic_rsrc.ldp_types
  292. member_rsrc = rsrc_api.get(member_uid)
  293. top_cont_rsrc = rsrc_api.get(cont_uid)
  294. assert top_cont_rsrc.imr[
  295. top_cont_rsrc.uri: nsc['dcterms'].relation:
  296. nsc['fcres'][target_uid]]
  297. @pytest.mark.usefixtures('db')
  298. class TestAdvancedDelete:
  299. '''
  300. Test resource version lifecycle.
  301. '''
  302. def test_soft_delete(self):
  303. """
  304. Soft-delete (bury) a resource.
  305. """
  306. uid = '/test_soft_delete01'
  307. rsrc_api.create_or_replace(uid)
  308. rsrc_api.delete(uid)
  309. with pytest.raises(TombstoneError):
  310. rsrc_api.get(uid)
  311. def test_resurrect(self):
  312. """
  313. Restore (resurrect) a soft-deleted resource.
  314. """
  315. uid = '/test_soft_delete02'
  316. rsrc_api.create_or_replace(uid)
  317. rsrc_api.delete(uid)
  318. rsrc_api.resurrect(uid)
  319. rsrc = rsrc_api.get(uid)
  320. assert nsc['ldp'].Resource in rsrc.ldp_types
  321. def test_hard_delete(self):
  322. """
  323. Hard-delete (forget) a resource.
  324. """
  325. uid = '/test_hard_delete01'
  326. rsrc_api.create_or_replace(uid)
  327. rsrc_api.delete(uid, False)
  328. with pytest.raises(ResourceNotExistsError):
  329. rsrc_api.get(uid)
  330. with pytest.raises(ResourceNotExistsError):
  331. rsrc_api.resurrect(uid)
  332. def test_delete_children(self):
  333. """
  334. Soft-delete a resource with children.
  335. """
  336. uid = '/test_soft_delete_children01'
  337. rsrc_api.create_or_replace(uid)
  338. for i in range(3):
  339. rsrc_api.create_or_replace('{}/child{}'.format(uid, i))
  340. rsrc_api.delete(uid)
  341. with pytest.raises(TombstoneError):
  342. rsrc_api.get(uid)
  343. for i in range(3):
  344. with pytest.raises(TombstoneError):
  345. rsrc_api.get('{}/child{}'.format(uid, i))
  346. # Cannot resurrect children of a tombstone.
  347. with pytest.raises(TombstoneError):
  348. rsrc_api.resurrect('{}/child{}'.format(uid, i))
  349. def test_resurrect_children(self):
  350. """
  351. Resurrect a resource with its children.
  352. This uses fixtures from the previous test.
  353. """
  354. uid = '/test_soft_delete_children01'
  355. rsrc_api.resurrect(uid)
  356. parent_rsrc = rsrc_api.get(uid)
  357. assert nsc['ldp'].Resource in parent_rsrc.ldp_types
  358. for i in range(3):
  359. child_rsrc = rsrc_api.get('{}/child{}'.format(uid, i))
  360. assert nsc['ldp'].Resource in child_rsrc.ldp_types
  361. def test_hard_delete_children(self):
  362. """
  363. Hard-delete (forget) a resource with its children.
  364. This uses fixtures from the previous test.
  365. """
  366. uid = '/test_hard_delete_children01'
  367. rsrc_api.create_or_replace(uid)
  368. for i in range(3):
  369. rsrc_api.create_or_replace('{}/child{}'.format(uid, i))
  370. rsrc_api.delete(uid, False)
  371. with pytest.raises(ResourceNotExistsError):
  372. rsrc_api.get(uid)
  373. with pytest.raises(ResourceNotExistsError):
  374. rsrc_api.resurrect(uid)
  375. for i in range(3):
  376. with pytest.raises(ResourceNotExistsError):
  377. rsrc_api.get('{}/child{}'.format(uid, i))
  378. with pytest.raises(ResourceNotExistsError):
  379. rsrc_api.resurrect('{}/child{}'.format(uid, i))
  380. def test_hard_delete_descendants(self):
  381. """
  382. Forget a resource with all its descendants.
  383. """
  384. uid = '/test_hard_delete_descendants01'
  385. rsrc_api.create_or_replace(uid)
  386. for i in range(1, 4):
  387. rsrc_api.create_or_replace('{}/child{}'.format(uid, i))
  388. for j in range(i):
  389. rsrc_api.create_or_replace('{}/child{}/grandchild{}'.format(
  390. uid, i, j))
  391. rsrc_api.delete(uid, False)
  392. with pytest.raises(ResourceNotExistsError):
  393. rsrc_api.get(uid)
  394. with pytest.raises(ResourceNotExistsError):
  395. rsrc_api.resurrect(uid)
  396. for i in range(1, 4):
  397. with pytest.raises(ResourceNotExistsError):
  398. rsrc_api.get('{}/child{}'.format(uid, i))
  399. with pytest.raises(ResourceNotExistsError):
  400. rsrc_api.resurrect('{}/child{}'.format(uid, i))
  401. for j in range(i):
  402. with pytest.raises(ResourceNotExistsError):
  403. rsrc_api.get('{}/child{}/grandchild{}'.format(
  404. uid, i, j))
  405. with pytest.raises(ResourceNotExistsError):
  406. rsrc_api.resurrect('{}/child{}/grandchild{}'.format(
  407. uid, i, j))
  408. #@pytest.mark.skip(reason='TODO This function can be reenabled after an '
  409. # 'asynchronus checksum queue is implemented.')
  410. #def test_checksum(self):
  411. # """
  412. # Verify that a checksum is created and updated appropriately.
  413. # """
  414. # root_cksum1 = env.app_globals.md_store.get_checksum(nsc['fcres']['/'])
  415. # uid = '/test_checksum'
  416. # rsrc_api.create_or_replace(uid)
  417. # root_cksum2 = env.app_globals.md_store.get_checksum(nsc['fcres']['/'])
  418. # cksum1 = env.app_globals.md_store.get_checksum(nsc['fcres'][uid])
  419. # assert len(cksum1)
  420. # assert root_cksum1 != root_cksum2
  421. # rsrc_api.update(
  422. # uid,
  423. # 'DELETE {} INSERT {<> a <http://ex.org/ns#Hello> .} WHERE {}')
  424. # cksum2 = env.app_globals.md_store.get_checksum(nsc['fcres'][uid])
  425. # assert cksum1 != cksum2
  426. # rsrc_api.delete(uid)
  427. # cksum3 = env.app_globals.md_store.get_checksum(nsc['fcres'][uid])
  428. # assert cksum3 is None
  429. @pytest.mark.usefixtures('db')
  430. class TestResourceVersioning:
  431. '''
  432. Test resource version lifecycle.
  433. '''
  434. def test_create_version(self):
  435. """
  436. Create a version snapshot.
  437. """
  438. uid = '/test_version1'
  439. rdf_data = b'<> <http://purl.org/dc/terms/title> "Original title." .'
  440. update_str = '''DELETE {
  441. <> <http://purl.org/dc/terms/title> "Original title." .
  442. } INSERT {
  443. <> <http://purl.org/dc/terms/title> "Title #2." .
  444. } WHERE {
  445. }'''
  446. rsrc_api.create_or_replace(uid, rdf_data=rdf_data, rdf_fmt='turtle')
  447. ver_uid = rsrc_api.create_version(uid, 'v1').split('fcr:versions/')[-1]
  448. #FIXME Without this, the test fails.
  449. set(rsrc_api.get_version(uid, ver_uid))
  450. rsrc_api.update(uid, update_str)
  451. current = rsrc_api.get(uid)
  452. assert (
  453. (current.uri, nsc['dcterms'].title, Literal('Title #2.'))
  454. in current.imr)
  455. assert (
  456. (current.uri, nsc['dcterms'].title, Literal('Original title.'))
  457. not in current.imr)
  458. v1 = rsrc_api.get_version(uid, ver_uid)
  459. assert (
  460. (v1.uri, nsc['dcterms'].title, Literal('Original title.'))
  461. in set(v1))
  462. assert (
  463. (v1.uri, nsc['dcterms'].title, Literal('Title #2.'))
  464. not in set(v1))
  465. def test_revert_to_version(self):
  466. """
  467. Test reverting to a previous version.
  468. Uses assets from previous test.
  469. """
  470. uid = '/test_version1'
  471. ver_uid = 'v1'
  472. rsrc_api.revert_to_version(uid, ver_uid)
  473. rev = rsrc_api.get(uid)
  474. assert (
  475. (rev.uri, nsc['dcterms'].title, Literal('Original title.'))
  476. in rev.imr)
  477. def test_versioning_children(self):
  478. """
  479. Test that children are not affected by version restoring.
  480. 1. create parent resource
  481. 2. Create child 1
  482. 3. Version parent
  483. 4. Create child 2
  484. 5. Restore parent to previous version
  485. 6. Verify that restored version still has 2 children
  486. """
  487. uid = '/test_version_children'
  488. ver_uid = 'v1'
  489. ch1_uid = '{}/kid_a'.format(uid)
  490. ch2_uid = '{}/kid_b'.format(uid)
  491. rsrc_api.create_or_replace(uid)
  492. rsrc_api.create_or_replace(ch1_uid)
  493. ver_uid = rsrc_api.create_version(uid, ver_uid).split('fcr:versions/')[-1]
  494. rsrc = rsrc_api.get(uid)
  495. assert nsc['fcres'][ch1_uid] in rsrc.imr[
  496. rsrc.uri : nsc['ldp'].contains]
  497. rsrc_api.create_or_replace(ch2_uid)
  498. rsrc = rsrc_api.get(uid)
  499. assert nsc['fcres'][ch2_uid] in rsrc.imr[
  500. rsrc.uri : nsc['ldp'].contains]
  501. rsrc_api.revert_to_version(uid, ver_uid)
  502. rsrc = rsrc_api.get(uid)
  503. assert nsc['fcres'][ch1_uid] in rsrc.imr[
  504. rsrc.uri : nsc['ldp'].contains]
  505. assert nsc['fcres'][ch2_uid] in rsrc.imr[
  506. rsrc.uri : nsc['ldp'].contains]