Skip to content

Commit

Permalink
WORK IN PROGRESS: converting to store entity URL path without host - …
Browse files Browse the repository at this point in the history
…fix entitytgenericedit tests
  • Loading branch information
gklyne committed Oct 16, 2014
1 parent 9e0a3fd commit 8735d4d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
17 changes: 11 additions & 6 deletions src/annalist_root/annalist/tests/entity_testentitydata.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def entity_url(coll_id="testcoll", type_id="testtype", entity_id="entity_id"):
"""
URI for entity data; also view using default entity view
"""
if not valid_id(entity_id):
entity_id = "___"
return collection_entity_view_url(coll_id=coll_id, type_id=type_id, entity_id=entity_id)
#@@
# viewname = "AnnalistEntityAccessView"
Expand Down Expand Up @@ -146,7 +148,7 @@ def entitydata_create_values(entity_id, update="Entity", coll_id="testcoll", typ
"""
Data used when creating entity test data
"""
typeuri = hosturi + entity_url(coll_id, "_type", type_id)
typeuri = entity_url(coll_id, "_type", type_id)
types = [entitydata_type(type_id), typeuri]
# log.info('entitydata_create_values: types %r'%(types,))
return (
Expand All @@ -157,8 +159,8 @@ def entitydata_create_values(entity_id, update="Entity", coll_id="testcoll", typ
})

def entitydata_values(entity_id, update="Entity", coll_id="testcoll", type_id="testtype", hosturi=TestHostUri):
typeuri = hosturi + entity_url(coll_id, "_type", type_id)
dataurl = hosturi + entity_url(coll_id, type_id, entity_id)
typeuri = entity_url(coll_id, "_type", type_id)
dataurl = entity_url(coll_id, type_id, entity_id)
d = entitydata_create_values(
entity_id, update=update, coll_id=coll_id, type_id=type_id, hosturi=hosturi
).copy() #@@ copy needed here?
Expand All @@ -169,6 +171,7 @@ def entitydata_values(entity_id, update="Entity", coll_id="testcoll", type_id="t
, 'annal:url': dataurl
, 'annal:uri': dataurl
})
# log.info("entitydata_values %r"%(d,))
return d

