def setUp(self):
     init_annalist_test_site()
     init_annalist_test_coll()
     self.testsite    = Site(TestBaseUri, TestBaseDir)
     self.testcoll    = Collection(self.testsite, "testcoll")
     # Populate collection with linked record types, views and lists
     self.testsrc_type = RecordType.create(self.testcoll, "testsrc_type", testsrc_type_create_values)
     self.testtgt_type = RecordType.create(self.testcoll, "testtgt_type", testtgt_type_create_values)
     self.testsrc_view = RecordView.create(self.testcoll, "testsrc_view", testsrc_view_create_values)
     self.testtgt_view = RecordView.create(self.testcoll, "testtgt_view", testtgt_view_create_values)
     self.testsrc_list = RecordList.create(self.testcoll, "testsrc_list", testsrc_list_create_values)
     self.testtgt_list = RecordList.create(self.testcoll, "testtgt_list", testtgt_list_create_values)
     self.testtgtref_field = RecordField.create(self.testcoll, "testtgtref_field", testtgtref_field_create_values)
     self.no_options   = [ FieldChoice('', label="(no options)") ]
     self.tgt_options  = (
         [ FieldChoice("testtgt_type/"+v, 
             label="testtgt_entity %s label"%v,
             link=entity_url("testcoll", "testtgt_type", v))
           for v in ["testtgt1", "testtgt2"]
         ])
     # Create data records for testing:
     self.testtgt_type_info = EntityTypeInfo(self.testcoll, "testtgt_type", create_typedata=True)
     self.testsrc_type_info = EntityTypeInfo(self.testcoll, "testsrc_type", create_typedata=True)
     for tgt_id in ("testtgt1", "testtgt2"):
         self.testtgt_type_info.create_entity(tgt_id, testtgt_entity_create_values(tgt_id))
     for src_id, tgt_ref in (("testsrc1", "testtgt1"), ("testsrc2", "testtgt2")):
         self.testsrc_type_info.create_entity(src_id, testsrc_entity_create_values(src_id, tgt_ref))
     # Login and permissions
     create_test_user(self.testcoll, "testuser", "testpassword")
     self.client = Client(HTTP_HOST=TestHost)
     loggedin = self.client.login(username="******", password="******")
     self.assertTrue(loggedin)
     return
