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 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 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 = entitydata_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, "") self.assertEqual( r['location'], TestHostUri + 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_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 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 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 _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 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 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 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_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 setUp(self): init_annalist_test_site() self.imagename = "test-image.jpg" self.imagepath = "%s/%s"%(TestBaseDir, self.imagename) self.imageuri = "file://"+self.imagepath self.testsite = Site(TestBaseUri, TestBaseDir) self.testcoll = Collection.create(self.testsite, "testcoll", collection_create_values("testcoll")) self.img_type = RecordType.create(self.testcoll, "img_type", recordtype_create_values("img_type")) self.img_data = RecordTypeData.create(self.testcoll, "img_type", {}) self.ref_type = RecordType.create(self.testcoll, "ref_type", recordtype_create_values("ref_type")) self.ref_data = RecordTypeData.create(self.testcoll, "ref_type", {}) # 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(self.testsite, "testcoll") self.coll1 = collection_values("coll1") self.testcoll_add = collection_create_values("testcoll") self.type1_add = recordtype_create_values("testcoll", "type1") self.type1 = recordtype_read_values("testcoll", "type1") self.type2_add = recordtype_create_values("testcoll", "type2") self.type2 = recordtype_read_values("testcoll", "type2") self.view1_add = recordview_create_values("testcoll", "view1") self.view1 = recordview_read_values("testcoll", "view1") self.view2_add = recordview_create_values("testcoll", "view2") self.view2 = recordview_read_values("testcoll", "view2") self.list1_add = recordlist_create_values("testcoll", "list1") self.list1 = recordlist_read_values("testcoll", "list1") self.list2_add = recordlist_create_values("testcoll", "list2") self.list2 = recordlist_read_values("testcoll", "list2") return
def setUp(self): init_annalist_test_site() init_annalist_test_coll() self.testsite = Site(TestBaseUri, TestBaseDir) self.testcoll = Collection(self.testsite, "testcoll") self.coll1 = collection_values("coll1") self.testcoll_add = collection_create_values("testcoll") self.type1_add = recordtype_create_values("testcoll", "type1") self.type1 = recordtype_read_values("testcoll", "type1") self.type2_add = recordtype_create_values("testcoll", "type2") self.type2 = recordtype_read_values("testcoll", "type2") self.view1_add = recordview_create_values("testcoll", "view1") self.view1 = recordview_read_values("testcoll", "view1") self.view2_add = recordview_create_values("testcoll", "view2") self.view2 = recordview_read_values("testcoll", "view2") self.list1_add = recordlist_create_values("testcoll", "list1") self.list1 = recordlist_read_values("testcoll", "list1") self.list2_add = recordlist_create_values("testcoll", "list2") self.list2 = recordlist_read_values("testcoll", "list2") 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): # 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("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 test_recordtype1_data(self): t = RecordType(self.testcoll, "type1", self.testsite) self.assertEqual(t.get_id(), "type1") self.assertEqual(t.get_type_id(), "_type") self.assertIn("/c/testcoll/_annalist_collection/types/type1/", t.get_url()) self.assertEqual(TestBaseUri + "/c/testcoll/d/_type/type1/", t.get_view_url()) t.set_values(recordtype_create_values(type_id="type1")) td = t.get_values() self.assertEqual(set(td.keys()), set(recordtype_value_keys())) v = recordtype_values(type_id="type1") self.assertDictionaryMatch(td, v) 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 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 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=.*&info_message=.*deletetype.*testcoll.*$") # Confirm deletion self.assertFalse(RecordType.exists(self.testcoll, "deletetype")) 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 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): 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 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 setUp(self): self.testsite = init_annalist_test_site() self.testcoll = Collection.create(self.testsite, "testcoll", collection_create_values("testcoll")) # Create test type self.testtypes = RecordType.create( self.testcoll, "testtype", recordtype_create_values(coll_id="testcoll", type_id="testtype", type_uri="test:testtype", supertype_uris=[])) # Create test type data parents 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() 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 test_post_delete_type(self): # Create empty type empty_type_values = recordtype_create_values("coll1", "type_empty") empty_type = self.coll1.add_type("type_empty", empty_type_values) # Now try to delete it form_data = ( { "typelist": "type_empty" , "type_delete": "Delete" }) r = self.client.post(self.edit_url, form_data) self.assertEqual(r.status_code, 200) self.assertEqual(r.reason_phrase, "OK") self.assertTemplateUsed(r, "annalist_confirm.html") # Check confirmation form content confirmed_action_uri = recordtype_edit_url("delete", "coll1") self.assertContains(r, '''<form method="POST" action="'''+TestBasePath+'''/confirm/">''', status_code=200) self.assertEqual(r.context['confirmed_action'], confirmed_action_uri) self.assertEqual(r.context['cancel_action'], self.edit_url) action_params = json.loads(r.context['action_params']) self.assertEqual(action_params['type_delete'], ["Delete"]) self.assertEqual(action_params['typelist'], ["type_empty"]) return
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 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_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 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_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
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)