def entitydata_context_data(
Expand Down Expand Up @@ -367,7 +370,7 @@ def entitydata_default_view_form_data(
action=None, cancel=None, update="Entity",
add_view_field=None, use_view=None,
new_view=None, new_field=None, new_type=None):
# log.info("entitydata_recordtype_view_form_data: entity_id %s"%(entity_id))
# log.info("entitydata_default_view_form_data: entity_id %s"%(entity_id))
form_data_dict = (
{ 'Entity_label': '%s data ... (%s/%s)'%(update, coll_id, type_id)
, 'Entity_comment': '%s description ... (%s/%s)'%(update, coll_id, type_id)
Expand Down Expand Up @@ -469,7 +472,7 @@ def entitydata_recordtype_view_context_data(
context_dict['fields'][0]['field_value'] = entity_id
context_dict['fields'][1]['field_value'] = '%s testcoll/testtype/%s'%(update,entity_id)
context_dict['fields'][2]['field_value'] = '%s coll testcoll, type testtype, entity %s'%(update,entity_id)
context_dict['fields'][3]['field_value'] = TestBaseUri + "/c/%s/d/%s/%s/"%("testcoll", "testtype", entity_id)
context_dict['fields'][3]['field_value'] = TestBasePath + "/c/%s/d/%s/%s/"%("testcoll", "testtype", entity_id)
context_dict['orig_id'] = entity_id
if orig_id:
context_dict['orig_id'] = orig_id
Expand All @@ -491,10 +494,12 @@ def entitydata_recordtype_view_form_data(
, 'continuation_url': entitydata_list_type_url(coll_id, orig_type or type_id)
})
if entity_id and type_id:
type_url = entity_url(coll_id=coll_id, type_id=type_id, entity_id=entity_id)
type_url = type_url.replace("___", entity_id) # Preserve bad type in form data
form_data_dict['entity_id'] = entity_id
form_data_dict['Type_label'] = '%s %s/%s/%s'%(update, coll_id, type_id, entity_id)
form_data_dict['Type_comment'] = '%s coll %s, type %s, entity %s'%(update, coll_id, type_id, entity_id)
form_data_dict['Type_uri'] = TestBaseUri + "/c/%s/d/%s/%s/"%(coll_id, type_id, entity_id)
form_data_dict['Type_uri'] = type_url
form_data_dict['orig_id'] = entity_id
if type_id:
form_data_dict['entity_type'] = type_id
Expand Down
24 changes: 15 additions & 9 deletions src/annalist_root/annalist/tests/test_entitygenericedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
site_dir, collection_dir,
continuation_url_param,
collection_edit_url,
collection_entity_view_url,
site_title,
render_select_options,
create_test_user
Expand Down Expand Up @@ -115,6 +116,7 @@ def _create_entity_data(self, entity_id, update="Entity"):

def _check_entity_data_values(self, entity_id, type_id="testtype", update="Entity", update_dict=None):
"Helper function checks content of form-updated record type entry with supplied entity_id"
# log.info("_check_entity_data_values: type_id %s, entity_id %s"%(type_id, entity_id))
typeinfo = EntityTypeInfo(self.testsite, self.testcoll, type_id)
self.assertTrue(typeinfo.entityclass.exists(typeinfo.entityparent, entity_id))
e = typeinfo.entityclass.load(typeinfo.entityparent, entity_id)
Expand Down Expand Up @@ -244,7 +246,7 @@ def test_get_form_rendering(self):
<div class="%(input_classes)s">
<input type="text" size="64" name="Type_uri"
placeholder="(URI)"
value="http://test.example.com/testsite/c/testcoll/d/testtype/00000001/"/>
value="%(default_entity_url)s"/>
</div>
</div>
</div>
Expand Down Expand Up @@ -317,11 +319,12 @@ def test_get_new(self):
self.assertEqual(r.status_code, 200)
self.assertEqual(r.reason_phrase, "OK")
# Test context
view_url = collection_entity_view_url(coll_id="testcoll", type_id="testtype", entity_id="00000001")
self.assertEqual(r.context['coll_id'], "testcoll")
self.assertEqual(r.context['type_id'], "testtype")
self.assertEqual(r.context['entity_id'], "00000001")
self.assertEqual(r.context['orig_id'], "00000001")
self.assertEqual(r.context['entity_url'], TestHostUri + entity_url(entity_id="00000001"))
self.assertEqual(r.context['entity_url'], view_url)
self.assertEqual(r.context['action'], "new")
self.assertEqual(r.context['continuation_url'], "/xyzzy/")
# Fields
Expand Down Expand Up @@ -390,7 +393,7 @@ def test_get_new(self):
self.assertEqual(r.context['fields'][3]['field_render_edit'], "field/annalist_edit_identifier.html")
self.assertEqual(r.context['fields'][3]['field_placement'].field, "small-12 columns")
self.assertEqual(r.context['fields'][3]['field_value_type'], "annal:Identifier")
self.assertEqual(r.context['fields'][3]['field_value'], TestBaseUri + "/c/testcoll/d/testtype/00000001/")
self.assertEqual(r.context['fields'][3]['field_value'], view_url)
self.assertEqual(r.context['fields'][3]['options'], self.no_options)
# 5th field - view id
view_id_help = (
Expand Down Expand Up @@ -432,11 +435,12 @@ def test_get_new_no_continuation(self):
self.assertEqual(r.status_code, 200)
self.assertEqual(r.reason_phrase, "OK")
# Test context
view_url = collection_entity_view_url(coll_id="testcoll", type_id="testtype", entity_id="00000001")
self.assertEqual(r.context['coll_id'], "testcoll")
self.assertEqual(r.context['type_id'], "testtype")
self.assertEqual(r.context['entity_id'], "00000001")
self.assertEqual(r.context['orig_id'], "00000001")
self.assertEqual(r.context['entity_url'], TestHostUri + entity_url(entity_id="00000001"))
self.assertEqual(r.context['entity_url'], view_url)
self.assertEqual(r.context['action'], "new")
self.assertEqual(r.context['continuation_url'], "")
return
Expand All @@ -449,11 +453,12 @@ def test_get_edit(self):
self.assertEqual(r.reason_phrase, "OK")
self.assertContains(r, "<h3>'testtype' data in collection 'testcoll'</h3>")
# Test context
view_url = collection_entity_view_url(coll_id="testcoll", type_id="testtype", entity_id="entity1")
self.assertEqual(r.context['coll_id'], "testcoll")
self.assertEqual(r.context['type_id'], "testtype")
self.assertEqual(r.context['entity_id'], "entity1")
self.assertEqual(r.context['orig_id'], "entity1")
self.assertEqual(r.context['entity_url'], TestHostUri + entity_url("testcoll", "testtype", "entity1"))
self.assertEqual(r.context['entity_url'], view_url)
self.assertEqual(r.context['action'], "edit")
self.assertEqual(r.context['continuation_url'], "/xyzzy/")
# Fields
Expand Down Expand Up @@ -526,7 +531,7 @@ def test_get_edit(self):
self.assertEqual(r.context['fields'][3]['field_render_edit'], "field/annalist_edit_identifier.html")
self.assertEqual(r.context['fields'][3]['field_placement'].field, "small-12 columns")
self.assertEqual(r.context['fields'][3]['field_value_type'], "annal:Identifier")
self.assertEqual(r.context['fields'][3]['field_value'], TestBaseUri + "/c/testcoll/d/testtype/entity1/")
self.assertEqual(r.context['fields'][3]['field_value'], view_url)
self.assertEqual(r.context['fields'][3]['options'], self.no_options)
# 5th field - view id
type_uri_help = (
Expand Down Expand Up @@ -708,6 +713,7 @@ def test_new_entity_default_type(self):
# Check new entity data created
self._check_entity_data_values("newentity", type_id="Default_type", update_dict=
{ '@type': ['annal:Default_type', 'annal:EntityData']
, 'annal:uri': f['Type_uri'] # because using Type_view
})
return

Expand All @@ -726,13 +732,13 @@ def create_new_type(self, coll_id, type_id):
self.assertTrue(RecordType.exists(self.testcoll, type_id))
return

def test_new_entity_new_typedata(self):
def test_new_entity_new_recorddata(self):
# Checks logic for creating an entity which may require creation of new recorddata
self.create_new_type("testcoll", "newtype")
# Create new entity
self.assertFalse(EntityData.exists(self.testdata, "newentity"))
f = entitydata_recordtype_view_form_data(entity_id="newentity", type_id="newtype", action="new")
u = entitydata_edit_url("new", "testcoll", "newtype", view_id="Type_view")
f = entitydata_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")
Expand Down
6 changes: 3 additions & 3 deletions src/annalist_root/annalist/views/entityedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ def save_entity(self,
else:
new_typeinfo = typeinfo
new_parent = orig_parent
# log.info("new_parent%r"%(new_parent))
# log.info("new_parent %r"%(new_parent.get_id()))

# Check existence of entity to save according to action performed
if (action in ["new", "copy"]) or entity_id_changed:
Expand All @@ -567,6 +567,7 @@ def save_entity(self,
# Note: form data is applied as update to original entity data so that
# values not in view are preserved.
entity_values = orig_entity.get_values() if orig_entity else {}
# log.info("orig entity_values %r"%(entity_values,))
if new_typeinfo.recordtype and ANNAL.CURIE.uri in new_typeinfo.recordtype:
typeuri = new_typeinfo.recordtype.get(ANNAL.CURIE.uri, None)
entity_values['@type'] = typeuri # NOTE: previous types not carried forward
Expand All @@ -578,8 +579,7 @@ def save_entity(self,
entity_values.update(entityvaluemap.map_form_data_to_values(form_data))
entity_values[ANNAL.CURIE.type_id] = entity_type_id
entity_values[ANNAL.CURIE.type] = new_typeinfo.entityclass._entitytype
# log.info("orig_entity values%r"%(entity_values))
# log.info("entity_values%r"%(entity_values))
# log.info("save entity_values%r"%(entity_values))

# If saving view description, ensure all property URIs are unique
#
Expand Down

0 comments on commit 8735d4d

Please sign in to comment.