test_2_0_resource_api.py 21 KB

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