def test_post_edit_view_enum_field_new(self):
     self._create_record_view("editview")
     self._check_record_view_values("editview")
     f = view_view_form_data(
         view_id="editview",
         orig_id="editview",
         action="edit",
         update="Updated RecordView",
         new_enum="View_fields__3__View_field_sel__new_edit")
     u = entitydata_edit_url("edit",
                             "testcoll",
                             "_view",
                             entity_id="editview",
                             view_id="View_view")
     r = self.client.post(u, f)
     r = self.client.post(u, f)
     self.assertEqual(r.status_code, 302)
     self.assertEqual(r.reason_phrase, "FOUND")
     self.assertEqual(r.content, "")
     # v = entitydata_edit_url("new", "testcoll", "_field", view_id="Field_view")
     v = entitydata_edit_url("edit",
                             "testcoll",
                             "_field",
                             "Entity_comment",
                             view_id="Field_view")
     w = entitydata_edit_url("edit",
                             "testcoll",
                             "_view",
                             entity_id="editview",
                             view_id="View_view")
     c = continuation_url_param(w)
     self.assertIn(TestHostUri + v, r['location'])
     self.assertIn(c, r['location'])
     self._check_record_view_values("editview", update="Updated RecordView")
     return
 def test_post_edit_view_enum_field_new(self):
     self._create_record_view("editview")
     self._check_record_view_values("editview")
     f = recordview_entity_view_form_data(
         view_id="editview", orig_id="editview", 
         action="edit", update="Updated RecordView",
         new_enum="View_fields__3__Field_id__new_edit"
         )
     u = entitydata_edit_url(
         "edit", "testcoll", "_view", 
         entity_id="editview", view_id="View_view"
         )
     r = self.client.post(u, f)
     r = self.client.post(u, f)
     self.assertEqual(r.status_code,   302)
     self.assertEqual(r.reason_phrase, "FOUND")
     self.assertEqual(r.content,       "")
     # v = entitydata_edit_url("new", "testcoll", "_field", view_id="Field_view")
     v = entitydata_edit_url("edit", "testcoll", "_field", "Entity_comment", view_id="Field_view")
     w = entitydata_edit_url(
         "edit", "testcoll", "_view", entity_id="editview", 
         view_id="View_view"
         )
     c = continuation_url_param(w)
     self.assertIn(TestHostUri+v, r['location'])
     self.assertIn(c, r['location'])
     self._check_record_view_values("editview", update="Updated RecordView")
     return
 def test_post_new_entity_new_type(self):
     self.assertFalse(EntityData.exists(self.testdata, "entitynewtype"))
     f = default_view_form_data(entity_id="entitynewtype",
                                action="new",
                                update="Updated entity",
                                new_type="New type")
     u = entitydata_edit_url("new",
                             "testcoll",
                             "testtype",
                             view_id="Default_view")
     r = self.client.post(u, f)
     self.assertEqual(r.status_code, 302)
     self.assertEqual(r.reason_phrase, "FOUND")
     self.assertEqual(r.content, "")
     v = TestHostUri + entitydata_edit_url(
         "new", "testcoll", "_type", view_id="Type_view")
     w = entitydata_edit_url("edit",
                             "testcoll",
                             "testtype",
                             entity_id="entitynewtype",
                             view_id="Default_view")
     c = continuation_url_param(w)
     self.assertIn(v, r['location'])
     self.assertIn(c, r['location'])
     self._check_entity_data_values("entitynewtype",
                                    update="Updated entity")
     return
 def test_post_default_form_use_view(self):
     self._create_entity_data("entityuseview")
     self.assertTrue(EntityData.exists(self.testdata, "entityuseview"))
     f = entitydata_default_view_form_data(
         entity_id="entityuseview",
         action="view",
         use_view="_view/Type_view",
     )
     f.pop('entity_id', None)
     u = entitydata_edit_url("view",
                             "testcoll",
                             "testtype",
                             "entityuseview",
                             view_id="Default_view")
     r = self.client.post(u, f)
     self.assertEqual(r.status_code, 302)
     self.assertEqual(r.reason_phrase, "FOUND")
     self.assertEqual(r.content, "")
     v = TestHostUri + entitydata_edit_url("view",
                                           "testcoll",
                                           "testtype",
                                           entity_id="entityuseview",
                                           view_id="Type_view")
     c = continuation_url_param("/testsite/c/testcoll/d/testtype/")
     self.assertIn(v, r['location'])
     self.assertIn(c, r['location'])
     self._check_entity_data_values("entityuseview")
     return
 def test_post_view_entity_edit(self):
     self._create_entity_data("entityview")
     f = entitydata_default_view_form_data(entity_id="entityview",
                                           action="view",
                                           edit="Edit")
     u = entitydata_edit_url("view",
                             "testcoll",
                             "testtype",
                             entity_id="entityview",
                             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, "")
     e = TestHostUri + entitydata_edit_url("edit",
                                           "testcoll",
                                           "testtype",
                                           entity_id="entityview",
                                           view_id="Default_view")
     l = continuation_url_param(
         entitydata_list_type_url("testcoll", "testtype"))
     c = continuation_url_param(u, prev_cont=l)
     self.assertIn(e, r['location'])
     self.assertIn(c, r['location'])
     # 'http://test.example.com/testsite/c/testcoll/v/Default_view/testtype/entityview/!edit
     #   ?continuation_url=/testsite/c/testcoll/v/Default_view/testtype/entityview/!view
     #   %3Fcontinuation_url=/testsite/c/testcoll/d/testtype/'
     return
 def test_post_view_entity_copy(self):
     self._create_entity_data("entityview")
     f = entitydata_default_view_form_data(entity_id="entityview",
                                           action="view",
                                           copy="Copy")
     u = entitydata_edit_url("view",
                             "testcoll",
                             "testtype",
                             entity_id="entityview",
                             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, "")
     e = TestHostUri + entitydata_edit_url("copy",
                                           "testcoll",
                                           "testtype",
                                           entity_id="entityview",
                                           view_id="Default_view")
     l = continuation_url_param(
         entitydata_list_type_url("testcoll", "testtype"))
     c = continuation_url_param(u, prev_cont=l)
     self.assertIn(e, r['location'])
     self.assertIn(c, r['location'])
     return
 def test_post_edit_entity_enum_type_new(self):
     self._create_entity_data("entitynewtype")
     e1 = self._check_entity_data_values("entitynewtype")
     f  = entitydata_default_view_form_data(
             entity_id="entitynewtype", action="edit", update="Updated entity", 
             new_enum="entity_type__new_edit"
             )
     u  = entitydata_edit_url(
         "edit", "testcoll", "testtype", entity_id="entitynewtype", 
         view_id="Default_view"
         )
     r = self.client.post(u, f)
     self.assertEqual(r.status_code,   302)
     self.assertEqual(r.reason_phrase, "FOUND")
     self.assertEqual(r.content,       "")
     # v = entitydata_edit_url("new", "testcoll", "_type", view_id="Type_view")
     v = entitydata_edit_url("edit", "testcoll", "_type", "testtype", view_id="Type_view")
     w = entitydata_edit_url(
         "edit", "testcoll", "testtype", entity_id="entitynewtype", 
         view_id="Default_view"
         )
     c = continuation_url_param(w)
     self.assertIn(TestHostUri+v, r['location'])
     self.assertIn(c, r['location'])
     self._check_entity_data_values("entitynewtype", update="Updated entity")
     return
 def test_post_edit_entity_enum_type_new(self):
     self._create_entity_data("entitynewtype")
     e1 = self._check_entity_data_values("entitynewtype")
     f = default_view_form_data(entity_id="entitynewtype",
                                action="edit",
                                update="Updated entity",
                                new_enum="entity_type__new_edit")
     u = entitydata_edit_url("edit",
                             "testcoll",
                             "testtype",
                             entity_id="entitynewtype",
                             view_id="Default_view")
     r = self.client.post(u, f)
     self.assertEqual(r.status_code, 302)
     self.assertEqual(r.reason_phrase, "FOUND")
     self.assertEqual(r.content, "")
     # v = entitydata_edit_url("new", "testcoll", "_type", view_id="Type_view")
     v = entitydata_edit_url("edit",
                             "testcoll",
                             "_type",
                             "testtype",
                             view_id="Type_view")
     w = entitydata_edit_url("edit",
                             "testcoll",
                             "testtype",
                             entity_id="entitynewtype",
                             view_id="Default_view")
     c = continuation_url_param(w)
     self.assertIn(TestHostUri + v, r['location'])
     self.assertIn(c, r['location'])
     self._check_entity_data_values("entitynewtype",
                                    update="Updated entity")
     return
 def test_reference_uploaded_resource(self):
     # Create uploaded resource (see previous test)
     with open(self.filepath) as fp:
         f = entitydata_default_view_form_data(type_id="testupltype",
                                               entity_id="test1",
                                               action="edit")
         f['upl_field'] = fp  # Upload file with submission
         u = entitydata_edit_url("view",
                                 "testcoll",
                                 "testupltype",
                                 entity_id="test1",
                                 view_id="testuplfileview")
         r = self.client.post(u, f)
     self.assertEqual(r.status_code, 302)
     self.assertEqual(r.reason_phrase, "FOUND")
     # Display resource with reference
     u = entitydata_edit_url("view",
                             "testcoll",
                             "testreftype",
                             entity_id="test1",
                             view_id="testrefview")
     r = self.client.get(u)
     self.assertEqual(r.status_code, 200)
     self.assertEqual(r.reason_phrase, "OK")
     # Check display context
     self.assertEqual(len(r.context['fields']), 4)
     f0 = context_view_field(r.context, 0, 0)
     self.assertEqual(f0.field_id, "Entity_id")
     self.assertEqual(f0.field_value, "test1")
     f1 = context_view_field(r.context, 1, 0)
     self.assertEqual(f1.field_id, "Entity_label")
     self.assertEqual(f1.field_value, "test_ref_entity test1 label")
     f2 = context_view_field(r.context, 2, 0)
     self.assertEqual(f2.field_id, "Entity_comment")
     self.assertEqual(f2.field_value, "test_ref_entity test1 comment")
     f3 = context_view_field(r.context, 3, 0)
     basepath = TestBasePath + "/c/testcoll/d/testupltype/"
     # print "\n*****\n"+repr(context_view_field(r.context, i, 0).target_value)+"\n*****\n"
     self.assertEqual(f3.field_id, "Test_reference")
     self.assertEqual(f3.field_value, "testupltype/test1")
     self.assertEqual(f3.field_value_link, basepath + "test1/")
     self.assertEqual(f3.target_value['upload_name'], "upl_field")
     self.assertEqual(f3.target_value['resource_name'], "upl_field.md")
     self.assertEqual(f3.target_value['resource_type'], "text/markdown")
     self.assertEqual(f3.target_value['uploaded_file'], "testdatafile.md")
     self.assertEqual(f3.target_value['uploaded_size'], 137)
     self.assertEqual(f3.target_value_link, basepath + "test1/upl_field.md")
     return