Exemple #2
0
def coll123_create_data(site):
    coll1 = Collection.create(site, "coll1", collection_create_values("coll1"))
    coll2 = Collection.create(site, "coll2", collection_create_values("coll2"))
    coll3 = Collection.create(site, "coll3", collection_create_values("coll3"))
    #
    for coll in [coll1, coll2, coll3]:
        type1 = RecordType.create(
            coll, "type1", recordtype_create_values(coll._entityid, "type1"))
        view1 = RecordView.create(
            coll, "view1", recordview_create_values(coll._entityid, "view1"))
        list1 = RecordList.create(
            coll, "list1", recordlist_create_values(coll._entityid, "list1"))
        data1 = RecordTypeData.create(coll, "type1", {})
        type2 = RecordType.create(
            coll, "type2", recordtype_create_values(coll._entityid, "type2"))
        view2 = RecordView.create(
            coll, "view2", recordview_create_values(coll._entityid, "view2"))
        list2 = RecordList.create(
            coll, "list2", recordlist_create_values(coll._entityid, "list2"))
        data2 = RecordTypeData.create(coll, "type2", {})
        #
        for t, d in [(type1, data1), (type2, data2)]:
            for eid in ["entity1", "entity2", "entity3"]:
                e = EntityData.create(d, eid,
                                      entitydata_create_values(coll, t, eid))
    return
 def test_recordlist_create_load(self):
     t = RecordList.create(self.testcoll, "list1",
                           recordlist_create_values(list_id="list1"))
     td = RecordList.load(self.testcoll, "list1").get_values()
     v = recordlist_read_values(list_id="list1")
     self.assertKeysMatch(td, v)
     self.assertDictionaryMatch(td, v)
     return
 def setUp(self):
     init_annalist_test_site()
     init_annalist_test_coll()
     self.testsite = Site(TestBaseUri, TestBaseDir)
     self.testcoll = Collection(self.testsite, "testcoll")
     # Populate collection with linked record types, views and lists
     self.testsrc_type = RecordType.create(self.testcoll, "testsrc_type",
                                           testsrc_type_create_values)
     self.testtgt_type = RecordType.create(self.testcoll, "testtgt_type",
                                           testtgt_type_create_values)
     self.testsrc_view = RecordView.create(self.testcoll, "testsrc_view",
                                           testsrc_view_create_values)
     self.testtgt_view = RecordView.create(self.testcoll, "testtgt_view",
                                           testtgt_view_create_values)
     self.testsrc_list = RecordList.create(self.testcoll, "testsrc_list",
                                           testsrc_list_create_values)
     self.testtgt_list = RecordList.create(self.testcoll, "testtgt_list",
                                           testtgt_list_create_values)
     self.testtgtref_field = RecordField.create(
         self.testcoll, "testtgtref_field", testtgtref_field_create_values)
     self.no_options = [FieldChoice('', label="(no options)")]
     self.tgt_options = ([
         FieldChoice("testtgt_type/" + v,
                     label="testtgt_entity %s label" % v,
                     link=entity_url("testcoll", "testtgt_type", v))
         for v in ["testtgt1", "testtgt2"]
     ])
     # Create data records for testing:
     self.testtgt_type_info = EntityTypeInfo(self.testcoll,
                                             "testtgt_type",
                                             create_typedata=True)
     self.testsrc_type_info = EntityTypeInfo(self.testcoll,
                                             "testsrc_type",
                                             create_typedata=True)
     for tgt_id in ("testtgt1", "testtgt2"):
         self.testtgt_type_info.create_entity(
             tgt_id, testtgt_entity_create_values(tgt_id))
     for src_id, tgt_ref in (("testsrc1", "testtgt1"), ("testsrc2",
                                                        "testtgt2")):
         self.testsrc_type_info.create_entity(
             src_id, testsrc_entity_create_values(src_id, tgt_ref))
     # Login and permissions
     create_test_user(self.testcoll, "testuser", "testpassword")
     self.client = Client(HTTP_HOST=TestHost)
     loggedin = self.client.login(username="******",
                                  password="******")
     self.assertTrue(loggedin)
     return
 def test_recordlist2_data(self):
     t = RecordList(self.testcoll, "list2", self.testsite)
     self.assertEqual(t.get_id(), "list2")
     self.assertEqual(t.get_type_id(), "_list")
     self.assertIn("/c/testcoll/_annalist_collection/lists/list2/",
                   t.get_url())
     self.assertEqual(TestBaseUri + "/c/testcoll/d/_list/list2/",
                      t.get_view_url())
     t.set_values(recordlist_create_values(list_id="list2"))
     td = t.get_values()
     self.assertEqual(set(td.keys()), set(recordlist_value_keys()))
     v = recordlist_values(list_id="list2")
     self.assertDictionaryMatch(td, v)
     return
 def test_post_new_list_cancel(self):
     self.assertFalse(RecordList.exists(self.testcoll, "newlist"))
     f = recordlist_view_form_data(list_id="newlist",
                                   action="new",
                                   cancel="Cancel",
                                   update="Updated RecordList")
     u = entitydata_edit_url("new",
                             "testcoll",
                             "_list",
                             view_id="List_view")
     r = self.client.post(u, f)
     self.assertEqual(r.status_code, 302)
     self.assertEqual(r.reason_phrase, "FOUND")
     self.assertEqual(r.content, "")
     self.assertEqual(r['location'], self.continuation_url)
     # Check that new record type still does not exist
     self.assertFalse(RecordList.exists(self.testcoll, "newview"))
     return
 def test_post_confirmed_remove_view(self):
     t = RecordList.create(self.testcoll, "deleteview",
                           recordlist_create_values("deleteview"))
     self.assertTrue(RecordList.exists(self.testcoll, "deleteview"))
     # Submit positive confirmation
     u = TestHostUri + recordlist_edit_url("delete", "testcoll")
     f = recordlist_delete_confirm_form_data("deleteview")
     r = self.client.post(u, f)
     self.assertEqual(r.status_code, 302)
     self.assertEqual(r.reason_phrase, "FOUND")
     self.assertEqual(r.content, "")
     self.assertMatch(
         r['location'],
         "^" + TestHostUri + collection_edit_url("testcoll") +
         r"\?info_head=.*&info_message=.*deleteview.*testcoll.*$")
     # Confirm deletion
     self.assertFalse(RecordList.exists(self.testcoll, "deleteview"))
     return
