本文整理汇总了Python中annalist.models.entitydata.EntityData类的典型用法代码示例。如果您正苦于以下问题:Python EntityData类的具体用法?Python EntityData怎么用?Python EntityData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EntityData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_post_edit_entity_new_type
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
示例2: test_post_edit_type_new_id
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
示例3: test_entitydata_type_id
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
示例4: test_entitydata2_data
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
示例5: test_entitydata_create_load
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
示例6: test_post_copy_entity_cancel
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
示例7: test_new_entity_new_type
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
示例8: _create_testentity
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
示例9: setUp
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="testuser", password="testpassword")
self.assertTrue(loggedin)
return
示例10: test_post_confirmed_remove_entity
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
示例11: _check_entity_data_values
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
示例12: entities
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
示例13: create_subproperty_field_view_entity
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
示例14: _create_entity_data
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
示例15: test_post_new_entity
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