示例#10
0
    def test_image_edit_field(self):
        # Upload to an image view field
        with open(self.imagepath) as fp:
            f = entitydata_default_view_form_data(type_id="testimgtype", entity_id="test1", action="edit")
            f['img_field'] = fp     # Upload file with submission
            u = entitydata_edit_url("edit", "testcoll", "testimgtype", entity_id="test1", view_id="testimgview")
            r = self.client.post(u, f)
        self.assertEqual(r.status_code,   302)
        self.assertEqual(r.reason_phrase, "FOUND")

        # Read back and compare entity resource just created
        siteobj = open(self.imagepath, "rb")
        testobj = self.test_img_type_info.get_fileobj(
            "test1", "img_field", "annal:Image", "image/jpeg", "rb"
            )
        self.assertTrue(siteobj.read() == testobj.read(), "Referenced image != original")

        # Retrieve updated form
        r = self.client.get(u)
        # Test context
        # print "@@ "+context_field_map(r.context)
        self.assertEqual(len(r.context['fields']), 4)
        f0 = context_view_field(r.context, 0, 0)
        self.assertEqual(f0.field_id,     "Entity_id")
        self.assertEqual(f0.field_value,  "test1")
        f1 = context_view_field(r.context, 1, 0)
        self.assertEqual(f1.field_id,     "Entity_label")
        f2 = context_view_field(r.context, 2, 0)
        self.assertEqual(f2.field_id,     "Entity_comment")
        f3 = context_view_field(r.context, 3, 0)
        self.assertEqual(f3.field_id,     "Test_image")
        self.assertDictionaryMatch(f3.field_value, test_image_field_value())
        return
示例#11
0
 def test_upload_image_resource(self):
     # See https://docs.djangoproject.com/en/1.7/topics/testing/tools/#django.test.Client.post
     with open(self.imagepath) as fp:
         f = entitydata_default_view_form_data(type_id="testupltype", entity_id="test1", action="edit")
         f['upl_field'] = fp     # Upload file with submission
         u = entitydata_edit_url("edit", "testcoll", "testupltype", entity_id="test1", view_id="testuplimageview")
         r = self.client.post(u, f)
     self.assertEqual(r.status_code,   302)
     self.assertEqual(r.reason_phrase, "FOUND")
     # Retrieve updated form
     r = self.client.get(u)
     # Test context
     self.assertEqual(len(r.context['fields']), 4)
     f0 = context_view_field(r.context, 0, 0)
     self.assertEqual(f0.field_id,     "Entity_id")
     self.assertEqual(f0.field_value,  "test1")
     f1 = context_view_field(r.context, 1, 0)
     self.assertEqual(f1.field_id,     "Entity_label")
     f2 = context_view_field(r.context, 2, 0)
     self.assertEqual(f2.field_id,     "Entity_comment")
     f3 = context_view_field(r.context, 3, 0)
     self.assertEqual(f3.field_id,     "Test_upload_image")
     self.assertDictionaryMatch(f3.field_value, test_upload_image_field_value())
     # Read back and compare entity resource just created
     siteobj = open(self.imagepath, "rb")
     testobj = self.test_upl_type_info.get_fileobj(
         "test1", "upl_field", "annal:Image", "image/jpeg", "rb"
         )
     self.assertTrue(siteobj.read() == testobj.read(), "Uploaded image != original")
     # self.assertEqual(siteobj.read(), testobj.read())
     return
 def test_post_view_entity_copy(self):
     self._create_entity_data("entityview")
     f = entitydata_default_view_form_data(entity_id="entityview", action="view", copy="Copy")
     u = entitydata_edit_url("view", "testcoll", "testtype", entity_id="entityview", 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,       "")
     e = TestHostUri + entitydata_edit_url(
         "copy", "testcoll", "testtype", entity_id="entityview", view_id="Default_view"
         )
     l = continuation_url_param(entitydata_list_type_url("testcoll", "testtype"))
     c = continuation_url_param(u, prev_cont=l)
     self.assertIn(e, r['location'])
     self.assertIn(c, r['location'])
     return
示例#13
0
 def test_bad_user_permissions_form_rendering(self):
     # Test handling of permissions not stored in entity as a list of values
     create_user_permissions(self.testcoll, 
         "baduserperms",
         user_permissions="VIEW CREATE UPDATE DELETE"
         )
     u = entitydata_edit_url(
         "edit", "testcoll", layout.USER_TYPEID, "baduserperms", view_id="User_view"
         )
     with SuppressLogging(logging.WARNING):
         r = self.client.get(u)
     self.assertEqual(r.status_code,   200)
     self.assertEqual(r.reason_phrase, "OK")
     field_vals = default_fields(
         coll_id="testcoll", type_id=layout.USER_TYPEID, entity_id="baduserperms",
         tooltip=context_view_field(r.context, 4, 0)['field_help']
         )
     formrow5 = """
         <div class="small-12 columns" title="%(tooltip)s">
             <div class="row view-value-row">
                 <div class="%(label_classes)s">
                     <span>Permissions</span>
                 </div>
                 <div class="%(input_classes)s">
                     <input type="text" size="64" name="User_permissions" 
                            placeholder="(user permissions; e.g. &#39;VIEW CREATE UPDATE DELETE CONFIG&#39;)"
                            value="VIEW CREATE UPDATE DELETE"/>
                 </div>
             </div>
         </div>
         """%field_vals(width=12)
     # log.info(r.content)
     self.assertContains(r, formrow5, html=True)
     return
示例#14
0
 def test_get_new(self):
     u = entitydata_edit_url("new",
                             "testcoll",
                             "_type",
                             view_id="Type_view")
     r = self.client.get(u + "?continuation_url=/xyzzy/")
     self.assertEqual(r.status_code, 200)
     self.assertEqual(r.reason_phrase, "OK")
     # Test context
     type_url = collection_entity_view_url(coll_id="testcoll",
                                           type_id="_type",
                                           entity_id="00000001")
     self.assertEqual(r.context['coll_id'], "testcoll")
     self.assertEqual(r.context['type_id'], "_type")
     self.assertEqual(r.context['entity_id'], "00000001")
     self.assertEqual(r.context['orig_id'], "00000001")
     self.assertEqual(r.context['entity_url'], type_url)
     self.assertEqual(r.context['entity_uri'], None)
     self.assertEqual(r.context['action'], "new")
     self.assertEqual(r.context['continuation_url'], "/xyzzy/")
     # Fields
     self._check_context_fields(
         r,
         type_id="00000001",
         type_label=default_label("testcoll", "_type", "00000001"),
         type_help=default_comment("testcoll", "_type", "00000001"),
         type_uri="")
     return
 def test_get_view_form_no_login(self):
     self.client.logout()
     u = entitydata_edit_url("view", "testcoll", "testtype", entity_id="entity1", view_id="Type_view")
     r = self.client.get(u)
     self.assertEqual(r.status_code,   200)
     self.assertEqual(r.reason_phrase, "OK")
     return