Exemple #8
0
 def lists(self):
     """
     Generator enumerates and returns record lists that may be stored
     """
     for f in self._children(RecordList):
         t = RecordList.load(self, f)
         if t:
             yield t
     return
Exemple #9
0
    def remove_list(self, list_id):
        """
        Remove identified list description

        list_id     local identifier for the list to remove.

        Returns None on success, or a non-False status code if the list is not removed.
        """
        s = RecordList.remove(self, list_id)
        return s
Exemple #10
0
    def get_list(self, list_id):
        """
        Retrieve identified list description

        list_id     local identifier for the list to retrieve.

        returns a RecordList object for the identified list, or None.
        """
        l = RecordList.load(self, list_id, altscope="all")
        return l
 def _check_list_view_values(self,
                             list_id,
                             list_uri=None,
                             update="RecordList",
                             num_fields=4):
     "Helper function checks content of record view entry with supplied list_id"
     self.assertTrue(RecordList.exists(self.testcoll, list_id))
     t = RecordList.load(self.testcoll, list_id)
     self.assertEqual(t.get_id(), list_id)
     self.assertEqual(t.get_view_url(),
                      TestHostUri + recordlist_url("testcoll", list_id))
     v = recordlist_values(list_id=list_id,
                           list_uri=list_uri,
                           update=update)
     if num_fields == 0:
         v['annal:list_fields'] = []
     # log.info("RecordList.load values: %r"%(t.get_values(),))
     self.assertDictionaryMatch(t.get_values(), v)
     return t
def coll123_create_data(site):
    coll1 = Collection.create(site, "coll1", collection_create_values("coll1"))
    coll2 = Collection.create(site, "coll2", collection_create_values("coll2"))
    coll3 = Collection.create(site, "coll3", collection_create_values("coll3"))
    #
    for coll in [coll1, coll2, coll3]:
        type1 = RecordType.create(coll, "type1", recordtype_create_values(coll._entityid, "type1"))
        view1 = RecordView.create(coll, "view1", recordview_create_values(coll._entityid, "view1"))
        list1 = RecordList.create(coll, "list1", recordlist_create_values(coll._entityid, "list1"))
        data1 = RecordTypeData.create(coll, "type1", {})
        type2 = RecordType.create(coll, "type2", recordtype_create_values(coll._entityid, "type2"))
        view2 = RecordView.create(coll, "view2", recordview_create_values(coll._entityid, "view2"))
        list2 = RecordList.create(coll, "list2", recordlist_create_values(coll._entityid, "list2"))
        data2 = RecordTypeData.create(coll, "type2", {})
        #
        for t,d in [(type1,data1),(type2,data2)]:
            for eid in ["entity1", "entity2", "entity3"]:
                e = EntityData.create(d, eid, entitydata_create_values(coll,t,eid))
    return
Exemple #13
0
    def get_list(self, list_id):
        """
        Retrieve identified list description

        list_id     local identifier for the list to retrieve.

        returns a RecordList object for the identified list, or None.
        """
        l = RecordList.load(self, list_id, altparent=self._parentsite)
        return l
