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 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 setUp(self): init_annalist_test_site() init_annalist_test_coll() self.testsite = Site(TestBaseUri, TestBaseDir) self.testcoll = Collection(self.testsite, "testcoll") # Populate collection with linked record types, views and lists self.testsrc_type = RecordType.create(self.testcoll, "testsrc_type", testsrc_type_create_values) self.testtgt_type = RecordType.create(self.testcoll, "testtgt_type", testtgt_type_create_values) self.testsrc_view = RecordView.create(self.testcoll, "testsrc_view", testsrc_view_create_values) self.testtgt_view = RecordView.create(self.testcoll, "testtgt_view", testtgt_view_create_values) self.testsrc_list = RecordList.create(self.testcoll, "testsrc_list", testsrc_list_create_values) self.testtgt_list = RecordList.create(self.testcoll, "testtgt_list", testtgt_list_create_values) self.testtgtref_field = RecordField.create(self.testcoll, "testtgtref_field", testtgtref_field_create_values) self.no_options = [ FieldChoice('', label="(no options)") ] self.tgt_options = ( [ FieldChoice("testtgt_type/"+v, label="testtgt_entity %s label"%v, link=entity_url("testcoll", "testtgt_type", v)) for v in ["testtgt1", "testtgt2"] ]) # Create data records for testing: self.testtgt_type_info = EntityTypeInfo(self.testcoll, "testtgt_type", create_typedata=True) self.testsrc_type_info = EntityTypeInfo(self.testcoll, "testsrc_type", create_typedata=True) for tgt_id in ("testtgt1", "testtgt2"): self.testtgt_type_info.create_entity(tgt_id, testtgt_entity_create_values(tgt_id)) for src_id, tgt_ref in (("testsrc1", "testtgt1"), ("testsrc2", "testtgt2")): self.testsrc_type_info.create_entity(src_id, testsrc_entity_create_values(src_id, tgt_ref)) # 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_recordtype_create_load(self): t = RecordType.create(self.testcoll, "type1", recordtype_create_values(type_id="type1")) td = RecordType.load(self.testcoll, "type1").get_values() v = recordtype_read_values(type_id="type1") self.assertKeysMatch(td, v) self.assertDictionaryMatch(td, v) 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_exists_type(self): # Some type existence tests taking account of site data default type self.assertTrue(RecordType.exists(self.testcoll, "testtype")) self.assertFalse(RecordType.exists(self.testcoll, "notype")) self.assertFalse(RecordType.exists(self.testcoll, "Default_type")) self.assertTrue(RecordType.exists(self.testcoll, "Default_type", altscope="all")) 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 test_alt_parent_inherit_site(self): # Test inheritance of definitions from site with an alternative collection set coll_id = "newcoll" newcoll = Collection.create(self.testsite, coll_id, collection_create_values(coll_id)) altparents = newcoll.set_alt_entities(self.testcoll) parentids = [ p.get_id() for p in altparents ] self.assertEqual(parentids, ["newcoll", "testcoll", layout.SITEDATA_ID]) self.assertTrue(RecordType.exists(newcoll, "Default_type", altscope="all")) def_type = RecordType.load(newcoll, "Default_type", altscope="all") self.assertEquals(def_type["rdfs:label"], "Default record") return
def test_post_new_type_cancel(self): self.assertFalse(RecordType.exists(self.testcoll, "newtype")) f = recordtype_entity_view_form_data( type_id="newtype", action="new", cancel="Cancel", update="Updated RecordType" ) u = entitydata_edit_url("new", "testcoll", layout.TYPE_TYPEID, 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 still does not exist self.assertFalse(RecordType.exists(self.testcoll, "newtype")) return
def setUp(self): self.filepath = "%s/README.md"%TestBaseDir self.fileuri = "file://"+self.filepath self.imagepath = "%s/test-image.jpg"%TestBaseDir self.imageuri = "file://"+self.filepath init_annalist_test_site() init_annalist_test_coll() self.testsite = Site(TestBaseUri, TestBaseDir) self.testcoll = Collection(self.testsite, "testcoll") # Populate collection with record type, view and field self.test_ref_type = RecordType.create( self.testcoll, "testreftype", test_image_ref_type_create_values ) self.test_ref_view = RecordView.create( self.testcoll, "testrefview", test_image_ref_view_create_values ) self.test_ref_field = RecordField.create( self.testcoll, "Test_image_ref", test_image_ref_field_create_values ) # Create data records for testing image references: self.test_ref_type_info = EntityTypeInfo( self.testcoll, "testreftype", create_typedata=True ) self.test_ref_type_info.create_entity("test1", test_ref_entity_create_values(self.imageuri)) # 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("testtype")) self.testdata = RecordTypeData.create(self.testcoll, "testtype", {}) # Create view with duplicate field id self.viewdata = recordview_create_values(view_id="DupField_view") recordview_values_add_field( self.viewdata, field_id="Entity_comment", field_placement="small:0,12" ) recordview_values_add_field( self.viewdata, field_id="Entity_comment", field_property_uri="rdfs:comment_alt", field_placement="small:0,12" ) self.testview = RecordView.create(self.testcoll, "DupField_view", self.viewdata) # 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_post_delete_type_entity(self): testtypedelete = RecordType.create(self.testcoll, "testtypedelete", recordtype_create_values("testcoll", "testtypedelete")) testdatadelete = RecordTypeData.create(self.testcoll, "testtypedelete", {}) f = entitylist_form_data("delete", entities=["_type/testtypedelete"]) u = entitydata_list_type_url("testcoll", "_type", list_id="Type_list") r = self.client.post(u, f) self.assertEqual(r.status_code, 200) self.assertEqual(r.reason_phrase, "OK") self.assertContains(r, "<h3>Confirm requested action</h3>") self.assertContains(r, "Remove record testtypedelete of type _type in collection testcoll: Are you sure?") self.assertContains(r, 'Click "Confirm" to continue, or "Cancel" to abort operation') self.assertContains(r, '<input type="hidden" name="confirmed_action" value="/testsite/c/testcoll/d/_type/!delete_confirmed"/>', html=True ) self.assertEqual(r.context['action_description'], 'Remove record testtypedelete of type _type in collection testcoll') self.assertEqual(r.context['confirmed_action'], '/testsite/c/testcoll/d/_type/!delete_confirmed') self.assertEqual(r.context['action_params'], confirm_delete_params(button_id="entity_delete", entity_id="testtypedelete", type_id="_type", list_id="Type_list") ) self.assertEqual(r.context['cancel_action'], '/testsite/c/testcoll/l/Type_list/_type/') return
def get_type(self, type_id): """ Retrieve identified type description type_id local identifier for the type to retrieve. returns a RecordType object for the identified type, or None. """ self._load_types() t = self._types_by_id.get(type_id, None) # Was it created but not cached? if not t and RecordType.exists(self, type_id, altscope="all"): log.info("___ Collection.get_type: "+type_id) t = RecordType.load(self, type_id, altscope="all") self._update_type_cache(t) return t
def setUp(self): self.fileuri = "file://%s/README.md"%TestBaseDir init_annalist_test_site() init_annalist_test_coll() self.testsite = Site(TestBaseUri, TestBaseDir) self.testcoll = Collection(self.testsite, "testcoll") # Populate collection with linked record types, views and lists self.test_imp_type = RecordType.create( self.testcoll, "testimptype", test_import_type_create_values ) self.test_imp_view = RecordView.create( self.testcoll, "testimpview", test_import_view_create_values ) self.test_imp_field = RecordField.create( self.testcoll, "Test_import", test_import_field_create_values ) self.test_ref_type = RecordType.create( self.testcoll, "testreftype", test_reference_type_create_values ) self.test_ref_view = RecordView.create( self.testcoll, "testrefview", test_reference_view_create_values ) self.test_ref_field = RecordField.create( self.testcoll, "Test_reference", test_reference_field_create_values ) # Create data records for testing import and references: self.test_imp_type_info = EntityTypeInfo( self.testcoll, "testimptype", create_typedata=True ) for entity_id in ("test1", "test2"): self.test_imp_type_info.create_entity( entity_id, test_imp_entity_create_values(entity_id) ) self.test_ref_type_info = EntityTypeInfo( self.testcoll, "testreftype", create_typedata=True ) for entity_id in ("test1", "test2"): self.test_ref_type_info.create_entity( entity_id, test_ref_entity_create_values(entity_id) ) # 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 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 cache_get_vocab(self, vocab_id): """ Retrieve namespace vocabulary entity for id (namespace prefix) from cache. Returns namespace vocabulary entity if found, otherwise None. """ vocab_cache.get_vocab(self, vocab_id) t = vocab_cache.get_vocab(self, vocab_id) # Was it previously created but not cached? if not t and RecordType.exists(self, vocab_id, altscope="all"): msg = ( "Collection.get_vocab %s present but not cached for collection %s"% (vocab_id, self.get_id()) ) log.warning(msg) t = RecordType.load(self, vocab_id, altscope="all") vocab_cache.set_vocab(self, t) # raise ValueError(msg) #@@@ (used in testing to help pinpoint errors) return t
def cache_get_type(self, type_id): """ Retrieve type from cache. Returns type entity if found, otherwise None. """ type_cache.get_type(self, type_id) t = type_cache.get_type(self, type_id) # Was it previously created but not cached? if not t and RecordType.exists(self, type_id, altscope="all"): msg = ( "Collection.get_type %s present but not cached for collection %s"% (type_id, self.get_id()) ) log.warning(msg) t = RecordType.load(self, type_id, altscope="all") type_cache.set_type(self, t) # raise ValueError(msg) #@@@ (used in testing to help pinpoint errors) return t
def remove_type(self, type_id): """ Remove identified type description type_id local identifier for the type to remove. Returns None on success, or a non-False status code if the type is not removed. """ s = RecordType.remove(self, type_id) return s
def _load_types(self): """ Initialize cache of RecordType entities """ if not (self._types_by_id and self._types_by_uri): self._types_by_id = {} self._types_by_uri = {} for type_id in self._children(RecordType, altscope="all"): t = RecordType.load(self, type_id, altscope="all") self._update_type_cache(t) return
def remove_type(self, type_id): """ Remove identified type description type_id local identifier for the type to remove. Returns a non-False status code if the type is not removed. """ self._flush_type(type_id) s = RecordType.remove(self, type_id) return s
def _check_record_type_values(self, type_id, update="RecordType", type_uri=None, extra_values=None ): "Helper function checks content of record type entry with supplied type_id" self.assertTrue(RecordType.exists(self.testcoll, type_id)) t = RecordType.load(self.testcoll, type_id) self.assertEqual(t.get_id(), type_id) self.assertEqual(t.get_view_url(), TestHostUri + recordtype_url("testcoll", type_id)) v = recordtype_values( type_id=type_id, update=update, type_uri=type_uri ) if extra_values: v.update(extra_values) # print "t: "+repr(t.get_values()) # print "v: "+repr(v) self.assertDictionaryMatch(t.get_values(), v) return t
def setUp(self): # Set up basic site data 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("testtype")) self.testdata = RecordTypeData.create(self.testcoll, "testtype", {}) # 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", {}) # 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 test_post_confirmed_remove_type(self): t = RecordType.create(self.testcoll, "deletetype", recordtype_create_values("deletetype")) self.assertTrue(RecordType.exists(self.testcoll, "deletetype")) # Submit positive confirmation u = TestHostUri + recordtype_edit_url("delete", "testcoll") f = recordtype_delete_confirm_form_data("deletetype") 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+ collection_edit_url("testcoll")+ r"\?.*info_head=.*$" ) self.assertMatch(r['location'], "^"+TestHostUri+ collection_edit_url("testcoll")+ r"\?.*info_message=.*deletetype.*testcoll.*$" ) # Confirm deletion self.assertFalse(RecordType.exists(self.testcoll, "deletetype")) return
def add_type(self, type_id, type_meta): """ Add a new or updated record type to the current collection type_id identifier for the new type, as a string with a form that is valid as URI path segment. type_meta a dictionary providing additional information about the type to be created. Returns a RecordType object for the newly created type. """ log.debug("Collection.add_type %s in %s"%(type_id, self.get_id())) t = RecordType.create(self, type_id, type_meta) return t
def setUp(self): init_annalist_test_site() self.testsite = Site(TestBaseUri, TestBaseDir) self.testcoll = Collection(self.testsite, "testcoll") self.testcoll1_a = Collection(self.testsite, "testcoll1") self.testcoll1_b = Collection(self.testsite, "testcoll1") self.testcoll2_a = Collection(self.testsite, "testcoll2") self.testcoll2_b = Collection(self.testsite, "testcoll2") self.typecache = CollectionTypeCache() self.type1 = RecordType(self.testcoll1_a, "type1") self.type1.set_values( recordtype_create_values(type_id="type1", type_uri="test:type1", supertype_uris=[] ) ) self.type11 = RecordType(self.testcoll1_a, "type11") self.type11.set_values( recordtype_create_values(type_id="type11", type_uri="test:type11", supertype_uris=["test:type1"] ) ) self.type111 = RecordType(self.testcoll1_a, "type111") self.type111.set_values( recordtype_create_values(type_id="type111", type_uri="test:type111", supertype_uris=["test:type11"] ) ) self.type12 = RecordType(self.testcoll1_a, "type12") self.type12.set_values( recordtype_create_values(type_id="type12", type_uri="test:type12", supertype_uris=["test:type1"] ) ) self.type2 = RecordType(self.testcoll1_a, "type2") self.type2.set_values( recordtype_create_values(type_id="type2", type_uri="test:type2", supertype_uris=[] ) ) self.type21 = RecordType(self.testcoll1_a, "type21") self.type21.set_values( recordtype_create_values(type_id="type21", type_uri="test:type21", supertype_uris=["test:type2"] ) ) self.type22 = RecordType(self.testcoll1_a, "type22") self.type22.set_values( recordtype_create_values(type_id="type22", type_uri="test:type22", supertype_uris=["test:type2"] ) ) return
def add_type(self, type_id, type_meta): """ Add a new record type to the current collection type_id identifier for the new type, as a string with a form that is valid as URI path segment. type_meta a dictionary providing additional information about the type to be created. Returns a RecordType object for the newly created type. """ t = RecordType.create(self, type_id, type_meta) if self._types_by_id: self._update_type_cache(t) return t
def test_post_copy_type(self): self.assertFalse(RecordType.exists(self.testcoll, "copytype")) f = recordtype_entity_view_form_data( type_id="copytype", orig_id="Default_type", action="copy", update="RecordType" ) u = entitydata_edit_url( "copy", "testcoll", layout.TYPE_TYPEID, entity_id="Default_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, "") self.assertEqual(r['location'], self.continuation_url) # Check that new record type exists self._check_record_type_values("copytype", update="RecordType") return
def test_recordtype2_data(self): t = RecordType(self.testcoll, "type2") self.assertEqual(t.get_id(), "type2") self.assertEqual(t.get_type_id(), layout.TYPE_TYPEID) self.assertIn( "/c/testcoll/_annalist_collection/%(type_dir)s/type2/"%self.layout, t.get_url() ) self.assertEqual( TestBaseUri + "/c/testcoll/d/%(type_typeid)s/type2/"%self.layout, t.get_view_url() ) t.set_values(recordtype_create_values(type_id="type2")) td = t.get_values() self.assertEqual(set(td.keys()), set(recordtype_value_keys())) v = recordtype_values(type_id="type2") self.assertDictionaryMatch(td, v) return
def setUp(self): init_annalist_test_site() init_annalist_test_coll() 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("testtype")) self.testdata = RecordTypeData.create(self.testcoll, "testtype", {}) self.no_options = [ FieldChoice('', label="(no options)") ] self.no_view_id = [ FieldChoice('', label="(view id)") ] self.no_list_id = [ FieldChoice('', label="(list id)") ] self.view_options = get_site_views_linked("testcoll") self.list_options = 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 __init__(self, coll, type_id, create_typedata=False): """ Set up type attribute values. coll collection object in which type is used type_id entity type id, which is a collection-defined value, or one of a number of special site-wide built-in types. create_typedata if true, requests that a RecordTypeData entity be created and saved on disk for user-defined types if it does not already exist. (Creating a RecordTypeData entity ensures that the corresponding data storage location is available for saving entity data.) Attributes of type information object are: recordtype type object describing the identified type entityparent Parent entity for entities of this type, or None if the type is not defined for the collection entityaltparent Alternative (site-wide) parent entity for built-in types, or None entityclass Python class object for entity entitymessages a table of message strings for diagnostics relating to operations on this type. and other values as initialized here. """ self.entitycoll = coll self.recordtype = None self.entityparent = None self.coll_id = coll.get_id() self.type_id = type_id self.permissions_map = None if type_id == layout.COLL_TYPEID: # "_coll" # NOTE: # # This setup defaults to using site permissions for collection operations. # But there is some special-case code in views.displayinfo that uses the # collection itself if it exists. # # (See use of attribute DisplayInfo.coll_perms.) # self.recordtype = coll.get_site().site_data_collection().get_type( type_id) self.entityparent = coll.get_site() self.entityaltparent = None self.entityclass = Collection self.entitymessages = COLL_MESSAGES self.permissions_map = CONFIG_PERMISSIONS # unless entity is layout.SITEDATA_ID? elif type_id in TYPE_CLASS_MAP: self.recordtype = coll.get_type(type_id) self.entityparent = coll self.entityaltparent = coll.get_site() self.entityclass = TYPE_CLASS_MAP[type_id] self.entitymessages = TYPE_MESSAGE_MAP[type_id] if self.coll_id == layout.SITEDATA_ID: self.permissions_map = SITE_PERMISSIONS_MAP[type_id] else: self.permissions_map = TYPE_PERMISSIONS_MAP[type_id] else: if not valid_id(type_id): raise ValueError("EntityTypeInfo invalid type_id (%s)" % (type_id, )) if RecordType.exists(coll, type_id, altscope="all"): # log.info("@@ EntityTypeInfo: Type %s exists"%type_id) self.recordtype = coll.get_type(type_id) else: # log.info("@@ EntityTypeInfo: Type %s does not exist for collection %s"%(type_id,coll.get_id())) pass if create_typedata and not RecordTypeData.exists(coll, type_id): self.entityparent = RecordTypeData.create(coll, type_id, {}) else: self.entityparent = RecordTypeData(coll, type_id) self.entityaltparent = None self.entityclass = EntityData self.entitymessages = ENTITY_MESSAGES self.permissions_map = ENTITY_PERMISSIONS if not self.recordtype: # .recordtype is used by views.displayinfo to locate the default # view and/or list id for examining records of a particular type. # Also used in entityedit for getting @type URI/CURIE values. # Used in bound_field to get link to type record log.warning("EntityTypeInfo.__init__: RecordType %s not found" % type_id) # log.info("".join(traceback.format_stack())) # raise ValueError("Trace") return
def setUp(self): self.filepath = "%s/testdatafile.md" % TestBaseDir self.fileuri = "file://" + self.filepath self.imagepath = "%s/test-image.jpg" % TestBaseDir self.imageuri = "file://" + self.imagepath init_annalist_test_site() init_annalist_test_coll() self.testsite = Site(TestBaseUri, TestBaseDir) self.testcoll = Collection(self.testsite, "testcoll") # Populate collection with linked record types, views and lists # Types self.test_upl_type = RecordType.create(self.testcoll, "testupltype", test_upload_type_create_values) self.test_ref_type = RecordType.create( self.testcoll, "testreftype", test_reference_type_create_values) self.test_image_type = RecordType.create( self.testcoll, "testimgtype", test_image_type_create_values) # Views self.test_upl_file_view = RecordView.create( self.testcoll, "testuplfileview", test_upload_file_view_create_values) self.test_upl_image_view = RecordView.create( self.testcoll, "testuplimageview", test_upload_image_view_create_values) self.test_ref_file_view = RecordView.create( self.testcoll, "testrefview", test_reference_view_create_values) self.test_ref_image_view = RecordView.create( self.testcoll, "testimgrefview", test_image_ref_view_create_values) self.test_image_view = RecordView.create( self.testcoll, "testimgview", test_image_view_create_values) # Fields self.test_upl_file_field = RecordField.create( self.testcoll, "Test_upload_file", test_upload_file_field_create_values) self.test_upl_image_field = RecordField.create( self.testcoll, "Test_upload_image", test_upload_image_field_create_values) self.test_ref_file_field = RecordField.create( self.testcoll, "Test_reference", test_reference_field_create_values) self.test_ref_image_field = RecordField.create( self.testcoll, "Test_image_ref", test_image_ref_field_create_values) self.test_image_field = RecordField.create( self.testcoll, "Test_image", test_image_field_create_values) # Create data records for testing import and references: test_entity_ids = ("test1", "test2") test_entity_ids = ("test1", ) self.test_upl_type_info = EntityTypeInfo(self.testcoll, "testupltype", create_typedata=True) for entity_id in test_entity_ids: self.test_upl_type_info.create_entity( entity_id, test_imp_entity_create_values(entity_id)) self.test_ref_type_info = EntityTypeInfo(self.testcoll, "testreftype", create_typedata=True) for entity_id in test_entity_ids: self.test_ref_type_info.create_entity( entity_id, test_ref_entity_create_values(entity_id)) self.test_img_type_info = EntityTypeInfo(self.testcoll, "testimgtype", create_typedata=True) for entity_id in test_entity_ids: self.test_img_type_info.create_entity( entity_id, test_img_entity_create_values(entity_id)) # 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
class CollectionTypeCacheTest(AnnalistTestCase): """ Tests for collection type and supertype cache classes. """ def setUp(self): init_annalist_test_site() self.testsite = Site(TestBaseUri, TestBaseDir) self.testcoll = Collection(self.testsite, "testcoll") self.testcoll1_a = Collection(self.testsite, "testcoll1") self.testcoll1_b = Collection(self.testsite, "testcoll1") self.testcoll2_a = Collection(self.testsite, "testcoll2") self.testcoll2_b = Collection(self.testsite, "testcoll2") self.typecache = CollectionTypeCache() self.type1 = RecordType(self.testcoll1_a, "type1") self.type1.set_values( recordtype_create_values(type_id="type1", type_uri="test:type1", supertype_uris=[])) self.type11 = RecordType(self.testcoll1_a, "type11") self.type11.set_values( recordtype_create_values(type_id="type11", type_uri="test:type11", supertype_uris=["test:type1"])) self.type111 = RecordType(self.testcoll1_a, "type111") self.type111.set_values( recordtype_create_values(type_id="type111", type_uri="test:type111", supertype_uris=["test:type11"])) self.type12 = RecordType(self.testcoll1_a, "type12") self.type12.set_values( recordtype_create_values(type_id="type12", type_uri="test:type12", supertype_uris=["test:type1"])) self.type2 = RecordType(self.testcoll1_a, "type2") self.type2.set_values( recordtype_create_values(type_id="type2", type_uri="test:type2", supertype_uris=[])) self.type21 = RecordType(self.testcoll1_a, "type21") self.type21.set_values( recordtype_create_values(type_id="type21", type_uri="test:type21", supertype_uris=["test:type2"])) self.type22 = RecordType(self.testcoll1_a, "type22") self.type22.set_values( recordtype_create_values(type_id="type22", type_uri="test:type22", supertype_uris=["test:type2"])) return def create_type_record(self, coll, type_entity): return RecordType.create(coll, type_entity.get_id(), type_entity.get_values()) def create_test_type_entities(self): # Create type records in collection data self.create_type_record(self.testcoll1_a, self.type1) self.create_type_record(self.testcoll1_a, self.type11) self.create_type_record(self.testcoll1_a, self.type111) self.create_type_record(self.testcoll1_a, self.type12) self.create_type_record(self.testcoll1_a, self.type2) self.create_type_record(self.testcoll1_a, self.type21) self.create_type_record(self.testcoll1_a, self.type22) # Add all types to cache self.typecache.set_type(self.testcoll1_a, self.type1) self.typecache.set_type(self.testcoll1_a, self.type11) self.typecache.set_type(self.testcoll1_a, self.type111) self.typecache.set_type(self.testcoll1_a, self.type12) self.typecache.set_type(self.testcoll1_a, self.type2) self.typecache.set_type(self.testcoll1_a, self.type21) self.typecache.set_type(self.testcoll1_a, self.type22) # Check cache content self.expect_site_type_ids = ({ "_coll", "_enum_list_type", "_enum_render_type", "_enum_value_mode", "_enum_value_type", "_field", "_group", "_list", "_type", "_user", "_view", "_vocab", "Default_type" }) self.expect_coll_type_ids = ({ "type1", "type11", "type111", "type12", "type2", "type21", "type22" }) self.expect_all_type_ids = set.union(self.expect_site_type_ids, self.expect_coll_type_ids) retrieve_type_ids = set( t.get_id() for t in self.typecache.get_all_types(self.testcoll1_a)) self.assertEqual(retrieve_type_ids, self.expect_coll_type_ids) return def tearDown(self): resetSitedata(scope="collections") return def test_empty_cache(self): self.assertEqual(set(self.typecache.get_all_types(self.testcoll1_a)), set()) self.assertEqual(set(self.typecache.get_all_types(self.testcoll1_b)), set()) self.assertEqual(set(self.typecache.get_all_types(self.testcoll2_a)), set()) self.assertEqual(set(self.typecache.get_all_types(self.testcoll2_b)), set()) return def test_singleton_cache(self): self.assertEqual([ t.get_uri() for t in self.typecache.get_all_types(self.testcoll1_a) ], []) # NOTE: if the 'set_type' call also causes cache initialization of all types, # including the created type record which is discovered on disk, and the subsequent # set_type call returns 'False'. self.create_type_record(self.testcoll1_a, self.type1) self.assertFalse(self.typecache.set_type(self.testcoll1_a, self.type1)) # self.assertIsNone(self.testcoll1_a.remove_type("type1")) self.assertFalse(self.typecache.set_type(self.testcoll1_a, self.type1)) self.assertFalse(self.typecache.set_type(self.testcoll1_b, self.type1)) self.assertEqual( self.typecache.get_type(self.testcoll1_a, "type1").get_uri(), "test:type1") self.assertEqual( self.typecache.get_type(self.testcoll1_b, "type1").get_uri(), "test:type1") self.assertEqual(self.typecache.get_type(self.testcoll1_a, "type2"), None) self.assertEqual(self.typecache.get_type(self.testcoll1_b, "type2"), None) self.assertEqual( self.typecache.get_type_from_uri(self.testcoll1_a, "test:type1").get_id(), "type1") self.assertEqual( self.typecache.get_type_from_uri(self.testcoll1_b, "test:type1").get_id(), "type1") self.assertEqual( self.typecache.get_type_from_uri(self.testcoll1_a, "test:type2"), None) self.assertEqual( self.typecache.get_type_from_uri(self.testcoll1_b, "test:type3"), None) self.assertEqual([ t.get_uri() for t in self.typecache.get_all_types(self.testcoll1_a) ], ["test:type1"]) self.assertEqual([ t.get_uri() for t in self.typecache.get_all_types(self.testcoll1_b) ], ["test:type1"]) self.assertEqual([ t.get_uri() for t in self.typecache.get_all_types(self.testcoll2_a) ], []) self.assertEqual([ t.get_uri() for t in self.typecache.get_all_types(self.testcoll2_b) ], []) return def test_empty_cache_2(self): self.typecache.set_type(self.testcoll1_a, self.type1) self.assertIsNotNone( self.typecache.remove_type(self.testcoll1_a, "type1")) self.assertIsNone(self.typecache.remove_type(self.testcoll1_b, "type1")) self.assertEqual(list(self.typecache.get_all_types(self.testcoll1_a)), []) self.assertEqual(list(self.typecache.get_all_types(self.testcoll1_b)), []) self.assertEqual(list(self.typecache.get_all_types(self.testcoll2_a)), []) self.assertEqual(list(self.typecache.get_all_types(self.testcoll2_b)), []) return def test_flush_cache(self): self.typecache.set_type(self.testcoll1_a, self.type1) self.assertTrue(self.typecache.flush_cache(self.testcoll1_a)) self.assertIsNone(self.typecache.remove_type(self.testcoll1_b, "type1")) self.assertEqual(list(self.typecache.get_all_types(self.testcoll1_a)), []) self.assertEqual(list(self.typecache.get_all_types(self.testcoll1_b)), []) self.assertEqual(list(self.typecache.get_all_types(self.testcoll2_a)), []) self.assertEqual(list(self.typecache.get_all_types(self.testcoll2_b)), []) self.assertTrue(self.typecache.flush_cache(self.testcoll1_b)) self.assertFalse(self.typecache.flush_cache(self.testcoll1_b)) return # def test_collection_has_cache(self): # # Initial state - no cache # self.assertFalse(self.typecache.collection_has_cache(self.testcoll1_a)) # self.assertFalse(self.typecache.collection_has_cache(self.testcoll1_b)) # self.assertFalse(self.typecache.collection_has_cache(self.testcoll2_a)) # self.assertFalse(self.typecache.collection_has_cache(self.testcoll2_b)) # # Add type: non-empty cache exists for collection # self.typecache.set_type(self.testcoll1_a, self.type1) # self.assertTrue(self.typecache.collection_has_cache(self.testcoll1_a)) # self.assertTrue(self.typecache.collection_has_cache(self.testcoll1_b)) # self.assertFalse(self.typecache.collection_has_cache(self.testcoll2_a)) # self.assertFalse(self.typecache.collection_has_cache(self.testcoll2_b)) # # Remove type: collection cache is empty # self.assertIsNotNone(self.typecache.remove_type(self.testcoll1_a, "type1")) # self.assertFalse(self.typecache.collection_has_cache(self.testcoll1_a)) # self.assertFalse(self.typecache.collection_has_cache(self.testcoll1_b)) # self.assertFalse(self.typecache.collection_has_cache(self.testcoll2_a)) # self.assertFalse(self.typecache.collection_has_cache(self.testcoll2_b)) # self.assertIsNone(self.typecache.remove_type(self.testcoll1_b, "type1")) # # Flush cache: cache is empty, so effectively no longer exists # self.assertFalse(self.typecache.flush_cache(self.testcoll1_a)) # self.assertFalse(self.typecache.collection_has_cache(self.testcoll1_a)) # self.assertFalse(self.typecache.collection_has_cache(self.testcoll1_b)) # self.assertFalse(self.typecache.collection_has_cache(self.testcoll2_a)) # self.assertFalse(self.typecache.collection_has_cache(self.testcoll2_b)) # # Add type again: non-empty cache exists for collection # self.typecache.set_type(self.testcoll1_a, self.type1) # self.assertTrue(self.typecache.collection_has_cache(self.testcoll1_a)) # self.assertTrue(self.typecache.collection_has_cache(self.testcoll1_b)) # self.assertFalse(self.typecache.collection_has_cache(self.testcoll2_a)) # self.assertFalse(self.typecache.collection_has_cache(self.testcoll2_b)) # # Flush cache: this time returns True as non-empty cache existed # self.assertTrue(self.typecache.flush_cache(self.testcoll1_a)) # self.assertFalse(self.typecache.collection_has_cache(self.testcoll1_a)) # self.assertFalse(self.typecache.collection_has_cache(self.testcoll1_b)) # self.assertFalse(self.typecache.collection_has_cache(self.testcoll2_a)) # self.assertFalse(self.typecache.collection_has_cache(self.testcoll2_b)) # self.assertIsNone(self.typecache.remove_type(self.testcoll1_b, "type1")) # return def test_get_types_by_uri(self): self.create_test_type_entities() self.assertEqual( self.typecache.get_type_from_uri(self.testcoll1_b, "test:type1").get_id(), "type1") self.assertEqual( self.typecache.get_type_from_uri(self.testcoll1_b, "test:type11").get_id(), "type11") self.assertEqual( self.typecache.get_type_from_uri(self.testcoll1_b, "test:type111").get_id(), "type111") self.assertEqual( self.typecache.get_type_from_uri(self.testcoll1_b, "test:type12").get_id(), "type12") self.assertEqual( self.typecache.get_type_from_uri(self.testcoll1_b, "test:type2").get_id(), "type2") self.assertEqual( self.typecache.get_type_from_uri(self.testcoll1_b, "test:type21").get_id(), "type21") self.assertEqual( self.typecache.get_type_from_uri(self.testcoll1_b, "test:type22").get_id(), "type22") return def test_get_all_types_scope_coll(self): self.create_test_type_entities() type_ids = set(t.get_id() for t in self.typecache.get_all_types(self.testcoll1_a)) self.assertEqual(type_ids, self.expect_coll_type_ids) type_ids = set(t.get_id() for t in self.typecache.get_all_types(self.testcoll1_b)) self.assertEqual(type_ids, self.expect_coll_type_ids) return def test_get_all_types_scope_all(self): self.create_test_type_entities() type_ids = set(t.get_id() for t in self.typecache.get_all_types(self.testcoll1_a, altscope="all")) self.assertEqual(type_ids, self.expect_all_type_ids) # type_ids = set(t.get_id() for t in self.typecache.get_all_types(self.testcoll1_b, altscope="all")) # self.assertEqual(type_ids, self.expect_all_type_ids) return def test_get_supertypes(self): self.create_test_type_entities() def get_supertype_uris(type_uri): st_entities = self.typecache.get_type_uri_supertypes( self.testcoll1_b, type_uri) st_uris = [st.get_uri() for st in st_entities] return set(st_uris) self.assertEqual(get_supertype_uris("test:type1"), set({})) self.assertEqual(get_supertype_uris("test:type11"), {"test:type1"}) self.assertEqual(get_supertype_uris("test:type111"), {"test:type1", "test:type11"}) self.assertEqual(get_supertype_uris("test:type12"), {"test:type1"}) self.assertEqual(get_supertype_uris("test:type2"), set({})) self.assertEqual(get_supertype_uris("test:type21"), {"test:type2"}) self.assertEqual(get_supertype_uris("test:type22"), {"test:type2"}) return def test_get_subtypes(self): self.create_test_type_entities() def get_subtype_uris(type_uri): st_entities = self.typecache.get_type_uri_subtypes( self.testcoll1_b, type_uri) st_uris = [st.get_uri() for st in st_entities] return set(st_uris) self.assertEqual(get_subtype_uris("test:type1"), {"test:type11", "test:type111", "test:type12"}) self.assertEqual(get_subtype_uris("test:type11"), {"test:type111"}) self.assertEqual(get_subtype_uris("test:type111"), set({})) self.assertEqual(get_subtype_uris("test:type12"), set({})) self.assertEqual(get_subtype_uris("test:type2"), {"test:type21", "test:type22"}) self.assertEqual(get_subtype_uris("test:type21"), set({})) self.assertEqual(get_subtype_uris("test:type22"), set({})) return def test_update_supertype(self): self.create_test_type_entities() def get_supertype_uris(type_uri): st_entities = self.typecache.get_type_uri_supertypes( self.testcoll1_b, type_uri) st_uris = [st.get_uri() for st in st_entities] return set(st_uris) self.assertEqual(get_supertype_uris("test:type1"), set({})) self.assertEqual(get_supertype_uris("test:type11"), {"test:type1"}) self.assertEqual(get_supertype_uris("test:type111"), {"test:type1", "test:type11"}) self.assertEqual(get_supertype_uris("test:type12"), {"test:type1"}) # Update super/sub-type self.typecache.remove_type(self.testcoll1_a, "type11") self.typecache.set_type(self.testcoll1_a, self.type11) # Re-check supertypes self.assertEqual(get_supertype_uris("test:type1"), set({})) self.assertEqual(get_supertype_uris("test:type11"), {"test:type1"}) self.assertEqual(get_supertype_uris("test:type111"), {"test:type1", "test:type11"}) self.assertEqual(get_supertype_uris("test:type12"), {"test:type1"}) return def test_update_subtype(self): self.create_test_type_entities() def get_subtype_uris(type_uri): st_entities = self.typecache.get_type_uri_subtypes( self.testcoll1_b, type_uri) st_uris = [st.get_uri() for st in st_entities] return set(st_uris) self.assertEqual(get_subtype_uris("test:type1"), {"test:type11", "test:type111", "test:type12"}) self.assertEqual(get_subtype_uris("test:type11"), {"test:type111"}) self.assertEqual(get_subtype_uris("test:type111"), set({})) self.assertEqual(get_subtype_uris("test:type12"), set({})) # Update super/sub-type self.typecache.remove_type(self.testcoll1_a, "type11") self.typecache.set_type(self.testcoll1_a, self.type11) # Re-check subtypes self.assertEqual(get_subtype_uris("test:type1"), {"test:type11", "test:type111", "test:type12"}) self.assertEqual(get_subtype_uris("test:type11"), {"test:type111"}) self.assertEqual(get_subtype_uris("test:type111"), set({})) self.assertEqual(get_subtype_uris("test:type12"), set({})) return
def setUp(self): init_annalist_test_site() self.testsite = Site(TestBaseUri, TestBaseDir) self.testcoll = Collection(self.testsite, "testcoll") self.testcoll1_a = Collection(self.testsite, "testcoll1") self.testcoll1_b = Collection(self.testsite, "testcoll1") self.testcoll2_a = Collection(self.testsite, "testcoll2") self.testcoll2_b = Collection(self.testsite, "testcoll2") self.typecache = CollectionTypeCache() self.type1 = RecordType(self.testcoll1_a, "type1") self.type1.set_values( recordtype_create_values(type_id="type1", type_uri="test:type1", supertype_uris=[])) self.type11 = RecordType(self.testcoll1_a, "type11") self.type11.set_values( recordtype_create_values(type_id="type11", type_uri="test:type11", supertype_uris=["test:type1"])) self.type111 = RecordType(self.testcoll1_a, "type111") self.type111.set_values( recordtype_create_values(type_id="type111", type_uri="test:type111", supertype_uris=["test:type11"])) self.type12 = RecordType(self.testcoll1_a, "type12") self.type12.set_values( recordtype_create_values(type_id="type12", type_uri="test:type12", supertype_uris=["test:type1"])) self.type2 = RecordType(self.testcoll1_a, "type2") self.type2.set_values( recordtype_create_values(type_id="type2", type_uri="test:type2", supertype_uris=[])) self.type21 = RecordType(self.testcoll1_a, "type21") self.type21.set_values( recordtype_create_values(type_id="type21", type_uri="test:type21", supertype_uris=["test:type2"])) self.type22 = RecordType(self.testcoll1_a, "type22") self.type22.set_values( recordtype_create_values(type_id="type22", type_uri="test:type22", supertype_uris=["test:type2"])) return
def create_type_record(self, coll, type_entity): return RecordType.create(coll, type_entity.get_id(), type_entity.get_values())
def __init__(self, site, coll, type_id, create_typedata=False): """ Set up type attribute values. site current site object coll collection object in which type is used type_id entity type id, which is a collection-defined value, or one of a number of special site-wide built-in types. create_typedata if true, requests that a RecordTypeData entity be created and saved on disk for user-defined types if it does not already exist. (Creating a RecordTypeData entity ensures that the corresponding data storage location is available for saving entity data.) Attributes of type information object are: recordtype type object describing the identified type entityparent Parent enbtity for entities of this type, or None if the type is not defined for the collection entityaltparent Alternative (site-wide) parent entity for built-in types, or None entityclass Python class object for entity entitymessages a table of message strings for diagnostics relating to operations on this type. and other values as initialized here. """ self.entitysite = site self.entitycoll = coll self.recordtype = None self.entityparent = None self.coll_id = coll.get_id() self.type_id = type_id self.permissions_map = None if type_id in TYPE_CLASS_MAP: self.recordtype = RecordType.load(coll, type_id, site) self.entityparent = coll self.entityaltparent = site self.entityclass = TYPE_CLASS_MAP[type_id] self.entitymessages = TYPE_MESSAGE_MAP[type_id] self.permissions_map = TYPE_PERMISSIONS_MAP[type_id] else: if RecordType.exists(coll, type_id, site): self.recordtype = RecordType.load(coll, type_id, site) if create_typedata and not RecordTypeData.exists(coll, type_id): self.entityparent = RecordTypeData.create(coll, type_id, {}) else: self.entityparent = RecordTypeData(coll, type_id) self.entityaltparent = None self.entityclass = EntityData self.entitymessages = ENTITY_MESSAGES self.permissions_map = ENTITY_PERMISSIONS if not self.recordtype: # .recordtype is used by views.displayinfo to locate the default # view and/or list id for examining records of a particular type. # # Also used in entityedit for getting @type URI/CURIE values. # # Used in render_utils to get link to type record log.warning("EntityTypeInfo.__init__: RecordType %s not found"%type_id) return
def create_type(self, type_id): # Create placeholder for testing t = RecordType.create( self.testcoll, type_id, recordtype_create_values(coll_id="testcoll", type_id="testtype")) return t
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