示例#16
0
 def test_post_edit_vocab_invalid_id(self):
     self._create_record_vocab("editvocab")
     self._check_record_vocab_values("editvocab")
     # Form post with invalid ID
     f = vocab_view_form_data(vocab_id="!badvocab",
                              orig_id="editvocab",
                              action="edit",
                              update="Updated RecordVocab")
     u = entitydata_edit_url("edit",
                             "testcoll",
                             layout.VOCAB_TYPEID,
                             entity_id="editvocab",
                             view_id="Vocab_view")
     r = self.client.post(u, f)
     self.assertEqual(r.status_code, 200)
     self.assertEqual(r.reason_phrase, "OK")
     self.assertContains(r, "<h3>%s</h3>" % (message.RECORD_VOCAB_ID))
     # Test context
     self._check_context_fields(r,
                                action="edit",
                                vocab_id="!badvocab",
                                orig_vocab_id="editvocab",
                                update="Updated RecordVocab")
     # Check original data is unchanged
     self._check_record_vocab_values("editvocab")
     return
示例#17
0
 def test_user_permissions_form_rendering(self):
     # Test rendering of permissions from list in entity
     u = entitydata_edit_url("edit",
                             "testcoll",
                             layout.USER_TYPEID,
                             "testuser",
                             view_id="User_view")
     r = self.client.get(u)
     self.assertEqual(r.status_code, 200)
     self.assertEqual(r.reason_phrase, "OK")
     field_vals = default_fields(coll_id="testcoll",
                                 type_id=layout.USER_TYPEID,
                                 entity_id="testuser",
                                 tooltip=context_view_field(
                                     r.context, 4, 0)['field_help'])
     formrow5 = """
         <div class="small-12 columns" title="%(tooltip)s">
             <div class="row view-value-row">
                 <div class="%(label_classes)s">
                     <span>Permissions</span>
                 </div>
                 <div class="%(input_classes)s">
                     <input type="text" size="64" name="User_permissions" 
                            placeholder="(user permissions; e.g. &#39;VIEW CREATE UPDATE DELETE CONFIG&#39;)"
                            value="VIEW CREATE UPDATE DELETE CONFIG ADMIN"/>
                 </div>
             </div>
         </div>
         """ % field_vals(width=12)
     # log.info(r.content)
     # log.info
     # for i in range(len(r.context['fields'])):
     #     log.info("Field %d: %r"%(i, r.context['fields'][i]))
     self.assertContains(r, formrow5, html=True)
     return
示例#18
0
 def test_get_edit(self):
     u = entitydata_edit_url("edit",
                             "testcoll",
                             layout.VOCAB_TYPEID,
                             entity_id="annal",
                             view_id="Vocab_view")
     r = self.client.get(u)
     self.assertEqual(r.status_code, 200)
     self.assertEqual(r.reason_phrase, "OK")
     # Test context (values read from test data fixture)
     type_url = collection_entity_view_url(coll_id="testcoll",
                                           type_id=layout.VOCAB_TYPEID,
                                           entity_id="annal")
     self.assertEqual(r.context['coll_id'], "testcoll")
     self.assertEqual(r.context['type_id'], layout.VOCAB_TYPEID)
     self.assertEqual(r.context['entity_id'], "annal")
     self.assertEqual(r.context['orig_id'], "annal")
     self.assertEqual(r.context['entity_uri'],
                      "http://purl.org/annalist/2014/#")
     self.assertEqual(r.context['action'], "edit")
     self.assertEqual(r.context['continuation_url'], "")
     # Fields
     self._check_context_fields(
         r,
         action="edit",
         vocab_id="annal",
         orig_vocab_id="annal",
         vocab_label="Vocabulary namespace for Annalist-defined terms",
         vocab_uri="http://purl.org/annalist/2014/#",
         vocab_seealso=[
             "https://github.com/gklyne/annalist/blob/master/src/annalist_root/annalist/identifiers.py"
         ],
         continuation_url="")
     return
示例#19
0
 def test_post_copy_vocab(self):
     self.assertFalse(RecordVocab.exists(self.testcoll, "copyvocab"))
     f = vocab_view_form_data(
         vocab_id="copyvocab",
         orig_id="annal",
         orig_coll="_annalist_site",
         action="copy",
         update="RecordVocab",
         vocab_uri=" test:copyvocab "  # Tests space stripping
     )
     u = entitydata_edit_url("copy",
                             "testcoll",
                             layout.VOCAB_TYPEID,
                             entity_id="annal",
                             view_id="Vocab_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_vocab_values("copyvocab",
                                     update="RecordVocab",
                                     vocab_uri="test:copyvocab")
     return
示例#20
0
 def test_save_subproperty_field(self):
     self.create_subproperty_field_view_entity()
     # Post edit form response
     u = entitydata_edit_url("edit",
                             "testcoll",
                             "testtype",
                             entity_id="testentity",
                             view_id="testview")
     f = ({
         'entity_id': "testentity",
         'entity_type': "testtype",
         'orig_id': "testentity",
         'orig_type': "testtype",
         'Test_sup_field': "Updated subproperty value",
         'action': "edit",
         'save': "Save"
     })
     r = self.client.post(u, f)
     self.assertEqual(r.status_code, 302)
     self.assertEqual(r.reason_phrase, "FOUND")
     # Check entity exists,and compare data with expected
     typeinfo = EntityTypeInfo(self.testcoll, "testtype")
     self.assertTrue(
         typeinfo.entityclass.exists(typeinfo.entityparent, "testentity"))
     e = typeinfo.entityclass.load(typeinfo.entityparent, "testentity")
     self.assertEqual(e.get_id(), "testentity")
     # Check superproperty value remains undefined
     self.assertEqual(e.get_values().get("test:superprop_uri", "undefined"),
                      "undefined")
     # Check subproperty has been updated
     v = self.testentity_data.get_values().copy()
     v['test:subprop_uri'] = f['Test_sup_field']
     self.assertDictionaryMatch(e.get_values(), v)
     return
示例#21
0
 def test_get_new(self):
     u = entitydata_edit_url("new",
                             "testcoll",
                             layout.VOCAB_TYPEID,
                             view_id="Vocab_view")
     r = self.client.get(u + "?continuation_url=/xyzzy/")
     self.assertEqual(r.status_code, 200)
     self.assertEqual(r.reason_phrase, "OK")
     # Test context
     type_url = collection_entity_view_url(coll_id="testcoll",
                                           type_id=layout.VOCAB_TYPEID,
                                           entity_id="00000001")
     self.assertEqual(r.context['coll_id'], "testcoll")
     self.assertEqual(r.context['type_id'], layout.VOCAB_TYPEID)
     self.assertEqual(r.context['entity_id'], "00000001")
     self.assertEqual(r.context['orig_id'], None)
     self.assertEqual(r.context['entity_uri'], "")
     self.assertEqual(r.context['action'], "new")
     self.assertEqual(r.context['continuation_url'], "/xyzzy/")
     # Fields
     self._check_context_fields(r,
                                action="new",
                                vocab_id="00000001",
                                orig_vocab_id=None,
                                vocab_label="",
                                vocab_descr="",
                                vocab_uri="",
                                continuation_url="/xyzzy/")
     return
示例#22
0
 def test_save_field_alias_target(self):
     # Save BibEntry from Default_view: aliased values should be included
     u = entitydata_edit_url(
         "edit", "testcoll", "BibEntry_type", 
         entity_id="bibentity1", 
         view_id="Default_view"
         )
     f = (
         { 'entity_id':          "bibentity1"
         , 'entity_type':        "BibEntry_type"
         , 'orig_id':            "bibentity1"
         , 'orig_type':          "BibEntry_type"
         , 'Entity_label':       "Updated "+self.bibentity1_data['bib:title']
         , 'Entity_comment':     "Updated "+self.bibentity1_data['bib:note']
         , 'action':             "edit"
         , 'save':               "Save"
         })
     r = self.client.post(u, f)
     self.assertEqual(r.status_code,   302)
     self.assertEqual(r.reason_phrase, "FOUND")
     # Check entity exists, and compare data with expected
     typeinfo = EntityTypeInfo(self.testcoll, "BibEntry_type")
     self.assertTrue(typeinfo.entityclass.exists(typeinfo.entityparent, "bibentity1"))
     e = typeinfo.entityclass.load(typeinfo.entityparent, "bibentity1")
     self.assertEqual(e.get_id(), "bibentity1")
     v = self.bibentity1_data.copy()
     v[RDFS.CURIE.label]   = f['Entity_label']
     v[RDFS.CURIE.comment] = f['Entity_comment']
     self.assertDictionaryMatch(e.get_values(), v)
     return
 def test_dup_field_update(self):
     # Create entity with duplicate fields
     self._create_entity_data("entitydupfield")
     self._check_entity_data_values(
         "entitydupfield", type_id="testtype", update="Entity", 
         comment2="Comment field 2",
         comment3="Comment field 3"
         )
     # Post form data to update entity
     u = entitydata_edit_url(
         "edit", "testcoll", "testtype", 
         entity_id="entitydupfield",
         view_id="DupField_view"
         )
     f = entitydata_form_data(
         entity_id="entitydupfield",
         type_id="testtype",
         coll_id="testcoll", 
         action="edit", update="Updated Entity"
         )
     f = entitydata_form_add_field(f, "Entity_comment", 2, "Update comment 2")
     f = entitydata_form_add_field(f, "Entity_comment", 3, "Update comment 3")
     r = self.client.post(u, f)
     self.assertEqual(r.status_code,   302)
     self.assertEqual(r.reason_phrase, "FOUND")
     # Test resulting entity value
     self._check_entity_data_values(
         "entitydupfield", type_id="testtype", update="Updated Entity", 
         comment2="Update comment 2",
         comment3="Update comment 3"
         )
     return