Exemple #14
0
    def remove_list(self, list_id):
        """
        Remove identified list description

        list_id     local identifier for the list to remove.

        Returns a non-False status code if the list is not removed.
        """
        s = RecordList.remove(self, list_id)
        return s
 def get_list_info(self, list_id):
     """
     Retrieve list definition to use for display
     """
     if not self.http_response:
         assert ((self.site and self.collection) is not None)
         assert list_id
         # log.debug(
         #     "DisplayInfo.get_list_info: collection.get_alt_entities %r"%
         #     [ c.get_id() for c in  self.collection.get_alt_entities(altscope="all") ]
         #     )
         if not RecordList.exists(self.collection, list_id, altscope="all"):
             log.warning(
                 "DisplayInfo.get_list_info: RecordList %s not found" %
                 list_id)
             self.http_response = self.view.error(
                 dict(self.view.error404values(),
                      message=message.RECORD_LIST_NOT_EXISTS %
                      ({
                          'id': list_id,
                          'coll_id': self.coll_id
                      })))
         else:
             self.list_id = list_id
             self.recordlist = RecordList.load(self.collection,
                                               list_id,
                                               altscope="all")
             if "@error" in self.recordlist:
                 self.http_response = self.view.error(
                     dict(self.view.error500values(),
                          message=message.RECORD_LIST_LOAD_ERROR %
                          ({
                              'id': list_id,
                              'file': self.recordlist["@error"],
                              'message': self.recordlist["@message"]
                          })))
             elif self.type_id is None and self.entitytypeinfo is None:
                 self.get_type_info(
                     extract_entity_id(
                         self.recordlist[ANNAL.CURIE.default_type]))
             # log.debug("DisplayInfo.get_list_info: %r"%(self.recordlist.get_values()))
     return self.http_response
 def test_post_copy_view_cancel(self):
     self.assertFalse(RecordList.exists(self.testcoll, "copylist"))
     f = recordlist_view_form_data(list_id="copylist",
                                   orig_id="Default_list",
                                   action="copy",
                                   cancel="Cancel",
                                   update="RecordList")
     u = entitydata_edit_url("copy",
                             "testcoll",
                             "_list",
                             entity_id="Default_list",
                             view_id="List_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 target record view still does not exist
     self.assertFalse(RecordList.exists(self.testcoll, "copylist"))
     return
Exemple #17
0
 def get_default_list(self):
     """
     Return the default list to be displayed for the current collection.
     """
     list_id = self.get(ANNAL.CURIE.default_list, None)
     if list_id and not RecordList.exists(
             self, list_id, altparent=self._parentsite):
         log.warning("Default list %s for collection %s does not exist" %
                     (list_id, self.get_id()))
         list_id = None
     return list_id
Exemple #18
0
 def test_migrate_list_fields(self):
     """
     Test migration of list fields
     """
     self.test_list = RecordList.create(self.testcoll, test_list_id,
                                        test_list_create_values)
     migrate_coll_data(self.testcoll)
     # Read field definition and check for inline field list
     view_data = self.check_entity_values(
         "_list", test_list_id, check_values=test_list_migrated_values)
     return
Exemple #19
0
 def get_default_list(self):
     """
     Return the default list to be displayed for the current collection.
     """
     list_id = self.get(ANNAL.CURIE.default_list, None)
     if list_id and not RecordList.exists(self, list_id, altscope="all"):
         log.warning(
             "Default list %s for collection %s does not exist"%
             (list_id, self.get_id())
             )
         list_id = None
     return list_id 
 def test_recordlist_init(self):
     t = RecordList(self.testcoll, "testlist", self.testsite)
     u = recordlist_coll_url(self.testsite,
                             coll_id="testcoll",
                             list_id="testlist")
     self.assertEqual(t._entitytype, ANNAL.CURIE.List)
     self.assertEqual(t._entityfile, layout.LIST_META_FILE)
     self.assertEqual(t._entityref, layout.META_LIST_REF)
     self.assertEqual(t._entityid, "testlist")
     self.assertEqual(t._entityurl, u)
     self.assertEqual(t._entitydir, recordlist_dir(list_id="testlist"))
     self.assertEqual(t._values, None)
     return
Exemple #21
0
    def add_list(self, list_id, list_meta):
        """
        Add a new record list to the current collection

        list_id     identifier for the new list, as a string
                    with a form that is valid as URI path segment.
        list_meta   a dictionary providing additional information about
                    the list to be created.

        returns a RecordList object for the newly created list.
        """
        l = RecordList.create(self, list_id, list_meta)
        return l
Exemple #22
0
    def add_list(self, list_id, list_meta):
        """
        Add a new record list to the current collection

        list_id     identifier for the new list, as a string
                    with a form that is valid as URI path segment.
        list_meta   a dictionary providing additional information about
                    the list to be created.

        returns a RecordList object for the newly created list.
        """
        l = RecordList.create(self, list_id, list_meta)
        return l
Exemple #23
0
 def get_list_info(self, list_id):
     """
     Retrieve list definition to use for display
     """
     if not self.http_response:
         assert ((self.site and self.collection) is not None)
         assert list_id
         # log.debug(
         #     "DisplayInfo.get_list_info: collection.get_alt_entities %r"%
         #     [ c.get_id() for c in  self.collection.get_alt_entities(altscope="all") ]
         #     )
         if not RecordList.exists(self.collection, list_id, altscope="all"):
             log.warning("DisplayInfo.get_list_info: RecordList %s not found"%list_id)
             self.http_response = self.view.error(
                 dict(self.view.error404values(),
                     message=message.RECORD_LIST_NOT_EXISTS%(
                         {'id': list_id, 'coll_id': self.coll_id})
                     )
                 )
         else:
             self.list_id    = list_id
             self.recordlist = RecordList.load(self.collection, list_id, altscope="all")
             if "@error" in self.recordlist:
                 self.http_response = self.view.error(
                     dict(self.view.error500values(),
                         message=message.RECORD_LIST_LOAD_ERROR%(
                             { 'id':       list_id
                             , 'file':     self.recordlist["@error"]
                             , 'message':  self.recordlist["@message"]
                             })
                         )
                     )
             elif self.type_id is None and self.entitytypeinfo is None:
                 self.get_type_info(
                     extract_entity_id(self.recordlist[ANNAL.CURIE.default_type])
                     )
             # log.debug("DisplayInfo.get_list_info: %r"%(self.recordlist.get_values()))
     return self.http_response
 def test_post_new_list(self):
     self.assertFalse(RecordList.exists(self.testcoll, "newlist"))
     f = recordlist_view_form_data(list_id="newlist",
                                   action="new",
                                   update="New List")
     u = entitydata_edit_url("new",
                             "testcoll",
                             "_list",
                             view_id="List_view")
     r = self.client.post(u, f)
     # print r.content
     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_list_view_values("newlist",
                                  update="New List",
                                  num_fields=0)
     return
 def test_recordlist_default_data(self):
     t = RecordList.load(self.testcoll,
                         "Default_list",
                         altparent=self.testsite)
     self.assertEqual(t.get_id(), "Default_list")
     self.assertIn("/c/testcoll/_annalist_collection/lists/Default_list",
                   t.get_url())
     self.assertEqual(t.get_type_id(), "_list")
     td = t.get_values()
     self.assertEqual(set(td.keys()),
                      set(recordlist_load_keys(list_uri=True)))
     v = recordlist_read_values(list_id="Default_list")
     v.update({
         '@id': "annal:display/Default_list",
         'rdfs:label': "List entities",
         'rdfs:comment': "Default list of entities of given type",
         'annal:uri': "annal:display/Default_list"
     })
     self.assertDictionaryMatch(td, v)
     return
 def test_post_edit_view_new_id(self):
     self._create_list_view("editlist1")
     self._check_list_view_values("editlist1")
     f = recordlist_view_form_data(list_id="editlist2",
                                   orig_id="editlist1",
                                   action="edit",
                                   update="Updated RecordList")
     u = entitydata_edit_url("edit",
                             "testcoll",
                             "_list",
                             entity_id="editlist1",
                             view_id="List_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 list exists and old does not
     self.assertFalse(RecordList.exists(self.testcoll, "editlist1"))
     self._check_list_view_values("editlist2", update="Updated RecordList")
     return
def coll_list(coll, list_id):
    """
    Return identified list in collection, or None
    """
    return RecordList.load(coll, list_id, altscope="all")
 def _create_list_view(self, list_id):
     "Helper function creates record view entry with supplied list_id"
     t = RecordList.create(self.testcoll, list_id,
                           recordlist_create_values(list_id=list_id))
     return t
def coll_list(coll, list_id):
    """
    Return identified list in collection, or None
    """
    return RecordList.load(coll, list_id, altscope="all")