def test_post_edit_type_new_id(self): # Check logic applied when type is renamed (t, d1, e1) = self._create_record_type("edittype1", entity_id="typeentity") self.assertTrue(RecordType.exists(self.testcoll, "edittype1")) self.assertFalse(RecordType.exists(self.testcoll, "edittype2")) self.assertTrue(RecordTypeData.exists(self.testcoll, "edittype1")) self.assertFalse(RecordTypeData.exists(self.testcoll, "edittype2")) self.assertTrue(EntityData.exists(d1, "typeentity")) self._check_record_type_values("edittype1") f = recordtype_entity_view_form_data( type_id="edittype2", orig_id="edittype1", action="edit", update="Updated RecordType" ) u = entitydata_edit_url( "edit", "testcoll", layout.TYPE_TYPEID, entity_id="edittype1", view_id="Type_view" ) r = self.client.post(u, f) self.assertEqual(r.status_code, 302) self.assertEqual(r.reason_phrase, "FOUND") self.assertEqual(r.content, "") self.assertEqual(r['location'], self.continuation_url) # Check that new record type exists and old does not self.assertFalse(RecordType.exists(self.testcoll, "edittype1")) self.assertTrue(RecordType.exists(self.testcoll, "edittype2")) self._check_record_type_values("edittype2", update="Updated RecordType") # Check that type data directory has been renamed self.assertFalse(RecordTypeData.exists(self.testcoll, "edittype1")) self.assertTrue(RecordTypeData.exists(self.testcoll, "edittype2")) self.assertFalse(EntityData.exists(d1, "typeentity")) d2 = RecordTypeData.load(self.testcoll, "edittype2") self.assertTrue(EntityData.exists(d2, "typeentity")) return
def test_post_edit_entity_new_type(self): self._create_entity_data("entityedittype") e1 = self._check_entity_data_values("entityedittype") self.assertFalse(RecordType.exists(self.testcoll, "newtype")) newtype = RecordType.create(self.testcoll, "newtype", recordtype_create_values("newtype")) newtypedata = RecordTypeData(self.testcoll, "newtype") self.assertTrue(RecordType.exists(self.testcoll, "newtype")) self.assertFalse(RecordTypeData.exists(self.testcoll, "newtype")) # Now post edit form submission with new type id f = default_view_form_data( entity_id="entityedittype", orig_id="entityedittype", type_id="newtype", orig_type="testtype", action="edit") u = entitydata_edit_url("edit", "testcoll", "testtype", entity_id="entityedittype") r = self.client.post(u, f) # log.info("***********\n"+r.content) self.assertEqual(r.status_code, 302) self.assertEqual(r.reason_phrase, "Found") self.assertEqual(r.content, b"") self.assertEqual(r['location'], entitydata_list_type_url("testcoll", "testtype")) # Check that new record type data now exists, and that new record exists and old does not self.assertTrue(RecordTypeData.exists(self.testcoll, "newtype")) self.assertFalse(EntityData.exists(self.testdata, "entityedittype")) self.assertTrue(EntityData.exists(newtypedata, "entityedittype")) self._check_entity_data_values("entityedittype", type_id="newtype") return
def test_entitydata2_data(self): e = EntityData(self.testdata, "entitydata2") e.set_values(entitydata_create_values("entitydata2")) ed = e.get_values() self.assertEqual(set(ed.keys()), set(entitydata_value_keys())) v = entitydata_values("entitydata2") self.assertEqual(ed, {k:v[k] for k in entitydata_value_keys()}) return
def test_entitydata_type_id(self): r = EntityRoot(TestBaseUri, TestBaseUri, TestBaseDir, TestBaseDir) self.assertEqual(r.get_type_id(), None) e1 = Entity(r, "testid1") self.assertEqual(e1.get_type_id(), None) e2 = EntityData(e1, "testid2") self.assertEqual(e2.get_type_id(), "testid1") return
def test_entitydata1_data(self): e = EntityData(self.testdata, "entitydata1") e.set_values(entitydata_create_values("entitydata1")) ed = e.get_values() self.assertEqual(set(ed.keys()), set(entitydata_value_keys())) v = entitydata_values("entitydata1") self.assertEqual(ed, {k: v[k] for k in entitydata_value_keys()}) return
def test_entitydata_create_load(self): e = EntityData.create(self.testdata, "entitydata1", entitydata_create_values("entitydata1")) self.assertEqual(e._entitydir, entitydata_dir(entity_id="entitydata1")) self.assertTrue(os.path.exists(e._entitydir)) ed = EntityData.load(self.testdata, "entitydata1").get_values() v = entitydata_values("entitydata1") self.assertKeysMatch(ed, v) self.assertDictionaryMatch(ed, v) return
def test_post_copy_entity_cancel(self): self.assertFalse(EntityData.exists(self.testdata, "copytype")) f = default_view_form_data(entity_id="copytype", action="copy", cancel="Cancel") u = entitydata_edit_url("copy", "testcoll", "testtype", entity_id="entity1") r = self.client.post(u, f) self.assertEqual(r.status_code, 302) self.assertEqual(r.reason_phrase, "Found") self.assertEqual(r.content, b"") self.assertEqual(r['location'], entitydata_list_type_url("testcoll", "testtype")) # Check that target record type still does not exist self.assertFalse(EntityData.exists(self.testdata, "copytype")) return
def test_new_entity_new_type(self): # Checks logic for creating an entity which may require creation of new recorddata # Create new type self.assertFalse(RecordType.exists(self.testcoll, "newtype")) f = type_view_form_data(action="new", coll_id="testcoll", type_entity_id="newtype", ) u = entitydata_edit_url("new", "testcoll", type_id="_type", view_id="Type_view") r = self.client.post(u, f) self.assertEqual(r.status_code, 302) self.assertEqual(r.reason_phrase, "Found") self.assertEqual(r.content, b"") self.assertEqual(r['location'], entitydata_list_type_url("testcoll", "_type")) self.assertTrue(RecordType.exists(self.testcoll, "newtype")) # Create new entity self.assertFalse(EntityData.exists(self.testdata, "newentity")) f = default_view_form_data(entity_id="newentity", type_id="newtype", action="new") u = entitydata_edit_url("new", "testcoll", "newtype", view_id="Default_view") r = self.client.post(u, f) self.assertEqual(r.status_code, 302) self.assertEqual(r.reason_phrase, "Found") self.assertEqual(r.content, b"") self.assertEqual(r['location'], entitydata_list_type_url("testcoll", "newtype")) # Check new entity data created self._check_entity_data_values("newentity", type_id="newtype") return
def _create_record_type(self, type_id, entity_id="testentity"): "Helper function creates record type entry with supplied type_id" t = RecordType.create(self.testcoll, type_id, recordtype_create_values(type_id=type_id)) d = RecordTypeData.create(self.testcoll, type_id, {}) e = EntityData.create(d, entity_id, {}) return (t, d, e)
def setUp(self): init_annalist_test_site() self.testsite = Site(TestBaseUri, TestBaseDir) self.testcoll = Collection.create(self.testsite, "testcoll", collection_create_values("testcoll")) self.testtype = RecordType.create( self.testcoll, "testtype", recordtype_create_values("testcoll", "testtype")) self.testtype2 = RecordType.create( self.testcoll, "testtype2", recordtype_create_values("testcoll", "testtype2")) self.testdata = RecordTypeData.create(self.testcoll, "testtype", {}) self.testdata2 = RecordTypeData.create(self.testcoll, "testtype2", {}) e1 = self._create_entity_data("entity1") e2 = self._create_entity_data("entity2") e3 = self._create_entity_data("entity3") e4 = EntityData.create( self.testdata2, "entity4", entitydata_create_values("entity4", type_id="testtype2")) self.type_ids = get_site_types_linked("testcoll") self.type_ids.append( FieldChoice("testtype", label="RecordType testcoll/testtype", link=recordtype_url("testcoll", "testtype"))) self.list_ids = get_site_lists_linked("testcoll") # Login and permissions create_test_user(self.testcoll, "testuser", "testpassword") self.client = Client(HTTP_HOST=TestHost) loggedin = self.client.login(username="******", password="******") self.assertTrue(loggedin) return
def setUp(self): init_annalist_test_site() self.testsite = Site(TestBaseUri, TestBaseDir) self.testcoll = Collection.create(self.testsite, "testcoll", collection_create_values("testcoll")) self.testtype = RecordType.create(self.testcoll, "testtype", recordtype_create_values("testcoll", "testtype")) self.testtype2 = RecordType.create(self.testcoll, "testtype2", recordtype_create_values("testcoll", "testtype2")) self.testdata = RecordTypeData.create(self.testcoll, "testtype", {}) self.testdata2 = RecordTypeData.create(self.testcoll, "testtype2", {}) e1 = self._create_entity_data("entity1") e2 = self._create_entity_data("entity2") e3 = self._create_entity_data("entity3") e4 = EntityData.create(self.testdata2, "entity4", entitydata_create_values("entity4", type_id="testtype2") ) self.type_ids = get_site_types_linked("testcoll") self.type_ids.append(FieldChoice("_type/testtype", label="RecordType testcoll/_type/testtype", link=recordtype_url("testcoll", "testtype") )) self.type_ids.append(FieldChoice("_type/testtype2", label="RecordType testcoll/_type/testtype2", link=recordtype_url("testcoll", "testtype2") )) self.list_ids = get_site_lists_linked("testcoll") # Login and permissions create_test_user(self.testcoll, "testuser", "testpassword") self.client = Client(HTTP_HOST=TestHost) loggedin = self.client.login(username="******", password="******") self.assertTrue(loggedin) return
def _create_testentity(self): testentity = EntityData.create(self.testdata, "testentity", { "annal:type": "test:testtype", "test:repeat_fields": [] }) self.assertTrue(testentity is not None) return testentity
def test_post_new_entity_enum_type_new(self): self.assertFalse(EntityData.exists(self.testdata, "entitynewtype")) f = default_view_form_data(entity_id="entitynewtype", action="new", update="Updated entity", new_enum="entity_type__new_edit") u = entitydata_edit_url("new", "testcoll", "testtype", view_id="Default_view") r = self.client.post(u, f) self.assertEqual(r.status_code, 302) self.assertEqual(r.reason_phrase, "FOUND") self.assertEqual(r.content, "") # v = entitydata_edit_url("new", "testcoll", "_type", view_id="Type_view") v = entitydata_edit_url("edit", "testcoll", "_type", "testtype", view_id="Type_view") w = entitydata_edit_url("edit", "testcoll", "testtype", entity_id="entitynewtype", view_id="Default_view") c = continuation_url_param(w) self.assertIn(TestHostUri + v, r['location']) self.assertIn(c, r['location']) self._check_entity_data_values("entitynewtype", update="Updated entity") return
def _create_testentity(self): testentity = EntityData.create(self.testdata, "testentity", { "annal:type": "test:testtype" , "test:repeat_fields": [] }) self.assertTrue(testentity is not None) return testentity
def init_annalist_named_test_coll(base_coll_id=None, coll_id="testcoll", type_id="testtype"): """ Similar to init_annalist_test_coll, but collection also installs and inherits from named collection definitions. """ # @@TODO: DRY: use create_test_coll_inheriting # @@TODO: rename: install_create_test_coll_inheriting log.debug("init_annalist_named_test_coll") testsite = Site(TestBaseUri, TestBaseDir) namedcoll = install_annalist_named_coll(base_coll_id) testcoll = Collection.create(testsite, coll_id, collection_create_values(coll_id)) testcoll.set_alt_entities(namedcoll) testcoll._save() testtype = RecordType.create(testcoll, type_id, recordtype_create_values(coll_id, type_id)) testdata = RecordTypeData.create(testcoll, type_id, {}) teste = EntityData.create( testdata, "entity1", entitydata_create_values(testcoll, testtype, "entity1")) testcoll.generate_coll_jsonld_context() return testcoll
def coll123_create_data(site): coll1 = Collection.create(site, "coll1", collection_create_values("coll1")) coll2 = Collection.create(site, "coll2", collection_create_values("coll2")) coll3 = Collection.create(site, "coll3", collection_create_values("coll3")) # for coll in [coll1, coll2, coll3]: type1 = RecordType.create( coll, "type1", recordtype_create_values(coll._entityid, "type1")) view1 = RecordView.create( coll, "view1", recordview_create_values(coll._entityid, "view1")) list1 = RecordList.create( coll, "list1", recordlist_create_values(coll._entityid, "list1")) data1 = RecordTypeData.create(coll, "type1", {}) type2 = RecordType.create( coll, "type2", recordtype_create_values(coll._entityid, "type2")) view2 = RecordView.create( coll, "view2", recordview_create_values(coll._entityid, "view2")) list2 = RecordList.create( coll, "list2", recordlist_create_values(coll._entityid, "list2")) data2 = RecordTypeData.create(coll, "type2", {}) # for t, d in [(type1, data1), (type2, data2)]: for eid in ["entity1", "entity2", "entity3"]: e = EntityData.create(d, eid, entitydata_create_values(coll, t, eid)) return
def create_test_coll_inheriting(base_coll_id=None, coll_id="testcoll", type_id="testtype"): """ Similar to init_annalist_test_coll, but collection also inherits from named collection. """ testsite = Site(TestBaseUri, TestBaseDir) basecoll = Collection.load(testsite, base_coll_id) if not basecoll: msg = "Base collection %s not found" % base_coll_id log.warning(msg) assert False, msg testcoll = Collection.create(testsite, coll_id, collection_create_values(coll_id)) testcoll.set_alt_entities(basecoll) testcoll._save() testtype = RecordType.create(testcoll, type_id, recordtype_create_values(coll_id, type_id)) testdata = RecordTypeData.create(testcoll, type_id, {}) teste = EntityData.create( testdata, "entity1", entitydata_create_values(testcoll, testtype, "entity1")) testcoll.generate_coll_jsonld_context() return testcoll
def test_post_new_entity_cancel(self): self.assertFalse(EntityData.exists(self.testdata, "newentity")) f = entitydata_form_data(entity_id="newentity", action="new", cancel="Cancel") u = entitydata_edit_url("new", "testcoll", "testtype") r = self.client.post(u, f) self.assertEqual(r.status_code, 302) self.assertEqual(r.reason_phrase, "FOUND") self.assertEqual(r.content, "") self.assertEqual( r['location'], TestHostUri + entitydata_list_type_url("testcoll", "testtype")) # Check that new record type still does not exist self.assertFalse(EntityData.exists(self.testdata, "newentity")) return
def test_post_default_form_use_view(self): self._create_entity_data("entityuseview") self.assertTrue(EntityData.exists(self.testdata, "entityuseview")) f = entitydata_default_view_form_data( entity_id="entityuseview", action="view", use_view="_view/Type_view", ) f.pop('entity_id', None) u = entitydata_edit_url("view", "testcoll", "testtype", "entityuseview", view_id="Default_view") r = self.client.post(u, f) self.assertEqual(r.status_code, 302) self.assertEqual(r.reason_phrase, "FOUND") self.assertEqual(r.content, "") v = TestHostUri + entitydata_edit_url("view", "testcoll", "testtype", entity_id="entityuseview", view_id="Type_view") c = continuation_url_param("/testsite/c/testcoll/d/testtype/") self.assertIn(v, r['location']) self.assertIn(c, r['location']) self._check_entity_data_values("entityuseview") return
def _create_ref_entity(self): ref_entity = EntityData.create(self.ref_data, "Test_ref_entity", { "annal:type": "test:ref_type" , "rdfs:label": "Label Test_ref_entity" , "rdfs:comment": "Description of reference image record" , "test:ref_image": "Test_img_entity" }) self.assertTrue(ref_entity is not None) return ref_entity
def _check_entity_data_values(self, entity_id, type_id="testtype", type_uri=None, update="Entity", parent=None, update_dict=None): "Helper function checks content of form-updated record type entry with supplied entity_id" recorddata = RecordTypeData.load(self.testcoll, type_id) self.assertTrue(EntityData.exists(recorddata, entity_id)) e = EntityData.load(recorddata, entity_id) self.assertEqual(e.get_id(), entity_id) self.assertEqual(e.get_url(""), TestHostUri + entity_url("testcoll", type_id, entity_id)) v = entitydata_values(entity_id, type_id=type_id, type_uri=type_uri, update=update) if update_dict: v.update(update_dict) for k in update_dict: if update_dict[k] is None: v.pop(k, None) self.assertDictionaryMatch(e.get_values(), v) return e
def test_post_copy_inherited_entity_no_access(self): loggedin = self.client.login(username="******", password="******") self.assertTrue(loggedin) self.assertFalse(EntityData.exists(self.testsubdata, "entity2")) f = default_view_form_data(action="copy", entity_id="entity2", type_id="testtype", coll_id="testsubcoll", orig_coll="testcoll" ) u = entitydata_edit_url(action="copy", coll_id="testsubcoll", type_id="testtype", entity_id="entity2", view_id="Default_view" ) r = self.client.post(u, f) self.assertEqual(r.status_code, 403) self.assertEqual(r.reason_phrase, "Forbidden") # Check that no new data exists self.assertFalse(EntityData.exists(self.testsubdata, "entity2")) return
def test_post_confirmed_remove_entity(self): t = EntityData.create(self.testdata, "deleteentity", entitydata_create_values("deleteentity")) self.assertTrue(EntityData.exists(self.testdata, "deleteentity")) # Submit positive confirmation u = entitydata_delete_confirm_url("testcoll", "testtype") f = entitydata_delete_confirm_form_data("deleteentity") r = self.client.post(u, f) self.assertEqual(r.status_code, 302) self.assertEqual(r.reason_phrase, "Found") self.assertEqual(r.content, b"") v = entitydata_list_all_url("testcoll") self.assertIn(v, r['location']) self.assertIn("info_head=", r['location']) self.assertIn("info_message=", r['location']) self.assertNotIn("search=testcoll", r['location']) # Confirm deletion self.assertFalse(EntityData.exists(self.testcoll, "deleteentity")) return
def entities(self): """ Generator enumerates and returns records of given type """ for f in self._children(EntityData): log.debug("RecordTypeData.entities: f %s"%f) e = EntityData.load(self, f) if e: yield e return
def create_data(self, entity_id): # Create placeholder for testing typedata = RecordTypeData.create(self.testcoll, "Default_type", {}) assert typedata is not None e = EntityData.create( typedata, entity_id, entitydata_create_values(entity_id, coll_id="testcoll", type_id="Default_type")) return e
def create_subproperty_field_view_entity(self): # Create test field using superproperty self.test_sup_field = RecordField.create(self.testcoll, "Test_sup_field", { ANNAL.CURIE.type: "annal:Field" , RDFS.CURIE.label: "Field using superproperty URI" , RDFS.CURIE.comment: "Field using superproperty URI" , ANNAL.CURIE.field_render_type: "_enum_render_type/Text" , ANNAL.CURIE.field_value_mode: "_enum_value_mode/Value_direct" , ANNAL.CURIE.field_entity_type: "test:testtype" , ANNAL.CURIE.placeholder: "(Test_sup_field)" , ANNAL.CURIE.property_uri: "test:superprop_uri" , ANNAL.CURIE.field_placement: "small:0,12;medium:0,6" }) self.assertTrue(self.test_sup_field is not None) # Create test field using subproperty and declaring superproperty self.test_sub_field = RecordField.create(self.testcoll, "Test_sub_field", { ANNAL.CURIE.type: "annal:Field" , RDFS.CURIE.label: "Field using superproperty URI" , RDFS.CURIE.comment: "Field using superproperty URI" , ANNAL.CURIE.field_render_type: "_enum_render_type/Text" , ANNAL.CURIE.field_value_mode: "_enum_value_mode/Value_direct" , ANNAL.CURIE.field_entity_type: "test:testtype" , ANNAL.CURIE.placeholder: "(Test_sub_field)" , ANNAL.CURIE.property_uri: "test:subprop_uri" , ANNAL.CURIE.superproperty_uri: [{"@id": "test:superprop_uri"}] , ANNAL.CURIE.field_placement: "small:0,12;medium:0,6" }) self.assertTrue(self.test_sub_field is not None) # Create test view using superproperty self.test_view = RecordView.create(self.testcoll, "testview", { ANNAL.CURIE.type: "annal:View" , ANNAL.CURIE.uri: "test:view" , RDFS.CURIE.label: "Test view label" , RDFS.CURIE.comment: "Test view comment" , ANNAL.CURIE.view_entity_type: "test:testtype" , ANNAL.CURIE.view_fields: [ { ANNAL.CURIE.field_id: layout.FIELD_TYPEID+"/Entity_id" , ANNAL.CURIE.field_placement: "small:0,12;medium:0,6" } , { ANNAL.CURIE.field_id: layout.FIELD_TYPEID+"/Test_sup_field" , ANNAL.CURIE.field_placement: "small:0,12;medium:0,6" } ] }) self.assertTrue(self.test_view is not None) # Create test entity using subproperty self.testentity_data = EntityData.create(self.testdata, "testentity", entitydata_create_values( "testentity", type_id="testtype", type_uri="test:testtype", extra_fields={"test:subprop_uri": "Test field value"} ) ) self.assertTrue(self.testentity_data is not None) return
def test_entitydata_init(self): e = EntityData(self.testdata, "testentity") id_dict = {'type_id': "testtype", 'id': "testentity"} self.assertEqual(e._entitytype, ANNAL.CURIE.EntityData) self.assertEqual(e._entityfile, layout.ENTITY_DATA_FILE) self.assertEqual(e._entityref, layout.COLL_BASE_ENTITY_REF%id_dict) self.assertEqual(e._entityid, "testentity") self.assertEqual(e._entityurl, TestHostUri + entity_url("testcoll", "testtype", "testentity")) self.assertEqual(e._entitydir, entitydata_dir("testcoll", "testtype", "testentity")) self.assertEqual(e._values, None) return
def _create_entity_data(self, entity_id, type_id="testtype", update="Entity", comment2="Comment field 2", comment3="Comment field 3" ): "Helper function creates entity data with supplied entity_id" v = entitydata_create_values(entity_id, type_id=type_id, update=update) v = entitydata_values_add_field(v, "rdfs:comment", 2, comment2) v = entitydata_values_add_field(v, "rdfs:comment_alt", 3, comment3) e = EntityData.create(self.testdata, entity_id, v) return e
def test_post_copy_inherited_entity(self): loggedin = self.client.login(username="******", password="******") self.assertTrue(loggedin) self.assertFalse(EntityData.exists(self.testsubdata, "entity2")) f = default_view_form_data(action="copy", entity_id="entity2", type_id="testtype", coll_id="testsubcoll", orig_coll="testcoll" ) u = entitydata_edit_url(action="copy", coll_id="testsubcoll", type_id="testtype", entity_id="entity2", view_id="Default_view" ) r = self.client.post(u, f) self.assertEqual(r.status_code, 302) self.assertEqual(r.reason_phrase, "FOUND") self.assertEqual(r.content, "") self.assertIn(self.continuation_url, r['location']) # Check that new data exists self.assertTrue(EntityData.exists(self.testsubdata, "entity2")) return
def test_post_new_entity(self): self.assertFalse(EntityData.exists(self.testdata, "newentity")) f = default_view_form_data(entity_id="newentity", action="new") u = entitydata_edit_url("new", "testcoll", "testtype", view_id="Default_view") r = self.client.post(u, f) self.assertEqual(r.status_code, 302) self.assertEqual(r.reason_phrase, "Found") self.assertEqual(r.content, b"") self.assertEqual(r['location'], entitydata_list_type_url("testcoll", "testtype")) # Check new entity data created self._check_entity_data_values("newentity") return
def test_post_confirmed_remove_entity_from_search(self): t = EntityData.create(self.testdata, "deleteentity", entitydata_create_values("deleteentity")) self.assertTrue(EntityData.exists(self.testdata, "deleteentity")) # Submit positive confirmation u = entitydata_delete_confirm_url("testcoll", "testtype") f = entitydata_delete_confirm_form_data("deleteentity", search="testcoll") r = self.client.post(u, f) self.assertEqual(r.status_code, 302) self.assertEqual(r.reason_phrase, "FOUND") self.assertEqual(r.content, "") self.assertMatch(r['location'], "^"+TestHostUri+ entitydata_list_all_url("testcoll") ) self.assertMatch(r['location'], r"info_head=.*&info_message=.*deleteentity.*testcoll.*$" ) self.assertIn("search=testcoll", r['location']) # Confirm deletion self.assertFalse(EntityData.exists(self.testcoll, "deleteentity")) return
def _check_entity_data_values(self, entity_id, type_id="testtype", update="Entity", parent=None, update_dict=None): "Helper function checks content of form-updated record type entry with supplied entity_id" recorddata = RecordTypeData.load(self.testcoll, type_id) self.assertTrue(EntityData.exists(recorddata, entity_id)) e = EntityData.load(recorddata, entity_id) self.assertEqual(e.get_id(), entity_id) self.assertEqual( e.get_url(""), TestHostUri + entity_url("testcoll", type_id, entity_id)) v = entitydata_values(entity_id, type_id=type_id, update=update) if update_dict: v.update(update_dict) for k in update_dict: if update_dict[k] is None: v.pop(k, None) self.assertDictionaryMatch(e.get_values(), v) return e
def test_post_new_entity(self): self.assertFalse(EntityData.exists(self.testdata, "newentity")) f = entitydata_form_data(entity_id="newentity", action="new") u = entitydata_edit_url("new", "testcoll", "testtype") r = self.client.post(u, f) self.assertEqual(r.status_code, 302) self.assertEqual(r.reason_phrase, "FOUND") self.assertEqual(r.content, "") self.assertEqual( r['location'], TestHostUri + entitydata_list_type_url("testcoll", "testtype")) # Check new entity data created self._check_entity_data_values("newentity") return
def test_get_view_inherited_entity(self): loggedin = self.client.login(username="******", password="******") self.assertTrue(loggedin) self.assertFalse(EntityData.exists(self.testsubdata, "entity2")) u = entitydata_edit_url( "edit", "testsubcoll", "testtype", entity_id="entity2", view_id="Default_view" ) r = self.client.get(u) self.assertEqual(r.status_code, 200) self.assertEqual(r.reason_phrase, "OK") # self.assertEqual(r.content, "") return
def test_post_edit_type_new_id(self): # Check logic applied when type is renamed (t, d1, e1) = self._create_record_type("edittype1", entity_id="typeentity") self.assertTrue(RecordType.exists(self.testcoll, "edittype1")) self.assertFalse(RecordType.exists(self.testcoll, "edittype2")) self.assertTrue(RecordTypeData.exists(self.testcoll, "edittype1")) self.assertFalse(RecordTypeData.exists(self.testcoll, "edittype2")) self.assertTrue(EntityData.exists(d1, "typeentity")) self._check_record_type_values("edittype1") f = recordtype_entity_view_form_data(type_id="edittype2", orig_id="edittype1", action="edit", update="Updated RecordType") u = entitydata_edit_url("edit", "testcoll", "_type", entity_id="edittype1", view_id="Type_view") r = self.client.post(u, f) self.assertEqual(r.status_code, 302) self.assertEqual(r.reason_phrase, "FOUND") self.assertEqual(r.content, "") self.assertEqual(r['location'], self.continuation_url) # Check that new record type exists and old does not self.assertFalse(RecordType.exists(self.testcoll, "edittype1")) self.assertTrue(RecordType.exists(self.testcoll, "edittype2")) self._check_record_type_values("edittype2", update="Updated RecordType") # Check that type data directory has been renamed self.assertFalse(RecordTypeData.exists(self.testcoll, "edittype1")) self.assertTrue(RecordTypeData.exists(self.testcoll, "edittype2")) self.assertFalse(EntityData.exists(d1, "typeentity")) d2 = RecordTypeData.load(self.testcoll, "edittype2") self.assertTrue(EntityData.exists(d2, "typeentity")) return
def test_post_edit_entity_new_id(self): self._create_entity_data("entityeditid1") e1 = self._check_entity_data_values("entityeditid1") # Now post edit form submission with different values and new id f = default_view_form_data(entity_id="entityeditid2", orig_id="entityeditid1", action="edit") u = entitydata_edit_url("edit", "testcoll", "testtype", entity_id="entityeditid1") r = self.client.post(u, f) self.assertEqual(r.status_code, 302) self.assertEqual(r.reason_phrase, "Found") self.assertEqual(r.content, b"") self.assertEqual(r['location'], entitydata_list_type_url("testcoll", "testtype")) # Check that new record type exists and old does not self.assertFalse(EntityData.exists(self.testdata, "entityeditid1")) self._check_entity_data_values("entityeditid2") return
def test_post_confirmed_remove_entity_from_search(self): t = EntityData.create(self.testdata, "deleteentity", entitydata_create_values("deleteentity")) self.assertTrue(EntityData.exists(self.testdata, "deleteentity")) # Submit positive confirmation u = entitydata_delete_confirm_url("testcoll", "testtype") f = entitydata_delete_confirm_form_data("deleteentity", search="testcoll") r = self.client.post(u, f) self.assertEqual(r.status_code, 302) self.assertEqual(r.reason_phrase, "FOUND") self.assertEqual(r.content, "") self.assertMatch(r['location'], "^"+TestHostUri+ entitydata_list_all_url("testcoll") ) self.assertMatch(r['location'], r"info_head=.*$" ) self.assertMatch(r['location'], r"info_message=.*deleteentity.*testcoll.*$" ) self.assertIn("search=testcoll", r['location']) # Confirm deletion self.assertFalse(EntityData.exists(self.testcoll, "deleteentity")) return
def test_post_copy_entity(self): self.assertFalse(EntityData.exists(self.testdata, "copytype")) f = default_view_form_data(entity_id="copytype", action="copy") u = entitydata_edit_url("copy", "testcoll", "testtype", entity_id="entity1") r = self.client.post(u, f) self.assertEqual(r.status_code, 302) self.assertEqual(r.reason_phrase, "FOUND") self.assertEqual(r.content, "") self.assertEqual( r['location'], TestHostUri + entitydata_list_type_url("testcoll", "testtype")) # Check that new record type exists self._check_entity_data_values("copytype") return
def setUp(self): self.testsite = init_annalist_test_site() self.testcoll = init_annalist_named_test_coll(layout.BIBDATA_ID) # Create BibEntry record (BibEntry_type defines field alias) self.testdata = RecordTypeData.create(self.testcoll, "BibEntry_type", {}) self.bibentity1_data = ({ "@type": ["bib:BibEntry", ANNAL.CURIE.EntityData], ANNAL.CURIE.type: "bib:BibEntry", ANNAL.CURIE.type_id: "BibEntry_type", "bib:type": "article", "bib:title": "bib:title for bibentity1", "bib:note": "Sample bibliographic entry with field aliasing", "bib:month": "09", "bib:year": "2014", "bib:author": [{ "bib:id": "author_id", "bib:name": "Author, J. H.", "bib:alternate": "Joe H. Author", "bib:firstname": "Joe", "bib:lastname": "Author" }], "bib:identifier": [], "bib:journal": [], "bib:editor": [], "bib:publication_details": [], "bib:license": [], "bib:bookentry": [] }) self.testbib1 = EntityData.create(self.testdata, "bibentity1", self.bibentity1_data) # Login and permissions create_test_user(self.testcoll, "testuser", "testpassword") self.client = Client(HTTP_HOST=TestHost) loggedin = self.client.login(username="******", password="******") self.assertTrue(loggedin) return
def test_new_entity_default_type(self): # Checks logic related to creating a new recorddata entity in collection # for type defined in site data self.assertFalse(EntityData.exists(self.testdata, "newentity")) f = default_view_form_data(entity_id="newentity", type_id="Default_type", action="new") u = entitydata_edit_url("new", "testcoll", "Default_type", view_id="Default_view") r = self.client.post(u, f) self.assertEqual(r.status_code, 302) self.assertEqual(r.reason_phrase, "Found") self.assertEqual(r.content, b"") self.assertEqual(r['location'], entitydata_list_type_url("testcoll", "Default_type")) # Check new entity data created self._check_entity_data_values( "newentity", type_id="Default_type", type_uri="annal:Default_type", update_dict= { '@type': ['annal:Default_type', 'annal:EntityData'] } ) return
def test_post_new_entity_new_type(self): self.assertFalse(EntityData.exists(self.testdata, "entitynewtype")) f = entitydata_default_view_form_data( entity_id="entitynewtype", action="new", update="Updated entity", new_type="New type" ) u = entitydata_edit_url("new", "testcoll", "testtype", view_id="Default_view") r = self.client.post(u, f) self.assertEqual(r.status_code, 302) self.assertEqual(r.reason_phrase, "FOUND") self.assertEqual(r.content, "") v = TestHostUri + entitydata_edit_url("new", "testcoll", "_type", view_id="Type_view") w = entitydata_edit_url("edit", "testcoll", "testtype", entity_id="entitynewtype", view_id="Default_view") c = continuation_url_param(w) self.assertIn(v, r['location']) self.assertIn(c, r['location']) self._check_entity_data_values("entitynewtype", update="Updated entity") return
def test_CreateTestSiteData(self): copySitedata( settings.SITE_SRC_ROOT + "/sampledata/init/" + test_layout.SITE_DIR, settings.SITE_SRC_ROOT + "/annalist/sitedata", TestBaseDir) testsite = Site(TestBaseUri, TestBaseDir) coll123_create_data(testsite) # testcoll = Collection.create(testsite, "testcoll", collection_create_values("testcoll")) testtype = RecordType.create(testcoll, "testtype", recordtype_create_values("testtype")) # testview = RecordView.create(testcoll, "testview", recordview_create_values("testview")) # testlist = RecordList.create(testcoll, "testlist", recordlist_create_values("testlist")) testdata = RecordTypeData.create(testcoll, "testtype", {}) teste = EntityData.create( testdata, "entity1", entitydata_create_values(testcoll, testtype, "entity1")) return
def coll123_create_data(site): coll1 = Collection.create(site, "coll1", collection_create_values("coll1")) coll2 = Collection.create(site, "coll2", collection_create_values("coll2")) coll3 = Collection.create(site, "coll3", collection_create_values("coll3")) # for coll in [coll1, coll2, coll3]: type1 = RecordType.create(coll, "type1", recordtype_create_values(coll._entityid, "type1")) view1 = RecordView.create(coll, "view1", recordview_create_values(coll._entityid, "view1")) list1 = RecordList.create(coll, "list1", recordlist_create_values(coll._entityid, "list1")) data1 = RecordTypeData.create(coll, "type1", {}) type2 = RecordType.create(coll, "type2", recordtype_create_values(coll._entityid, "type2")) view2 = RecordView.create(coll, "view2", recordview_create_values(coll._entityid, "view2")) list2 = RecordList.create(coll, "list2", recordlist_create_values(coll._entityid, "list2")) data2 = RecordTypeData.create(coll, "type2", {}) # for t,d in [(type1,data1),(type2,data2)]: for eid in ["entity1", "entity2", "entity3"]: e = EntityData.create(d, eid, entitydata_create_values(coll,t,eid)) return
def init_annalist_test_coll(coll_id="testcoll", type_id="testtype"): log.debug("init_annalist_test_coll") testsite = Site(TestBaseUri, TestBaseDir) testcoll = Collection.create(testsite, coll_id, collection_create_values(coll_id)) testtype = RecordType.create(testcoll, type_id, recordtype_create_values(coll_id, type_id)) testdata = RecordTypeData.create(testcoll, type_id, {}) teste = EntityData.create( testdata, "entity1", entitydata_create_values(testcoll,testtype,"entity1") ) testcoll.generate_coll_jsonld_context() # Reset id generator counters EntityData._last_id = 0 RecordType._last_id = 0 RecordView._last_id = 0 RecordList._last_id = 0 RecordField._last_id = 0 AnnalistUser._last_id = 0 return testcoll
def setUp(self): self.testsite = init_annalist_test_site() self.testcoll = init_annalist_named_test_coll(layout.BIBDATA_ID) self.testdata = RecordTypeData.load(self.testcoll, "testtype") self.testtype2 = RecordType.create( self.testcoll, "testtype2", recordtype_create_values("testcoll", "testtype2") ) self.testdata2 = RecordTypeData.create(self.testcoll, "testtype2", {}) create_test_user(self.testcoll, "testuser", "testpassword") self.client = Client(HTTP_HOST=TestHost) loggedin = self.client.login(username="******", password="******") self.assertTrue(loggedin) e1 = self._create_entity_data("entity1") e2 = self._create_entity_data("entity2") e3 = self._create_entity_data("entity3") e4 = EntityData.create(self.testdata2, "entity4", entitydata_create_values("entity4", type_id="testtype2") ) self.list_ids = get_site_bib_lists_linked("testcoll") return
def init_annalist_test_coll(coll_id="testcoll", type_id="testtype"): log.debug("init_annalist_test_coll") testsite = Site(TestBaseUri, TestBaseDir) testcoll = Collection.create(testsite, coll_id, collection_create_values(coll_id)) testtype = RecordType.create(testcoll, type_id, recordtype_create_values(coll_id, type_id)) testdata = RecordTypeData.create(testcoll, type_id, {}) teste = EntityData.create( testdata, "entity1", entitydata_create_values(testcoll, testtype, "entity1")) testcoll.generate_coll_jsonld_context() # Reset id generator counters EntityData._last_id = 0 RecordType._last_id = 0 RecordView._last_id = 0 RecordList._last_id = 0 RecordField._last_id = 0 AnnalistUser._last_id = 0 return testcoll
def test_new_entity_default_type(self): # Checks logic related to creating a new recorddata entity in collection # for type defined in site data self.assertFalse(EntityData.exists(self.testdata, "newentity")) f = entitydata_form_data(entity_id="newentity", type_id="Default_type", action="new") u = entitydata_edit_url("new", "testcoll", "Default_type") r = self.client.post(u, f) self.assertEqual(r.status_code, 302) self.assertEqual(r.reason_phrase, "FOUND") self.assertEqual(r.content, "") self.assertEqual( r['location'], TestHostUri + entitydata_list_type_url("testcoll", "Default_type")) # Check new entity data created self._check_entity_data_values( "newentity", type_id="Default_type", update_dict={'@type': ['annal:Default_type', 'annal:EntityData']}) return
def setUp(self): init_annalist_test_site() self.testsite = Site(TestBaseUri, TestBaseDir) self.testcoll = Collection.create(self.testsite, "testcoll", collection_create_values("testcoll")) self.testtype = RecordType.create(self.testcoll, "testtype", recordtype_create_values("testcoll", "testtype")) self.testtype2 = RecordType.create(self.testcoll, "testtype2", recordtype_create_values("testcoll", "testtype2")) self.testdata = RecordTypeData.create(self.testcoll, "testtype", {}) self.testdata2 = RecordTypeData.create(self.testcoll, "testtype2", {}) # self.user = User.objects.create_user('testuser', '*****@*****.**', 'testpassword') # self.user.save() create_test_user(self.testcoll, "testuser", "testpassword") self.client = Client(HTTP_HOST=TestHost) loggedin = self.client.login(username="******", password="******") self.assertTrue(loggedin) e1 = self._create_entity_data("entity1") e2 = self._create_entity_data("entity2") e3 = self._create_entity_data("entity3") e4 = EntityData.create(self.testdata2, "entity4", entitydata_create_values("entity4", type_id="testtype2") ) self.list_ids = get_site_lists_linked("testcoll") return
def setUp(self): self.testsite = init_annalist_test_site() self.testcoll = init_annalist_named_test_coll(layout.BIBDATA_ID) # Create BibEntry record (BibEntry_type defines field alias) self.testdata = RecordTypeData.create(self.testcoll, "BibEntry_type", {}) self.bibentity1_data = ( { "@type": [ "bib:BibEntry" , ANNAL.CURIE.EntityData ] , ANNAL.CURIE.type: "bib:BibEntry" , ANNAL.CURIE.type_id: "BibEntry_type" , "bib:type": "article" , "bib:title": "bib:title for bibentity1" , "bib:note": "Sample bibliographic entry with field aliasing" , "bib:month": "09" , "bib:year": "2014" , "bib:author": [ { "bib:id": "author_id" , "bib:name": "Author, J. H." , "bib:alternate": "Joe H. Author" , "bib:firstname": "Joe" , "bib:lastname": "Author" }] , "bib:identifier": [] , "bib:journal": [] , "bib:editor": [] , "bib:publication_details": [] , "bib:license": [] , "bib:bookentry": [] }) self.testbib1 = EntityData.create(self.testdata, "bibentity1", self.bibentity1_data) # Login and permissions create_test_user(self.testcoll, "testuser", "testpassword") self.client = Client(HTTP_HOST=TestHost) loggedin = self.client.login(username="******", password="******") self.assertTrue(loggedin) return
def create_test_coll_inheriting( base_coll_id=None, coll_id="testcoll", type_id="testtype"): """ Similar to init_annalist_test_coll, but collection also inherits from named collection. """ testsite = Site(TestBaseUri, TestBaseDir) basecoll = Collection.load(testsite, base_coll_id) if not basecoll: msg = "Base collection %s not found"%base_coll_id log.warning(msg) assert False, msg testcoll = Collection.create(testsite, coll_id, collection_create_values(coll_id)) testcoll.set_alt_entities(basecoll) testcoll._save() testtype = RecordType.create(testcoll, type_id, recordtype_create_values(coll_id, type_id)) testdata = RecordTypeData.create(testcoll, type_id, {}) teste = EntityData.create( testdata, "entity1", entitydata_create_values(testcoll, testtype, "entity1") ) testcoll.generate_coll_jsonld_context() return testcoll
def init_annalist_named_test_coll( base_coll_id=None, coll_id="testcoll", type_id="testtype"): """ Similar to init_annalist_test_coll, but collection also installs and inherits from named collection definitions. """ # @@TODO: DRY: use create_test_coll_inheriting # @@TODO: rename: install_create_test_coll_inheriting log.debug("init_annalist_named_test_coll") testsite = Site(TestBaseUri, TestBaseDir) namedcoll = install_annalist_named_coll(base_coll_id) testcoll = Collection.create(testsite, coll_id, collection_create_values(coll_id)) testcoll.set_alt_entities(namedcoll) testcoll._save() testtype = RecordType.create(testcoll, type_id, recordtype_create_values(coll_id, type_id)) testdata = RecordTypeData.create(testcoll, type_id, {}) teste = EntityData.create( testdata, "entity1", entitydata_create_values(testcoll, testtype, "entity1") ) testcoll.generate_coll_jsonld_context() return testcoll
def test_post_default_form_use_view(self): self._create_entity_data("entityuseview") self.assertTrue(EntityData.exists(self.testdata, "entityuseview")) f = default_view_form_data( entity_id="entityuseview", action="view", use_view="_view/Type_view", ) f.pop('entity_id', None) u = entitydata_edit_url( "view", "testcoll", "testtype", "entityuseview", view_id="Default_view" ) r = self.client.post(u, f) self.assertEqual(r.status_code, 302) self.assertEqual(r.reason_phrase, "Found") self.assertEqual(r.content, b"") v = entitydata_edit_url( "view", "testcoll", "testtype", entity_id="entityuseview", view_id="Type_view" ) c = continuation_url_param("/testsite/c/testcoll/d/testtype/") self.assertIn(v, r['location']) self.assertIn(c, r['location']) self._check_entity_data_values("entityuseview") return
def _create_entity_data(self, entity_id, update="Entity"): "Helper function creates entity data with supplied entity_id" e = EntityData.create(self.testdata, entity_id, entitydata_create_values(entity_id, update=update) ) return e
def setUp(self): init_annalist_test_site() self.testsite = Site(TestBaseUri, TestBaseDir) self.testcoll = Collection.create( self.testsite, "testcoll", collection_create_values("testcoll") ) # Create test types self.testtypes = RecordType.create( self.testcoll, "testtypes", recordtype_create_values( coll_id="testcoll", type_id="testtypes", type_uri="test:testtypes", supertype_uris=[] ) ) self.testtype1 = RecordType.create( self.testcoll, "testtype1", recordtype_create_values( coll_id="testcoll", type_id="testtype1", type_uri="test:testtype1", supertype_uris=["test:testtypes"] ) ) self.testtype2 = RecordType.create( self.testcoll, "testtype2", recordtype_create_values( coll_id="testcoll", type_id="testtype2", type_uri="test:testtype2", supertype_uris=["test:testtypes"] ) ) self.ref_type = RecordType.create( self.testcoll, "ref_type", recordtype_create_values( coll_id="testcoll", type_id="ref_type", type_uri="test:ref_type", supertype_uris=[] ) ) # Create test type data parents self.testdatas = RecordTypeData.create(self.testcoll, "testtypes", {}) self.testdata1 = RecordTypeData.create(self.testcoll, "testtype1", {}) self.testdata2 = RecordTypeData.create(self.testcoll, "testtype2", {}) self.ref_data = RecordTypeData.create(self.testcoll, "ref_type", {}) # Create test type data es = EntityData.create(self.testdatas, "entitys", entitydata_create_values( "entitys", type_id="testtypes", extra_fields={"test:turi": "test:testtypes"} ) ) e1 = EntityData.create(self.testdata1, "entity1", entitydata_create_values( "entity1", type_id="testtype1", extra_fields={"test:turi": "test:testtype1"} ) ) e2 = EntityData.create(self.testdata2, "entity2", entitydata_create_values( "entity2", type_id="testtype2", extra_fields={"test:turi": "test:testtype2"} ) ) # Login and permissions create_test_user(self.testcoll, "testuser", "testpassword") self.client = Client(HTTP_HOST=TestHost) loggedin = self.client.login(username="******", password="******") self.assertTrue(loggedin) return
def create_subproperty_list_field_view_entity(self): # Create list field using superproperty self.test_sup_list = RecordField.create(self.testcoll, "Test_sup_list", { ANNAL.CURIE.type: "annal:Field" , RDFS.CURIE.label: "List using superproperty URI" , RDFS.CURIE.comment: "List using superproperty URI" , ANNAL.CURIE.field_render_type: "_enum_render_type/Group_Seq_Row" , ANNAL.CURIE.field_value_mode: "_enum_value_mode/Value_direct" , ANNAL.CURIE.field_value_type: "annal:Test_sup_list" , ANNAL.CURIE.field_entity_type: "test:testtype" , ANNAL.CURIE.placeholder: "(Test_sup_list)" , ANNAL.CURIE.property_uri: "test:superprop_list_uri" , ANNAL.CURIE.field_placement: "small:0,12" , ANNAL.CURIE.field_fields: [ { ANNAL.CURIE.field_id: "_field/Test_sup_field" , ANNAL.CURIE.field_placement: "small:0,12" } ] , ANNAL.CURIE.repeat_label_add: "Add sup entity" , ANNAL.CURIE.repeat_label_delete: "Remove sup entity" }) self.assertTrue(self.test_sup_list is not None) # Create list field using subproperty and declaring superproperty self.test_sub_list = RecordField.create(self.testcoll, "Test_sub_list", { ANNAL.CURIE.type: "annal:Field" , RDFS.CURIE.label: "List using superproperty URI" , RDFS.CURIE.comment: "List using superproperty URI" , ANNAL.CURIE.field_render_type: "_enum_render_type/Group_Seq_Row" , ANNAL.CURIE.field_value_mode: "_enum_value_mode/Value_direct" , ANNAL.CURIE.field_value_type: "annal:Test_sub_list" , ANNAL.CURIE.field_entity_type: "test:testtype" , ANNAL.CURIE.placeholder: "(Test_sub_list)" , ANNAL.CURIE.property_uri: "test:subprop_list_uri" , ANNAL.CURIE.superproperty_uri: [{"@id": "test:superprop_list_uri"}] , ANNAL.CURIE.field_placement: "small:0,12" , ANNAL.CURIE.field_fields: [ { ANNAL.CURIE.field_id: "_field/Test_sub_field" , ANNAL.CURIE.field_placement: "small:0,12" } ] , ANNAL.CURIE.repeat_label_add: "Add sub entity" , ANNAL.CURIE.repeat_label_delete: "Remove sub entity" }) self.assertTrue(self.test_sub_list is not None) # Create test view using superproperty self.test_view = RecordView.create(self.testcoll, "testlistview", { ANNAL.CURIE.type: "annal:View" , ANNAL.CURIE.uri: "test:listview" , RDFS.CURIE.label: "Test listview label" , RDFS.CURIE.comment: "Test listview comment" , ANNAL.CURIE.view_entity_type: "test:testtype" , ANNAL.CURIE.view_fields: [ { ANNAL.CURIE.field_id: layout.FIELD_TYPEID+"/Entity_id" , ANNAL.CURIE.field_placement: "small:0,12;medium:0,6" } , { ANNAL.CURIE.field_id: layout.FIELD_TYPEID+"/Test_sup_list" , ANNAL.CURIE.field_placement: "small:0,12;medium:0,6" } ] }) self.assertTrue(self.test_view is not None) # Create test entity using list and item subproperty URIs self.testlistentity_data = EntityData.create(self.testdata, "testlistentity", entitydata_create_values( "testlistentity", type_id="testtype", type_uri="test:testtype", extra_fields= { "test:subprop_list_uri": [ { "test:subprop_uri": "Test field 1 value"} , { "test:subprop_uri": "Test field 2 value"} ] } ) ) self.assertTrue(self.testlistentity_data is not None) return