示例#24
0
 def test_view_field_alias(self):
     # View BibEntry field in Default_view
     u = entitydata_edit_url(
         "edit", "testcoll", "BibEntry_type", 
         entity_id="bibentity1", 
         view_id="Default_view"
         )
     r = self.client.get(u)
     self.assertEqual(r.status_code,   200)
     self.assertEqual(r.reason_phrase, "OK")
     # Test context
     url = entity_url(coll_id="testcoll", type_id="BibEntry_type", entity_id="bibentity1")
     self.assertEqual(r.context['coll_id'],          "testcoll")
     self.assertEqual(r.context['type_id'],          "BibEntry_type")
     self.assertEqual(r.context['entity_id'],        "bibentity1")
     self.assertEqual(r.context['orig_id'],          "bibentity1")
     self.assertEqual(r.context['action'],           "edit")
     # Fields
     self.assertEqual(len(r.context['fields']), 3)
     # Check aliased label field
     f2 = context_view_field(r.context, 1, 0)
     self.assertEqual(f2['field_id'], 'Entity_label')
     self.assertEqual(f2['field_property_uri'], RDFS.CURIE.label)
     self.assertEqual(f2['field_value'], self.bibentity1_data['bib:title'])
     return
示例#25
0
 def test_post_edit_type_invalid_id(self):
     self._create_record_type("edittype")
     self._check_record_type_values("edittype")
     # Form post with invalid ID
     f = recordtype_entity_view_form_data(type_id="!badtype",
                                          orig_id="edittype",
                                          action="edit",
                                          update="Updated RecordType")
     u = entitydata_edit_url("edit",
                             "testcoll",
                             layout.TYPE_TYPEID,
                             entity_id="edittype",
                             view_id="Type_view")
     r = self.client.post(u, f)
     self.assertEqual(r.status_code, 200)
     self.assertEqual(r.reason_phrase, "OK")
     self.assertContains(r, "<h3>Problem with record type identifier</h3>")
     # Test context
     self._check_context_fields(
         r,
         action="edit",
         type_id="!badtype",
         orig_type_id="edittype",
         type_label=None,
         type_uri=None,
         type_supertype_uris=[],
     )
     # Check original data is unchanged
     self._check_record_type_values("edittype")
     return
示例#26
0
 def test_user_permissions_form_rendering(self):
     # Test rendering of permissions from list in entity
     u = entitydata_edit_url(
         "edit", "testcoll", layout.USER_TYPEID, "testuser", view_id="User_view"
         )
     r = self.client.get(u)
     self.assertEqual(r.status_code,   200)
     self.assertEqual(r.reason_phrase, "OK")
     field_vals = default_fields(
         coll_id="testcoll", type_id=layout.USER_TYPEID, entity_id="testuser",
         tooltip=context_view_field(r.context, 4, 0)['field_help']
         )
     formrow5 = """
         <div class="small-12 columns" title="%(tooltip)s">
             <div class="row view-value-row">
                 <div class="%(label_classes)s">
                     <span>Permissions</span>
                 </div>
                 <div class="%(input_classes)s">
                     <input type="text" size="64" name="User_permissions" 
                            placeholder="(user permissions; e.g. &#39;VIEW CREATE UPDATE DELETE CONFIG&#39;)"
                            value="VIEW CREATE UPDATE DELETE CONFIG ADMIN"/>
                 </div>
             </div>
         </div>
         """%field_vals(width=12)
     # log.info(r.content)
     # log.info
     # for i in range(len(r.context['fields'])):
     #     log.info("Field %d: %r"%(i, r.context['fields'][i]))
     self.assertContains(r, formrow5, html=True)
     return
示例#27
0
 def test_select_subtype1_fields(self):
     ref_view = self._create_ref_type_view(view_id="Test_ref_type1_view",
                                           record_type="test:testtypes")
     ref_field = self._create_ref_type_field(entity_type="test:testtype1")
     u = entitydata_edit_url("new",
                             "testcoll",
                             "ref_type",
                             view_id="Test_ref_type1_view")
     r = self.client.get(u)
     self.assertEqual(r.status_code, 200)
     self.assertEqual(r.reason_phrase, "OK")
     # Check render context
     self.assertEqual(r.context['coll_id'], "testcoll")
     self.assertEqual(r.context['type_id'], "ref_type")
     # Fields
     head_fields = context_list_head_fields(r.context)
     self.assertEqual(len(head_fields), 1)  # One row of 2 cols..
     self.assertEqual(len(head_fields[0]['row_field_descs']), 2)
     f0 = context_view_field(r.context, 0, 0)
     f1 = context_view_field(r.context, 0, 1)
     self.assertEqual(f0['field_id'], "Entity_id")
     self.assertEqual(f1['field_id'], "Test_ref_type_field")
     baselabel = "Entity testcoll/"
     baseuri = TestBasePath + "/c/testcoll/d/%s/"
     ref_options = ([
         FieldChoice(opt, label=baselabel + opt, link=baseuri % opt)
         for opt in ['testtype1/entity1']
     ])
     self.assertEqual(f1['options'], ref_options)
     return
示例#28
0
 def test_get_edit(self):
     u = entitydata_edit_url(
         "edit", "testcoll", layout.TYPE_TYPEID, entity_id="Default_type", view_id="Type_view"
         )
     r = self.client.get(u)
     self.assertEqual(r.status_code,   200)
     self.assertEqual(r.reason_phrase, "OK")
     # Test context (values read from test data fixture)
     type_url = collection_entity_view_url(
         coll_id="testcoll", type_id=layout.TYPE_TYPEID, entity_id="Default_type"
         )
     self.assertEqual(r.context['coll_id'],          "testcoll")
     self.assertEqual(r.context['type_id'],          layout.TYPE_TYPEID)
     self.assertEqual(r.context['entity_id'],        "Default_type")
     self.assertEqual(r.context['orig_id'],          "Default_type")
     self.assertEqual(r.context['entity_uri'],       "annal:Default_type")
     self.assertEqual(r.context['action'],           "edit")
     self.assertEqual(r.context['continuation_url'], "")
     # Fields
     self._check_context_fields(r, 
         action="edit",
         type_id="Default_type",
         type_label="Default record",
         type_uri="annal:Default_type", type_supertype_uris=""
         )
     return
示例#29
0
 def test_dup_field_display(self):
     # Create entity with duplicate fields
     self._create_entity_data("entitydupfield")
     self._check_entity_data_values(
         "entitydupfield", type_id="testtype", update="Entity", 
         comment2="Comment field 2",
         comment3="Comment field 3"
         )
     # Display entity in view with duplicate fields
     u = entitydata_edit_url(
         "edit", "testcoll", "testtype", 
         entity_id="entitydupfield",
         view_id="DupField_view"
         )
     r = self.client.get(u)
     self.assertEqual(r.status_code,   200)
     self.assertEqual(r.reason_phrase, "OK")
     # Check display context
     expect_context = dupfield_view_context_data(
         coll_id="testcoll", type_id="testtype", 
         entity_id="entitydupfield", orig_id=None,
         type_ref="testtype", type_choices=self.type_ids,
         entity_label="Entity testcoll/testtype/entitydupfield",
         entity_descr="Entity coll testcoll, type testtype, entity entitydupfield",
         entity_descr2="Comment field 2",
         entity_descr3="Comment field 3",
         record_type="/testsite/c/testcoll/d/_type/testtype/",
         action="edit", 
         update="Entity",
         continuation_url=""
         )
     self.assertEqual(len(r.context['fields']), 5)
     self.assertDictionaryMatch(context_bind_fields(r.context), expect_context)
示例#30
0
 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
示例#31
0
 def test_post_edit_type_invalid_id(self):
     self._create_record_type("edittype")
     self._check_record_type_values("edittype")
     # Form post with invalid ID
     f = recordtype_entity_view_form_data(
         type_id="!badtype", orig_id="edittype", action="edit", update="Updated RecordType"
         )
     u = entitydata_edit_url(
         "edit", "testcoll", layout.TYPE_TYPEID, entity_id="edittype", view_id="Type_view"
         )
     r = self.client.post(u, f)
     self.assertEqual(r.status_code,   200)
     self.assertEqual(r.reason_phrase, "OK")
     self.assertContains(r, "<h3>Problem with record type identifier</h3>")
     # Test context
     self._check_context_fields(r, 
         action="edit",
         type_id="!badtype", orig_type_id="edittype",
         type_label=None,
         type_uri=None,
         type_supertype_uris=[],
         )
     # Check original data is unchanged
     self._check_record_type_values("edittype")
     return
示例#32
0
 def test_save_field_alias_target(self):
     # Save BibEntry from Default_view: aliased values should be included
     u = entitydata_edit_url(
         "edit", "testcoll", "BibEntry_type", 
         entity_id="bibentity1", 
         view_id="Default_view"
         )
     f = (
         { 'entity_id':          "bibentity1"
         , 'entity_type':        "BibEntry_type"
         , 'orig_id':            "bibentity1"
         , 'orig_type':          "BibEntry_type"
         , 'Entity_label':       "Updated "+self.bibentity1_data['bib:title']
         , 'Entity_comment':     "Updated "+self.bibentity1_data['bib:note']
         , 'action':             "edit"
         , 'save':               "Save"
         })
     r = self.client.post(u, f)
     self.assertEqual(r.status_code,   302)
     self.assertEqual(r.reason_phrase, "FOUND")
     # Check entity exists,and compare data with expected
     typeinfo = EntityTypeInfo(self.testsite, self.testcoll, "BibEntry_type")
     self.assertTrue(typeinfo.entityclass.exists(typeinfo.entityparent, "bibentity1"))
     e = typeinfo.entityclass.load(typeinfo.entityparent, "bibentity1")
     self.assertEqual(e.get_id(), "bibentity1")
     v = self.bibentity1_data.copy()
     v[RDFS.CURIE.label]   = f['Entity_label']
     v[RDFS.CURIE.comment] = f['Entity_comment']
     self.assertDictionaryMatch(e.get_values(), v)
     return
示例#33
0
 def test_dup_field_update(self):
     # Create entity with duplicate fields
     self._create_entity_data("entitydupfield")
     self._check_entity_data_values(
         "entitydupfield", type_id="testtype", update="Entity", 
         comment2="Comment field 2",
         comment3="Comment field 3"
         )
     # Post form data to update entity
     u = entitydata_edit_url(
             "edit", "testcoll", "testtype", 
             entity_id="entitydupfield",
             view_id="DupField_view"
             )
     f = default_view_form_data(
             entity_id="entitydupfield",
             type_id="testtype",
             coll_id="testcoll", 
             action="edit", update="Updated Entity"
             )
     f = entitydata_form_add_field(f, "Entity_comment", 2, "Update comment 2")
     f = entitydata_form_add_field(f, "Entity_comment", 3, "Update comment 3")
     r = self.client.post(u, f)
     self.assertEqual(r.status_code,   302)
     self.assertEqual(r.reason_phrase, "FOUND")
     # Test resulting entity value
     self._check_entity_data_values(
         "entitydupfield", type_id="testtype", update="Updated Entity", 
         comment2="Update comment 2",
         comment3="Update comment 3"
         )
     return
 def test_get_view(self):
     # Note - this test uses Type_view to display en entity of type "testtype"
     u = entitydata_edit_url("edit",
                             "testcoll",
                             "testtype",
                             entity_id="entity1",
                             view_id="Type_view")
     r = self.client.get(u)
     self.assertEqual(r.status_code, 200)
     self.assertEqual(r.reason_phrase, "OK")
     check_type_view_context_fields(
         self,
         r,
         action="edit",
         entity_id="entity1",
         orig_entity_id=None,
         type_id="testtype",
         type_label="Entity testcoll/testtype/entity1",
         type_comment="Entity coll testcoll, type testtype, entity entity1",
         type_uri="",
         type_supertype_uris=[],
         type_view="Default_view",
         type_view_options=self.no_view_id + self.view_options,
         type_list="Default_list",
         type_list_options=self.no_list_id + self.list_options,
         type_aliases=[],
     )
     return
示例#35
0
 def test_view_field_alias(self):
     # View BibEntry field in Default_view
     u = entitydata_edit_url(
         "edit", "testcoll", "BibEntry_type", 
         entity_id="bibentity1", 
         view_id="Default_view"
         )
     r = self.client.get(u)
     self.assertEqual(r.status_code,   200)
     self.assertEqual(r.reason_phrase, "OK")
     self.assertContains(r, "<title>Collection testcoll</title>")
     # Test context
     url = entity_url(coll_id="testcoll", type_id="BibEntry_type", entity_id="bibentity1")
     self.assertEqual(r.context['coll_id'],          "testcoll")
     self.assertEqual(r.context['type_id'],          "BibEntry_type")
     self.assertEqual(r.context['entity_id'],        "bibentity1")
     self.assertEqual(r.context['orig_id'],          "bibentity1")
     self.assertEqual(r.context['entity_url'],       url)
     self.assertEqual(r.context['action'],           "edit")
     # Fields
     self.assertEqual(len(r.context['fields']), 4)        
     # Check aliased label field
     self.assertEqual(r.context['fields'][2]['field_id'], 'Entity_label')
     self.assertEqual(r.context['fields'][2]['field_property_uri'], RDFS.CURIE.label)
     self.assertEqual(r.context['fields'][2]['field_value'], self.bibentity1_data['bib:title'])
     return
 def test_select_subtype1_fields(self):
     ref_view  = self._create_ref_type_view(view_id="Test_ref_type1_view", record_type="test:testtypes")
     ref_field = self._create_ref_type_field(entity_type="test:testtype1")
     u = entitydata_edit_url(
         "new", "testcoll", "ref_type", view_id="Test_ref_type1_view"
         )
     r = self.client.get(u)
     self.assertEqual(r.status_code,   200)
     self.assertEqual(r.reason_phrase, "OK")
     # Check render context
     self.assertEqual(r.context['coll_id'],          "testcoll")
     self.assertEqual(r.context['type_id'],          "ref_type")
     # Fields
     head_fields = context_list_head_fields(r.context)
     self.assertEqual(len(head_fields), 1)       # One row of 2 cols..
     self.assertEqual(len(head_fields[0]['row_field_descs']), 2)
     f0 = context_view_field(r.context, 0, 0)
     f1 = context_view_field(r.context, 0, 1)
     self.assertEqual(f0['field_id'], "Entity_id")
     self.assertEqual(f1['field_id'], "Test_ref_type_field")
     baselabel = "Entity testcoll/"
     baseuri   = TestBasePath+"/c/testcoll/d/%s/"
     ref_options = (
         [ FieldChoice(opt, label=baselabel+opt, link=baseuri%opt)
           for opt in ['testtype1/entity1']
         ])
     self.assertEqual(f1['options'], ref_options)
     return
示例#37
0
 def test_get_edit(self):
     u = entitydata_edit_url("edit",
                             "testcoll",
                             "_type",
                             entity_id="Default_type",
                             view_id="Type_view")
     r = self.client.get(u)
     self.assertEqual(r.status_code, 200)
     self.assertEqual(r.reason_phrase, "OK")
     # Test context (values read from test data fixture)
     type_url = collection_entity_view_url(coll_id="testcoll",
                                           type_id="_type",
                                           entity_id="Default_type")
     self.assertEqual(r.context['coll_id'], "testcoll")
     self.assertEqual(r.context['type_id'], "_type")
     self.assertEqual(r.context['entity_id'], "Default_type")
     self.assertEqual(r.context['orig_id'], "Default_type")
     self.assertEqual(r.context['entity_url'], type_url)
     self.assertEqual(r.context['entity_uri'], "annal:Default_type")
     self.assertEqual(r.context['action'], "edit")
     self.assertEqual(r.context['continuation_url'], "")
     # Fields
     self._check_context_fields(
         r,
         type_id="Default_type",
         type_label="Default record type",
         type_help=
         "Default record type, applied when no type is specified when creating a record.",
         type_uri="annal:Default_type")
     return
示例#38
0
 def test_bad_user_permissions_form_rendering(self):
     # Test handling of permissions not stored in entity as a list of values
     create_user_permissions(self.testcoll,
                             "baduserperms",
                             user_permissions="VIEW CREATE UPDATE DELETE")
     u = entitydata_edit_url("edit",
                             "testcoll",
                             "_user",
                             "baduserperms",
                             view_id="User_view")
     with SuppressLogging(logging.WARNING):
         r = self.client.get(u)
     self.assertEqual(r.status_code, 200)
     self.assertEqual(r.reason_phrase, "OK")
     field_vals = default_fields(coll_id="testcoll",
                                 type_id="_user",
                                 entity_id="baduserperms")
     formrow5 = """
         <div class="small-12 columns">
             <div class="row">
                 <div class="%(label_classes)s">
                     <p>Permissions</p>
                 </div>
                 <div class="%(input_classes)s">
                     <input type="text" size="64" name="User_permissions" 
                            placeholder="(user permissions; e.g. &#39;VIEW CREATE UPDATE DELETE&#39;)"
                            value="VIEW CREATE UPDATE DELETE"/>
                 </div>
             </div>
         </div>
         """ % field_vals(width=12)
     # log.info(r.content)
     self.assertContains(r, formrow5, html=True)
     return
示例#39
0
 def test_post_copy_user(self):
     # The main purpose of this test is to check that user permissions are saved properly
     self.assertFalse(AnnalistUser.exists(self.testcoll, "copyuser"))
     f = annalistuser_view_form_data(
         action="copy",
         orig_id="_default_user_perms",
         user_id="copyuser",
         user_name="User copyuser",
         user_uri="mailto:[email protected]",
         user_permissions="VIEW CREATE UPDATE DELETE")
     u = entitydata_edit_url("copy",
                             "testcoll",
                             "_user",
                             entity_id="_default_user_perms",
                             view_id="User_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.assertTrue(AnnalistUser.exists(self.testcoll, "copyuser"))
     self._check_annalist_user_values(
         "copyuser", ["VIEW", "CREATE", "UPDATE", "DELETE"])
     return
示例#40
0
 def test_post_edit_entity_invalid_id(self):
     self._create_entity_data("edittype")
     self._check_entity_data_values("edittype")
     # Form post with ID malformed
     f = default_view_form_data(entity_id="!badentity",
                                orig_id="edittype",
                                action="edit")
     u = entitydata_edit_url("edit",
                             "testcoll",
                             "testtype",
                             entity_id="edittype")
     r = self.client.post(u, f)
     self.assertEqual(r.status_code, 200)
     self.assertEqual(r.reason_phrase, "OK")
     self.assertContains(r, "<h3>Problem with entity identifier</h3>")
     # Test context for re-rendered form
     expect_context = default_view_context_data(
         entity_id="!badentity",
         orig_id="edittype",
         action="edit",
         type_ref="_type/testtype",
         type_choices=self.type_ids,
         record_type="/testsite/c/testcoll/d/_type/testtype/")
     self.assertDictionaryMatch(context_bind_fields(r.context),
                                expect_context)
     # Check stored entity is unchanged
     self._check_entity_data_values("edittype")
     return
示例#41
0
 def test_user_permissions_form_rendering(self):
     # Test rendering of permissions from list in entity
     u = entitydata_edit_url("edit",
                             "testcoll",
                             "_user",
                             "testuser",
                             view_id="User_view")
     r = self.client.get(u)
     self.assertEqual(r.status_code, 200)
     self.assertEqual(r.reason_phrase, "OK")
     field_vals = default_fields(coll_id="testcoll",
                                 type_id="_user",
                                 entity_id="testuser")
     formrow5 = """
         <div class="small-12 columns">
             <div class="row">
                 <div class="%(label_classes)s">
                     <p>Permissions</p>
                 </div>
                 <div class="%(input_classes)s">
                     <input type="text" size="64" name="User_permissions" 
                            placeholder="(user permissions; e.g. &#39;VIEW CREATE UPDATE DELETE&#39;)"
                            value="VIEW CREATE UPDATE DELETE CONFIG ADMIN"/>
                 </div>
             </div>
         </div>
         """ % field_vals(width=12)
     # log.info(r.content)
     self.assertContains(r, formrow5, html=True)
     return
    def test_image_rename(self):
        # This test that entity renaming also copies over an attachment

        # Upload image
        self.test_image_edit_field()

        # Rename entity
        f = entitydata_default_view_form_data(type_id="testimgtype",
                                              orig_id="test1",
                                              entity_id="test_new",
                                              action="edit")
        u = entitydata_edit_url("edit",
                                "testcoll",
                                "testimgtype",
                                entity_id="test1",
                                view_id="testimgview")
        r = self.client.post(u, f)
        self.assertEqual(r.status_code, 302)
        self.assertEqual(r.reason_phrase, "FOUND")

        # Read back and compare renamed entity resource
        siteobj = open(self.imagepath, "rb")
        testobj = self.test_img_type_info.get_fileobj("test_new", "img_field",
                                                      "annal:Image",
                                                      "image/jpeg", "rb")
        self.assertTrue(siteobj.read() == testobj.read(),
                        "Renamed entity image != original")
        return
示例#43
0
 def test_get_edit(self):
     u = entitydata_edit_url("edit",
                             "testcoll",
                             "testtype",
                             entity_id="entity1")
     r = self.client.get(u + "?continuation_url=/xyzzy/")
     self.assertEqual(r.status_code, 200)
     self.assertEqual(r.reason_phrase, "OK")
     # log.info(r.content)
     self.assertContains(
         r,
         "<title>Entity testcoll/testtype/entity1 - Default record view - Collection testcoll</title>"
     )
     # Test context
     expect_context = default_view_context_data(
         coll_id="testcoll",
         type_id="testtype",
         entity_id="entity1",
         type_ref="testtype",
         type_choices=self.type_ids,
         entity_label="Entity testcoll/testtype/entity1",
         entity_descr="Entity coll testcoll, type testtype, entity entity1",
         action="edit",
         update="Entity",
         continuation_url="/xyzzy/")
     self.assertEqual(len(r.context['fields']), 3)  # 4 fields over 3 rows
     self.assertDictionaryMatch(context_bind_fields(r.context),
                                expect_context)
     return
示例#44
0
 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 _no_test_test_select_view_subtype_fields(self):
     # @@INCOMPLETE:  this was an attempt to check field selction from the view context,
     #                but abandoned to to complexity of reconstructing bound fields.
     #                NOTE: sitedata tests use Beautifulsoup representation of rendered
     #                page for these tests
     ref_view  = self._create_ref_type_view()
     ref_field = self._create_ref_type_field()
     u = entitydata_edit_url(
         "edit", "testcoll", "_view", "Test_ref_type_view", view_id="View_view"
         )
     r = self.client.get(u)
     self.assertEqual(r.status_code,   200)
     self.assertEqual(r.reason_phrase, "OK")
     # Check render context
     self.assertEqual(r.context['coll_id'],          "testcoll")
     self.assertEqual(r.context['type_id'],          "_view")
     # Fields
     self.assertEqual(len(r.context['fields']), 6)
     self.assertEqual(r.context['fields'][0]['field_id'], "View_id")
     self.assertEqual(r.context['fields'][1]['field_id'], "View_label")
     self.assertEqual(r.context['fields'][2]['field_id'], "View_comment")
     self.assertEqual(r.context['fields'][3]['field_id'], "View_target_type")
     self.assertEqual(r.context['fields'][4]['field_id'], "View_edit_view")
     self.assertEqual(r.context['fields'][5]['field_id'], "View_fields")
     print repr(r.context['fields'][5])
     baselabel = "Entity testcoll/"
     baseuri   = TestBasePath+"/c/testcoll/d/%s/"
     ref_options = (
         [ FieldChoice(opt, label=baselabel+opt, link=baseuri%opt)
           for opt in ['testtype1/entity1', 'testtype2/entity2', 'testtypes/entitys']
         ])
     self.assertEqual(r.context['fields'][5]['options'], ref_options)
     return
 def test_get_view_no_collection(self):
     u = entitydata_edit_url("view", "no_collection", "_field", entity_id="entity1", view_id="Type_view")
     r = self.client.get(u)
     self.assertEqual(r.status_code,   404)
     self.assertEqual(r.reason_phrase, "Not found")
     self.assertContains(r, "Collection no_collection does not exist", status_code=404)
     return
示例#47
0
 def test_post_edit_type_invalid_id(self):
     self._create_record_type("edittype")
     self._check_record_type_values("edittype")
     # Form post with invalid ID
     f = recordtype_entity_view_form_data(type_id="!badtype",
                                          orig_id="edittype",
                                          action="edit",
                                          update="Updated RecordType")
     u = entitydata_edit_url("edit",
                             "testcoll",
                             "_type",
                             entity_id="edittype",
                             view_id="Type_view")
     r = self.client.post(u, f)
     self.assertEqual(r.status_code, 200)
     self.assertEqual(r.reason_phrase, "OK")
     self.assertContains(r, "<h3>Problem with record type identifier</h3>")
     # Test context
     expect_context = recordtype_entity_view_context_data(
         type_id="!badtype",
         orig_id="edittype",
         action="edit",
         update="Updated RecordType")
     self.assertDictionaryMatch(r.context, expect_context)
     # Check original data is unchanged
     self._check_record_type_values("edittype")
     return
 def test_get_view_no_view(self):
     u = entitydata_edit_url("edit", "testcoll", "_field", entity_id="entity1", view_id="no_view")
     with SuppressLogging(logging.WARNING):
         r = self.client.get(u)
     self.assertEqual(r.status_code,   404)
     self.assertEqual(r.reason_phrase, "Not found")
     self.assertContains(r, "Record view no_view in collection testcoll does not exist", status_code=404)
     return
示例#49
0
    def test_reference_uploaded_image(self):
        self.test_upload_image_resource()

        # Display resource with image reference
        u = entitydata_edit_url("view", "testcoll", "testreftype", entity_id="test1", view_id="testimgrefview")
        r = self.client.get(u)
        self.assertEqual(r.status_code,   200)
        self.assertEqual(r.reason_phrase, "OK")
        # Check display context
        self.assertEqual(len(r.context['fields']), 4)
        f0 = context_view_field(r.context, 0, 0)
        self.assertEqual(f0.field_id,     "Entity_id")
        self.assertEqual(f0.field_value,  "test1")
        f1 = context_view_field(r.context, 1, 0)
        self.assertEqual(f1.field_id,     "Entity_label")
        self.assertEqual(f1.field_value,  "test_ref_entity test1 label")
        f2 = context_view_field(r.context, 2, 0)
        self.assertEqual(f2.field_id,     "Entity_comment")
        self.assertEqual(f2.field_value,  "test_ref_entity test1 comment")
        f3 = context_view_field(r.context, 3, 0)
        basepath = TestBasePath + "/c/testcoll/d/testupltype/"
        # print "\n*****\n"+repr(context_view_field(r.context, i, 0).target_value)+"\n*****\n"
        self.assertEqual(f3.field_id,     "Test_image_ref")
        self.assertEqual(f3.field_value,        "testupltype/test1")
        self.assertEqual(f3.field_value_link,   basepath+"test1/")
        self.assertEqual(f3.target_value['upload_name'],   "upl_field")
        self.assertEqual(f3.target_value['resource_name'], "upl_field.jpg")
        self.assertEqual(f3.target_value['resource_type'], "image/jpeg")
        self.assertEqual(f3.target_value['uploaded_file'], "test-image.jpg")
        self.assertEqual(f3.target_value['uploaded_size'], 1547926)
        self.assertEqual(f3.target_value_link,  basepath+"test1/upl_field.jpg")
        # Check for rendered image link
        # log.info(r.content)
        field_details = (
            { "basepath":   TestBasePath
            , "coll_id":    "testcoll"
            , "type_id":    "testupltype"
            , "entity_id":  "test1"
            , "field_id":   "upl_field"
            , "tooltip":    ""
            })
        img_element = """
            <div class="small-12 columns" %(tooltip)s>
              <div class="row view-value-row">
                <div class="view-label small-12 medium-2 columns">
                  <span>test_image_ref_field label</span>
                </div>
                <div class="view-value small-12 medium-10 columns">
                  <a href="%(basepath)s/c/%(coll_id)s/d/%(type_id)s/%(entity_id)s/%(field_id)s.jpg" target="_blank">
                    <img src="%(basepath)s/c/%(coll_id)s/d/%(type_id)s/%(entity_id)s/%(field_id)s.jpg"
                         alt="Image at '%(basepath)s/c/%(coll_id)s/d/%(type_id)s/%(entity_id)s/%(field_id)s.jpg'" />
                  </a>
                </div>
              </div>
            </div>
            """%field_details
        self.assertContains(r, img_element, html=True)
        return
 def test_post_new_entity_new_type(self):
     self.assertFalse(EntityData.exists(self.testdata, "entitynewtype"))
     f = entitydata_default_view_form_data(
         entity_id="entitynewtype", action="new", update="Updated entity", 
         new_type="New type"
         )
     u = entitydata_edit_url("new", "testcoll", "testtype", view_id="Default_view")
     r = self.client.post(u, f)
     self.assertEqual(r.status_code,   302)
     self.assertEqual(r.reason_phrase, "FOUND")
     self.assertEqual(r.content,       "")
     v = TestHostUri + entitydata_edit_url("new", "testcoll", "_type", view_id="Type_view")
     w = entitydata_edit_url("edit", "testcoll", "testtype", entity_id="entitynewtype", view_id="Default_view")
     c = continuation_url_param(w)
     self.assertIn(v, r['location'])
     self.assertIn(c, r['location'])
     self._check_entity_data_values("entitynewtype", update="Updated entity")
     return
 def test_post_view_entity_edit(self):
     self._create_entity_data("entityview")
     f = entitydata_default_view_form_data(entity_id="entityview", action="view", edit="Edit")
     u = entitydata_edit_url("view", "testcoll", "testtype", entity_id="entityview", 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,       "")
     e = TestHostUri + entitydata_edit_url(
         "edit", "testcoll", "testtype", entity_id="entityview", view_id="Default_view"
         )
     l = continuation_url_param(entitydata_list_type_url("testcoll", "testtype"))
     c = continuation_url_param(u, prev_cont=l)
     self.assertIn(e, r['location'])
     self.assertIn(c, r['location'])
     # 'http://test.example.com/testsite/c/testcoll/v/Default_view/testtype/entityview/!edit
     #   ?continuation_url=/testsite/c/testcoll/v/Default_view/testtype/entityview/!view
     #   %3Fcontinuation_url=/testsite/c/testcoll/d/testtype/'
     return
示例#52
0
 def test_reference_uploaded_resource(self):
     # Create uploaded resource (see previous test)
     with open(self.filepath) as fp:
         f = entitydata_default_view_form_data(type_id="testupltype", entity_id="test1", action="edit")
         f['upl_field'] = fp     # Upload file with submission
         u = entitydata_edit_url(
             "view", "testcoll", "testupltype", entity_id="test1", view_id="testuplfileview"
             )
         r = self.client.post(u, f)
     self.assertEqual(r.status_code,   302)
     self.assertEqual(r.reason_phrase, "FOUND")
     # Display resource with reference
     u = entitydata_edit_url(
         "view", "testcoll", "testreftype", entity_id="test1", view_id="testrefview"
         )
     r = self.client.get(u)
     self.assertEqual(r.status_code,   200)
     self.assertEqual(r.reason_phrase, "OK")
     # Check display context
     self.assertEqual(len(r.context['fields']), 4)
     f0 = context_view_field(r.context, 0, 0)
     self.assertEqual(f0.field_id,     "Entity_id")
     self.assertEqual(f0.field_value,  "test1")
     f1 = context_view_field(r.context, 1, 0)
     self.assertEqual(f1.field_id,     "Entity_label")
     self.assertEqual(f1.field_value,  "test_ref_entity test1 label")
     f2 = context_view_field(r.context, 2, 0)
     self.assertEqual(f2.field_id,     "Entity_comment")
     self.assertEqual(f2.field_value,  "test_ref_entity test1 comment")
     f3 = context_view_field(r.context, 3, 0)
     basepath = TestBasePath + "/c/testcoll/d/testupltype/"
     # print "\n*****\n"+repr(context_view_field(r.context, i, 0).target_value)+"\n*****\n"
     self.assertEqual(f3.field_id,     "Test_reference")
     self.assertEqual(f3.field_value,        "testupltype/test1")
     self.assertEqual(f3.field_value_link,   basepath+"test1/")
     self.assertEqual(f3.target_value['upload_name'],   "upl_field")
     self.assertEqual(f3.target_value['resource_name'], "upl_field.md")
     self.assertEqual(f3.target_value['resource_type'], "text/markdown")
     self.assertEqual(f3.target_value['uploaded_file'], "testdatafile.md")
     self.assertEqual(f3.target_value['uploaded_size'], 137)
     self.assertEqual(f3.target_value_link,  basepath+"test1/upl_field.md")
     return
 def test_get_view_no_entity(self):
     u = entitydata_edit_url("view", "testcoll", "testtype", entity_id="entitynone", view_id="Type_view")
     r = self.client.get(u+"?continuation_url=/xyzzy/")
     self.assertEqual(r.status_code,   404)
     self.assertEqual(r.reason_phrase, "Not found")
     self.assertContains(r, "<title>Annalist error</title>", status_code=404)
     self.assertContains(r, "<h3>404: Not found</h3>", status_code=404)
     # log.debug(r.content)
     err_label = error_label("testcoll", "testtype", "entitynone")
     self.assertContains(r, "<p>Entity %s does not exist</p>"%err_label, status_code=404)
     return
示例#54
0
    def test_reference_image(self):

        # Display resource with image reference
        u = entitydata_edit_url("view", "testcoll", "testreftype", entity_id="test1", view_id="testrefview")
        r = self.client.get(u)
        self.assertEqual(r.status_code,   200)
        self.assertEqual(r.reason_phrase, "OK")
        # Check display context
        self.assertEqual(len(r.context['fields']), 4)
        f0 = context_view_field(r.context, 0, 0)
        self.assertEqual(f0.field_id,     "Entity_id")
        self.assertEqual(f0.field_value,  "test1")
        f1 = context_view_field(r.context, 1, 0)
        self.assertEqual(f1.field_id,     "Entity_label")
        self.assertEqual(f1.field_value,  "test_ref_image label")
        f2 = context_view_field(r.context, 2, 0)
        self.assertEqual(f2.field_id,     "Entity_comment")
        self.assertEqual(f2.field_value,  "test_ref_image comment")
        f3 = context_view_field(r.context, 3, 0)
        basepath = TestBasePath + "/c/testcoll/d/testreftype/"
        # print "\n*****\n"+repr(f3)+"\n*****\n"
        self.assertEqual(f3.field_id,           "Test_image_ref")
        self.assertEqual(f3.field_value,        self.imageuri)
        self.assertEqual(f3.field_value_link,   None)
        self.assertEqual(f3.target_value,       self.imageuri)
        self.assertEqual(f3.target_value_link,  self.imageuri)
        # Check for rendered image link
        # log.info(r.content)
        field_details = (
            { "basepath":   TestBasePath
            , "coll_id":    "testcoll"
            , "type_id":    "testupltype"
            , "entity_id":  "test1"
            , "image_uri":  self.imageuri
            , "field_id":   "ref_image"
            , "tooltip":    "" # 'title="%s"'%r.context['fields'][i].field_help
            })
        img_element = """
            <div class="small-12 columns" %(tooltip)s>
              <div class="row view-value-row">
                <div class="view-label small-12 medium-2 columns">
                  <span>test_image_ref_field label</span>
                </div>
                <div class="view-value small-12 medium-10 columns">
                  <a href="%(image_uri)s" target="_blank">
                    <img src="%(image_uri)s"
                         alt="Image at '%(image_uri)s'" />
                  </a>
                </div>
              </div>
            </div>
            """%field_details
        self.assertContains(r, img_element, html=True)
        return
 def test_post_view_entity_close(self):
     self._create_entity_data("entityview")
     f = entitydata_default_view_form_data(entity_id="entityview", action="view", close="Close")
     u = entitydata_edit_url("view", "testcoll", "testtype", entity_id="entityview", view_id="Default_view")
     r = self.client.post(u, f)
     self.assertEqual(r.status_code,   302)
     self.assertEqual(r.reason_phrase, "FOUND")
     self.assertEqual(r.content,       "")
     self.assertEqual(r['location'], TestHostUri + entitydata_list_type_url("testcoll", "testtype"))
     self._check_entity_data_values("entityview")
     return
 def test_post_new_entity_enum_type_new_no_login(self):
     self.client.logout()
     f = entitydata_default_view_form_data(
             entity_id="entitynewtype", action="new", update="Updated entity", 
             new_enum="entity_type__new_edit"
             )
     u = entitydata_edit_url("new", "testcoll", "testtype", view_id="Default_view")
     r = self.client.post(u, f)
     self.assertEqual(r.status_code,   401)
     self.assertEqual(r.reason_phrase, "Unauthorized")
     return
示例#57
0
 def test_reference_imported_resource(self):
     # Create imported resource (see previous test)
     f = entitydata_default_view_form_data(
         entity_id="test1", type_id="testimptype", action="edit", 
         do_import="imp_field__import"
         )
     f['imp_field'] = self.fileuri
     u = entitydata_edit_url(
         "edit", "testcoll", "testimptype", entity_id="test1", view_id="testimpview"
         )
     r = self.client.post(u, f)
     self.assertEqual(r.status_code,   302)
     self.assertEqual(r.reason_phrase, "FOUND")
     # Display resource with reference
     u = entitydata_edit_url(
         "view", "testcoll", "testreftype", entity_id="test1", view_id="testrefview"
         )
     r = self.client.get(u)
     self.assertEqual(r.status_code,   200)
     self.assertEqual(r.reason_phrase, "OK")
     # Check display context
     self.assertEqual(len(r.context['fields']), 4)
     f0 = context_view_field(r.context, 0, 0)
     self.assertEqual(f0.field_id,     "Entity_id")
     self.assertEqual(f0.field_value,  "test1")
     f1 = context_view_field(r.context, 1, 0)
     self.assertEqual(f1.field_id,     "Entity_label")
     self.assertEqual(f1.field_value,  "test_ref_entity test1 label")
     f2 = context_view_field(r.context, 2, 0)
     self.assertEqual(f2.field_id,     "Entity_comment")
     self.assertEqual(f2.field_value,  "test_ref_entity test1 comment")
     f3 = context_view_field(r.context, 3, 0)
     basepath = TestBasePath + "/c/testcoll/d/testimptype/"
     self.assertEqual(f3.field_id,           "Test_reference")
     self.assertEqual(f3.field_value,        "testimptype/test1")
     self.assertEqual(f3.field_value_link,   basepath+"test1/")
     self.assertEqual(f3.target_value['import_name'],   "imp_field")
     self.assertEqual(f3.target_value['resource_name'], "imp_field.md")
     self.assertEqual(f3.target_value['resource_type'], "text/markdown")
     self.assertEqual(f3.target_value_link,  basepath+"test1/imp_field.md")
     return
示例#58
0
    def test_image_view_field(self):
        # This test is for an image field that supports file upload in the same entity

        # Upload image
        self.test_image_edit_field()

        # Display resource in view mode
        u = entitydata_edit_url("view", "testcoll", "testimgtype", entity_id="test1", view_id="testimgview")
        r = self.client.get(u)
        self.assertEqual(r.status_code,   200)
        self.assertEqual(r.reason_phrase, "OK")
        # Check display context
        self.assertEqual(len(r.context['fields']), 4)
        f0 = context_view_field(r.context, 0, 0)
        self.assertEqual(f0.field_id,     "Entity_id")
        self.assertEqual(f0.field_value,  "test1")
        f1 = context_view_field(r.context, 1, 0)
        self.assertEqual(f1.field_id,     "Entity_label")
        f2 = context_view_field(r.context, 2, 0)
        self.assertEqual(f2.field_id,     "Entity_comment")
        f3 = context_view_field(r.context, 3, 0)
        basepath = TestBasePath + "/c/testcoll/d/testimgtype/"
        # print "\n*****\n"+repr(context_view_field(r.context, i, 0).target_value)+"\n*****\n"
        self.assertEqual(f3.field_id,           "Test_image")
        self.assertEqual(f3.field_value,        test_image_field_value())
        self.assertEqual(f3.target_value_link,  basepath+"test1/img_field.jpg")
        # Check for rendered image link
        # log.info(r.content)
        field_details = (
            { "basepath":   TestBasePath
            , "coll_id":    "testcoll"
            , "type_id":    "testimgtype"
            , "entity_id":  "test1"
            , "field_id":   "img_field"
            , "tooltip":    ""
            })
        img_element = """
            <div class="small-12 columns" %(tooltip)s>
              <div class="row view-value-row">
                <div class="view-label small-12 medium-2 columns">
                  <span>test_image_field label</span>
                </div>
                <div class="view-value small-12 medium-10 columns">
                  <a href="%(basepath)s/c/%(coll_id)s/d/%(type_id)s/%(entity_id)s/%(field_id)s.jpg" target="_blank">
                    <img src="%(basepath)s/c/%(coll_id)s/d/%(type_id)s/%(entity_id)s/%(field_id)s.jpg"
                         alt="Image at '%(basepath)s/c/%(coll_id)s/d/%(type_id)s/%(entity_id)s/%(field_id)s.jpg'" />
                  </a>
                </div>
              </div>
            </div>
            """%field_details
        self.assertContains(r, img_element, html=True)
        return
 def test_post_new_type_entity(self):
     f = entitylist_form_data("new", list_id="Field_list")
     u = entitydata_list_type_url("testcoll", layout.FIELD_TYPEID, list_id="Field_list")
     r = self.client.post(u, f)
     self.assertEqual(r.status_code,   302)
     self.assertEqual(r.reason_phrase, "FOUND")
     self.assertEqual(r.content,       "")
     v = TestHostUri + entitydata_edit_url("new", "testcoll", layout.FIELD_TYPEID, view_id="Field_view")
     c = continuation_url_param(u)
     self.assertIn(v, r['location'])
     self.assertIn(c, r['location'])
     return
示例#60
0
 def test_get_edit_not_exists(self):
     u = entitydata_edit_url(
         "edit", "testcoll", layout.TYPE_TYPEID, entity_id="notype", view_id="Type_view"
         )
     r = self.client.get(u)
     # log.info(r.content)
     self.assertEqual(r.status_code,   404)
     self.assertEqual(r.reason_phrase, "Not found")
     self.assertContains(r, "<title>Annalist error</title>", status_code=404)
     self.assertContains(r, "<h3>404: Not found</h3>", status_code=404)
     err_label = error_label("testcoll", layout.TYPE_TYPEID, "notype")
     self.assertContains(r, "<p>Entity %s does not exist</p>"%(err_label), status_code=404)
     return