Example #1
0
def create_test_coll_inheriting(base_coll_id=None,
                                coll_id="testcoll",
                                type_id="testtype"):
    """
    Similar to init_annalist_test_coll, but collection also
    inherits from named collection.
    """
    testsite = Site(TestBaseUri, TestBaseDir)
    basecoll = Collection.load(testsite, base_coll_id)
    if not basecoll:
        msg = "Base collection %s not found" % base_coll_id
        log.warning(msg)
        assert False, msg
    testcoll = Collection.create(testsite, coll_id,
                                 collection_create_values(coll_id))
    testcoll.set_alt_entities(basecoll)
    testcoll._save()
    testtype = RecordType.create(testcoll, type_id,
                                 recordtype_create_values(coll_id, type_id))
    testdata = RecordTypeData.create(testcoll, type_id, {})
    teste = EntityData.create(
        testdata, "entity1",
        entitydata_create_values(testcoll, testtype, "entity1"))
    testcoll.generate_coll_jsonld_context()
    return testcoll
Example #2
0
 def setUp(self):
     init_annalist_test_site()
     self.testsite = Site(TestBaseUri, TestBaseDir)
     self.testcoll = Collection(self.testsite, "testcoll")
     self.testcoll1 = Collection(self.testsite, "testcoll1")
     self.testcoll2 = Collection(self.testsite, "testcoll2")
     self.fieldcache = CollectionFieldCache()
     self.field1 = RecordField(self.testcoll1, "field1")
     self.field1.set_values(
         recordfield_create_values(field_id="field1",
                                   property_uri="test:field1",
                                   superproperty_uris=[]))
     self.field11 = RecordField(self.testcoll1, "field11")
     self.field11.set_values(
         recordfield_create_values(field_id="field11",
                                   property_uri="test:field11",
                                   superproperty_uris=["test:field1"]))
     self.field111 = RecordField(self.testcoll1, "field111")
     self.field111.set_values(
         recordfield_create_values(field_id="field111",
                                   property_uri="test:field111",
                                   superproperty_uris=["test:field11"]))
     self.field2 = RecordField(self.testcoll1, "field2")
     self.field2.set_values(
         recordfield_create_values(field_id="field2",
                                   property_uri="test:field2",
                                   superproperty_uris=[]))
     return
Example #3
0
 def get_coll_info(self, coll_id):
     """
     Check collection identifier, and get reference to collection object.
     """
     assert (self.site is not None)
     if not self.http_response:
         if not Collection.exists(self.site, coll_id):
             self.http_response = self.view.error(
                 dict(self.view.error404values(),
                      message=message.COLLECTION_NOT_EXISTS %
                      {'id': coll_id}))
         else:
             self.coll_id = coll_id
             #@@TODO: try with altscope="site"?
             self.collection = Collection.load(self.site,
                                               coll_id,
                                               altscope="all")
             self.coll_perms = self.collection
             ver = self.collection.get(ANNAL.CURIE.software_version,
                                       None) or "0.0.0"
             if LooseVersion(ver) > LooseVersion(annalist.__version__):
                 self.http_response = self.view.error(
                     dict(self.view.error500values(),
                          message=message.COLLECTION_NEWER_VERSION % {
                              'id': coll_id,
                              'ver': ver
                          }))
     return self.http_response
Example #4
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
Example #5
0
 def _check_collection_data_values(self, coll_id=None):
     """
     Helper function checks content of annalist collection data
     """
     self.assertTrue(Collection.exists(self.testsite, coll_id))
     t = Collection.load(self.testsite, coll_id)
     self.assertEqual(t.get_id(), coll_id)
     self.assertEqual(t.get_view_url_path(),
                      collection_view_url(coll_id="testcoll"))
     v = collectiondata_values(coll_id=coll_id)
     self.assertDictionaryMatch(t.get_values(), v)
     return t
def am_migratecollection(annroot, userhome, options):
    """
    Apply migrations for a specified collection

        annalist_manager migratecollection coll

    Reads and writes every entity in a collection, thereby applying data 
    migrations and saving them in the stored data.

    annroot     is the root directory for the Annalist software installation.
    userhome    is the home directory for the host system user issuing the command.
    options     contains options parsed from the command line.

    returns     0 if all is well, or a non-zero status code.
                This value is intended to be used as an exit status code
                for the calling program.
    """
    status, settings, site = get_settings_site(annroot, userhome, options)
    if status != am_errors.AM_SUCCESS:
        return status
    coll_id = getargvalue(getarg(options.args, 0), "Collection Id: ")
    coll = Collection.load(site, coll_id)
    if not (coll and coll.get_values()):
        print("Collection not found: %s" % (coll_id), file=sys.stderr)
        return am_errors.AM_NOCOLLECTION
    status = am_errors.AM_SUCCESS
    print("Apply data migrations in collection '%s'" % (coll_id, ))
    msgs = migrate_coll_data(coll)
    if msgs:
        for msg in msgs:
            print(msg)
        status = am_errors.AM_MIGRATECOLLFAIL
    return status
 def setUp(self):
     init_annalist_test_site()
     self.testsite = Site(TestBaseUri, TestBaseDir)
     self.testcoll = Collection.create(self.testsite, "testcoll",
                                       collection_create_values("testcoll"))
     self.testtype = RecordType.create(
         self.testcoll, "testtype",
         recordtype_create_values("testcoll", "testtype"))
     self.testtype2 = RecordType.create(
         self.testcoll, "testtype2",
         recordtype_create_values("testcoll", "testtype2"))
     self.testdata = RecordTypeData.create(self.testcoll, "testtype", {})
     self.testdata2 = RecordTypeData.create(self.testcoll, "testtype2", {})
     e1 = self._create_entity_data("entity1")
     e2 = self._create_entity_data("entity2")
     e3 = self._create_entity_data("entity3")
     e4 = EntityData.create(
         self.testdata2, "entity4",
         entitydata_create_values("entity4", type_id="testtype2"))
     self.type_ids = get_site_types_linked("testcoll")
     self.type_ids.append(
         FieldChoice("testtype",
                     label="RecordType testcoll/testtype",
                     link=recordtype_url("testcoll", "testtype")))
     self.list_ids = get_site_lists_linked("testcoll")
     # Login and permissions
     create_test_user(self.testcoll, "testuser", "testpassword")
     self.client = Client(HTTP_HOST=TestHost)
     loggedin = self.client.login(username="******",
                                  password="******")
     self.assertTrue(loggedin)
     return
Example #8
0
def init_annalist_named_test_coll(base_coll_id=None,
                                  coll_id="testcoll",
                                  type_id="testtype"):
    """
    Similar to init_annalist_test_coll, but collection also installs and 
    inherits from named collection definitions.

    """
    # @@TODO: DRY: use create_test_coll_inheriting
    # @@TODO: rename: install_create_test_coll_inheriting
    log.debug("init_annalist_named_test_coll")
    testsite = Site(TestBaseUri, TestBaseDir)
    namedcoll = install_annalist_named_coll(base_coll_id)
    testcoll = Collection.create(testsite, coll_id,
                                 collection_create_values(coll_id))
    testcoll.set_alt_entities(namedcoll)
    testcoll._save()
    testtype = RecordType.create(testcoll, type_id,
                                 recordtype_create_values(coll_id, type_id))
    testdata = RecordTypeData.create(testcoll, type_id, {})
    teste = EntityData.create(
        testdata, "entity1",
        entitydata_create_values(testcoll, testtype, "entity1"))
    testcoll.generate_coll_jsonld_context()
    return testcoll
Example #9
0
 def setUp(self):
     init_annalist_test_site()
     self.testsite = Site(TestBaseUri, TestBaseDir)
     self.sitedata = SiteData(self.testsite)
     self.testcoll = Collection(self.testsite, "testcoll")
     self.layout = ({
         'enum_field_placement_id': layout.ENUM_FIELD_PLACEMENT_ID,
         'enum_list_type_id': layout.ENUM_LIST_TYPE_ID,
         'enum_render_type_id': layout.ENUM_RENDER_TYPE_ID,
         'enum_value_type_id': layout.ENUM_VALUE_TYPE_ID,
         'enum_value_mode_id': layout.ENUM_VALUE_MODE_ID,
         'field_typeid': layout.FIELD_TYPEID,
         'group_typeid': layout.GROUP_TYPEID,
         'list_typeid': layout.LIST_TYPEID,
         'type_typeid': layout.TYPE_TYPEID,
         'user_typeid': layout.USER_TYPEID,
         'view_typeid': layout.VIEW_TYPEID,
         'vocab_typeid': layout.VOCAB_TYPEID,
         'field_dir': layout.FIELD_DIR,
         'group_dir': layout.GROUP_DIR,
         'list_dir': layout.LIST_DIR,
         'type_dir': layout.TYPE_DIR,
         'user_dir': layout.USER_DIR,
         'view_dir': layout.VIEW_DIR,
         'vocab_dir': layout.VOCAB_DIR
     })
     return
    def setUp(self):
        init_annalist_test_site()
        self.testsite = Site(TestBaseUri, TestBaseDir)
        self.testcoll = Collection.create(self.testsite, "testcoll",
                                          collection_create_values("testcoll"))
        self.testtype = RecordType.create(self.testcoll, "testtype",
                                          recordtype_create_values("testtype"))
        self.testdata = RecordTypeData.create(self.testcoll, "testtype", {})

        # Create view with duplicate field id
        self.viewdata = recordview_create_values(view_id="DupField_view")
        recordview_values_add_field(self.viewdata,
                                    field_id="Entity_comment",
                                    field_placement="small:0,12")
        recordview_values_add_field(self.viewdata,
                                    field_id="Entity_comment",
                                    field_property_uri="rdfs:comment_alt",
                                    field_placement="small:0,12")
        self.testview = RecordView.create(self.testcoll, "DupField_view",
                                          self.viewdata)

        # Login and permissions
        create_test_user(self.testcoll, "testuser", "testpassword")
        self.client = Client(HTTP_HOST=TestHost)
        loggedin = self.client.login(username="******",
                                     password="******")
        self.assertTrue(loggedin)
        return
 def test_set_alt_entities_2(self):
     coll_id   = "altcoll1"
     altcoll1  = Collection.create(self.testsite, coll_id, collection_create_values(coll_id))
     parents   = altcoll1.set_alt_entities(self.testcoll)
     parentids = [ p.get_id() for p in parents ]
     self.assertEqual( parentids, ["altcoll1", "testcoll", layout.SITEDATA_ID])
     return
Example #12
0
 def setUp(self):
     self.filepath  = "%s/README.md"%TestBaseDir
     self.fileuri   = "file://"+self.filepath
     self.imagepath = "%s/test-image.jpg"%TestBaseDir
     self.imageuri  = "file://"+self.filepath
     init_annalist_test_site()
     init_annalist_test_coll()
     self.testsite    = Site(TestBaseUri, TestBaseDir)
     self.testcoll    = Collection(self.testsite, "testcoll")
     # Populate collection with record type, view and field
     self.test_ref_type = RecordType.create(
         self.testcoll, "testreftype", test_image_ref_type_create_values
         )
     self.test_ref_view = RecordView.create(
         self.testcoll, "testrefview", test_image_ref_view_create_values
         )
     self.test_ref_field = RecordField.create(
         self.testcoll, "Test_image_ref", test_image_ref_field_create_values
         )
     # Create data records for testing image references:
     self.test_ref_type_info = EntityTypeInfo(
         self.testcoll, "testreftype", create_typedata=True
         )
     self.test_ref_type_info.create_entity("test1", test_ref_entity_create_values(self.imageuri))
     # 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
Example #13
0
 def setUp(self):
     init_annalist_test_site()
     self.testsite = Site(TestBaseUri, TestBaseDir)
     self.testcoll = Collection(self.testsite, "testcoll")
     self.testtype = RecordType(self.testcoll, "testtype")
     self.testdata = RecordTypeData(self.testcoll, "testtype")
     return
Example #14
0
 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.test_supertype_type = RecordType.create(
         self.testcoll, "test_supertype_type",
         test_supertype_type_create_values)
     self.test_subtype_type = RecordType.create(
         self.testcoll, "test_subtype_type",
         test_subtype_type_create_values)
     self.no_options = [FieldChoice('', label="(no options)")]
     # Create type and data records for testing:
     self.test_supertype_type_info = EntityTypeInfo(self.testcoll,
                                                    "test_supertype_type",
                                                    create_typedata=True)
     self.test_subtype_type_info = EntityTypeInfo(self.testcoll,
                                                  "test_subtype_type",
                                                  create_typedata=True)
     for entity_id in ("test_subtype_entity", ):
         self.test_subtype_type_info.create_entity(
             entity_id, test_subtype_entity_create_values(entity_id))
     # Login and permissions
     create_test_user(self.testcoll, "testuser", "testpassword")
     self.client = Client(HTTP_HOST=TestHost)
     loggedin = self.client.login(username="******",
                                  password="******")
     self.assertTrue(loggedin)
     return
 def setUp(self):
     init_annalist_test_site()
     self.testsite = Site(TestBaseUri, TestBaseDir)
     self.testcoll = Collection(self.testsite, "testcoll")
     self.testcoll1_a = Collection(self.testsite, "testcoll1")
     self.testcoll1_b = Collection(self.testsite, "testcoll1")
     self.testcoll2_a = Collection(self.testsite, "testcoll2")
     self.testcoll2_b = Collection(self.testsite, "testcoll2")
     self.typecache = CollectionTypeCache()
     self.type1 = RecordType(self.testcoll1_a, "type1")
     self.type1.set_values(
         recordtype_create_values(type_id="type1",
                                  type_uri="test:type1",
                                  supertype_uris=[]))
     self.type11 = RecordType(self.testcoll1_a, "type11")
     self.type11.set_values(
         recordtype_create_values(type_id="type11",
                                  type_uri="test:type11",
                                  supertype_uris=["test:type1"]))
     self.type111 = RecordType(self.testcoll1_a, "type111")
     self.type111.set_values(
         recordtype_create_values(type_id="type111",
                                  type_uri="test:type111",
                                  supertype_uris=["test:type11"]))
     self.type12 = RecordType(self.testcoll1_a, "type12")
     self.type12.set_values(
         recordtype_create_values(type_id="type12",
                                  type_uri="test:type12",
                                  supertype_uris=["test:type1"]))
     self.type2 = RecordType(self.testcoll1_a, "type2")
     self.type2.set_values(
         recordtype_create_values(type_id="type2",
                                  type_uri="test:type2",
                                  supertype_uris=[]))
     self.type21 = RecordType(self.testcoll1_a, "type21")
     self.type21.set_values(
         recordtype_create_values(type_id="type21",
                                  type_uri="test:type21",
                                  supertype_uris=["test:type2"]))
     self.type22 = RecordType(self.testcoll1_a, "type22")
     self.type22.set_values(
         recordtype_create_values(type_id="type22",
                                  type_uri="test:type22",
                                  supertype_uris=["test:type2"]))
     return
def am_copycollection(annroot, userhome, options):
    """
    Copy collection data

        annalist_manager copycollection old_coll_id new_coll_id

    Copies data from an existing collection to a new collection.

    annroot     is the root directory for the Annalist software installation.
    userhome    is the home directory for the host system user issuing the command.
    options     contains options parsed from the command line.

    returns     0 if all is well, or a non-zero status code.
                This value is intended to be used as an exit status code
                for the calling program.
    """
    status, settings, site = get_settings_site(annroot, userhome, options)
    if status != am_errors.AM_SUCCESS:
        return status
    if len(options.args) > 2:
        print("Unexpected arguments for %s: (%s)" %
              (options.command, " ".join(options.args)),
              file=sys.stderr)
        return am_errors.AM_UNEXPECTEDARGS
    old_coll_id = getargvalue(getarg(options.args, 0), "Old collection Id: ")
    old_coll = Collection.load(site, old_coll_id)
    if not (old_coll and old_coll.get_values()):
        print("Old collection not found: %s" % (old_coll_id), file=sys.stderr)
        return am_errors.AM_NOCOLLECTION
    new_coll_id = getargvalue(getarg(options.args, 1), "New collection Id: ")
    new_coll = Collection.load(site, new_coll_id)
    if (new_coll and new_coll.get_values()):
        print("New collection already exists: %s" % (new_coll_id),
              file=sys.stderr)
        return am_errors.AM_COLLECTIONEXISTS
    # Copy collection now
    print("Copying collection '%s' to '%s'" % (old_coll_id, new_coll_id))
    new_coll = site.add_collection(new_coll_id, old_coll.get_values())
    msgs = copy_coll_data(old_coll, new_coll)
    if msgs:
        for msg in msgs:
            print(msg)
        status = am_errors.AM_COPYCOLLFAIL
    print("")
    return status
Example #17
0
def init_annalist_test_site():
    log.debug("init_annalist_test_site")
    copySitedata(
        settings.SITE_SRC_ROOT + "/sampledata/testinit/" +
        test_layout.SITE_DIR,
        settings.SITE_SRC_ROOT + "/annalist/data/sitedata", TestBaseDir)
    testsite = Site(TestBaseUri, TestBaseDir)
    testsite.generate_site_jsonld_context()
    Collection.flush_all_caches()
    # Reset id generator counters
    EntityData._last_id = 0
    RecordType._last_id = 0
    RecordView._last_id = 0
    RecordList._last_id = 0
    RecordField._last_id = 0
    RecordVocab._last_id = 0
    AnnalistUser._last_id = 0
    return testsite
 def test_set_alt_entities_loop(self):
     altcoll1  = Collection(self.testsite, "altcoll1")
     parents   = self.testcoll.set_alt_entities(altcoll1)
     parentids = [ p.get_id() for p in parents ]
     self.assertEqual( parentids, ["testcoll", "altcoll1", layout.SITEDATA_ID])
     with SuppressLogging(logging.ERROR):
         with self.assertRaises(ValueError):
             parents   = altcoll1.set_alt_entities(self.testcoll)
     return
def am_installcollection(annroot, userhome, options):
    """
    Install software-defined collection data

        annalist_manager installcollection coll_id

    Copies data from an existing collection to a new collection.

    annroot     is the root directory for the Annalist software installation.
    userhome    is the home directory for the host system user issuing the command.
    options     contains options parsed from the command line.

    returns     0 if all is well, or a non-zero status code.
                This value is intended to be used as an exit status code
                for the calling program.
    """
    status, settings, site = get_settings_site(annroot, userhome, options)
    if status != am_errors.AM_SUCCESS:
        return status
    if len(options.args) > 1:
        print("Unexpected arguments for %s: (%s)" %
              (options.command, " ".join(options.args)),
              file=sys.stderr)
        return am_errors.AM_UNEXPECTEDARGS
    coll_id = getargvalue(getarg(options.args, 0),
                          "Collection Id to install: ")
    coll = Collection.load(site, coll_id)
    if (coll and coll.get_values()):
        print("Collection already exists: %s" % (coll_id), file=sys.stderr)
        return am_errors.AM_COLLECTIONEXISTS

    # Check collection Id
    if coll_id in installable_collections:
        src_dir_name = installable_collections[coll_id]['data_dir']
    else:
        print("Collection name to install not known: %s" % (coll_id),
              file=sys.stderr)
        print("Available collection Ids are: %s" %
              (",".join(installable_collections.keys())))
        return am_errors.AM_NOCOLLECTION

    # Install collection now
    src_dir = os.path.join(annroot, "annalist/data", src_dir_name)
    print("Installing collection '%s' from data directory '%s'" %
          (coll_id, src_dir))
    coll_metadata = installable_collections[coll_id]['coll_meta']
    date_time_now = datetime.datetime.now().replace(microsecond=0)
    coll_metadata[ANNAL.CURIE.comment] = (
        "Initialized at %s by `annalist-manager installcollection`" %
        date_time_now.isoformat())
    coll = site.add_collection(coll_id, coll_metadata)
    msgs = initialize_coll_data(src_dir, coll)
    if msgs:
        for msg in msgs:
            print(msg)
        status = am_errors.AM_INSTALLCOLLFAIL
    return status
Example #20
0
 def test_edit_collection_metadata(self):
     # This test performs a GET to retrieve values used in a form,
     # then a POST to save updated collection metadata.
     # This test is intended to test a problem encountered with updated 
     # entity copying logic that needs to take special account of collection
     # entities being presented as offspring of the site while being stored
     # as part of a collection.
     #
     coll_id = "testcoll"
     self.assertTrue(Collection.exists(self.testsite, coll_id))
     c = Collection.load(self.testsite, coll_id)
     self.assertEqual(c.get_id(), coll_id)
     self.assertEqual(c.get_view_url_path(), collection_view_url(coll_id="testcoll"))
     # GET collection metadata form data, and test values
     u = collectiondata_url(coll_id="testcoll")
     r = self.client.get(u)
     self.assertEqual(r.status_code,   200)
     self.assertEqual(r.reason_phrase, "OK")
     self.assertEqual(r.context['coll_id'],          layout.SITEDATA_ID)
     self.assertEqual(r.context['type_id'],          layout.COLL_TYPEID)
     self.assertEqual(r.context['entity_id'],        "testcoll")
     self.assertEqual(r.context['orig_id'],          "testcoll")
     self.assertEqual(r.context['orig_coll'],        layout.SITEDATA_ID)
     self.assertEqual(r.context['action'],           "view")
     self.assertEqual(r.context['continuation_url'], "")
     orig_coll = r.context['orig_coll']
     # Assemble and POST form data to =updated collection metadata
     new_label = "Updated collection metadata"
     f = coll_view_form_data(
         coll_id="testcoll", 
         action="edit", 
         coll_label=new_label,
         # orig_coll="None"
         orig_coll=layout.SITEDATA_ID
         )
     u = collectiondata_view_url(coll_id="testcoll", action="edit")
     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'],   TestBaseUri+"/c/_annalist_site/d/_coll/")
     # Check updated collection data
     self._check_collection_data_values(coll_id="testcoll", coll_label=new_label)
     return
Example #21
0
    def remove_collection(self, coll_id):
        """
        Remove a collection from the site data.

        coll_id     identifier for the collection to remove.

        Returns a non-False status code if the collection is not removed.
        """
        log.debug("remove_collection: %s" % (coll_id))
        return Collection.remove(self, coll_id)
Example #22
0
 def setUp(self):
     init_annalist_test_site()
     self.testsite = Site(TestBaseUri, TestBaseDir)
     self.testcoll = Collection(self.testsite, "testcoll")
     # self.tokenset_context  = self._make_test_context(
     #     ["aa", "bb", "cc"], repeat_prefix="tokprefix_"
     #     )
     self.intvalue_context = self._make_test_context(
         42, repeat_prefix="intprefix_")
     return
Example #23
0
 def setUp(self):
     init_annalist_test_site()
     self.testsite = Site(TestBaseUri, TestBaseDir)
     self.testcoll = Collection(self.testsite, "testcoll")
     self.testcoll1_a = Collection(self.testsite, "testcoll1")
     self.testcoll1_b = Collection(self.testsite, "testcoll1")
     self.testcoll2_a = Collection(self.testsite, "testcoll2")
     self.testcoll2_b = Collection(self.testsite, "testcoll2")
     self.vocabcache = CollectionVocabCache()
     self.vocab1 = RecordVocab(self.testcoll1_a, "vocab1")
     self.vocab1.set_values(
         entitydata_create_values("vocab1",
                                  type_id="_vocab",
                                  entity_uri="test:vocab1"))
     self.vocab2 = RecordVocab(self.testcoll1_a, "vocab2")
     self.vocab2.set_values(
         entitydata_create_values("vocab2",
                                  type_id="_vocab",
                                  entity_uri="test:vocab2"))
     return
Example #24
0
 def setUp(self):
     init_annalist_test_site()
     self.testsite = Site(TestBaseUri, TestBaseDir)
     self.testcoll = Collection.create(self.testsite, "testcoll",
                                       collection_create_values("testcoll"))
     self.annalcoll = Collection.load(self.testsite, layout.SITEDATA_ID)
     self.no_options = [FieldChoice('', label="(no options)")]
     # For checking Location: header values...
     self.continuation_url = (TestHostUri + entitydata_list_type_url(
         coll_id="testcoll", type_id=layout.VOCAB_TYPEID))
     # Login and permissions
     create_test_user(self.testcoll, "testuser", "testpassword")
     create_user_permissions(self.annalcoll,
                             "testuser",
                             user_permissions=["VIEW"])
     self.client = Client(HTTP_HOST=TestHost)
     loggedin = self.client.login(username="******",
                                  password="******")
     self.assertTrue(loggedin)
     return
 def test_alt_parent_inherit_site(self):
     # Test inheritance of definitions from site with an alternative collection set
     coll_id = "newcoll"
     newcoll = Collection.create(self.testsite, coll_id, collection_create_values(coll_id))
     altparents = newcoll.set_alt_entities(self.testcoll)
     parentids  = [ p.get_id() for p in altparents ]
     self.assertEqual(parentids, ["newcoll", "testcoll", layout.SITEDATA_ID])
     self.assertTrue(RecordType.exists(newcoll, "Default_type", altscope="all"))
     def_type = RecordType.load(newcoll, "Default_type", altscope="all")
     self.assertEquals(def_type["rdfs:label"], "Default record")
     return
 def setUp(self):
     init_annalist_test_site()
     self.testsite = Site(TestBaseUri, TestBaseDir)
     self.testcoll = Collection(self.testsite, "testcoll")
     self.testdata = RecordTypeData(self.testcoll, "testtype")
     # Login and permissions
     create_test_user(self.testcoll, "testuser", "testpassword")
     self.client = Client(HTTP_HOST=TestHost)
     loggedin = self.client.login(username="******", password="******")
     self.assertTrue(loggedin)
     return
 def test_collection_init(self):
     log.debug("test_collection_init: TestBaseUri %s, TestBaseDir %s"%(TestBaseUri,TestBaseDir))
     s = Site(TestBaseUri, TestBaseDir)
     c = Collection(s, "testcoll")
     self.assertEqual(c._entitytype,     ANNAL.CURIE.Collection)
     self.assertEqual(c._entityfile,     layout.COLL_META_REF)
     self.assertEqual(c._entityref,      layout.META_COLL_REF)
     self.assertEqual(c._entityid,       "testcoll")
     self.assertEqual(c._entityurl,      TestHostUri + collection_view_url(coll_id="testcoll"))
     self.assertEqual(c._entitydir,      collection_dir(coll_id="testcoll"))
     self.assertEqual(c._values,         None)
     return
Example #28
0
    def remove_collection(self, coll_id):
        """
        Remove a collection from the site data.

        coll_id     identifier for the collection to remove.

        Returns a non-False status code if the collection is not removed.
        """
        log.debug("remove_collection: %s" % (coll_id))
        if coll_id == layout.SITEDATA_ID:
            raise ValueError("Attempt to remove site data collection (%s)" %
                             coll_id)
        return Collection.remove(self, coll_id)
Example #29
0
    def collections(self):
        """
        Generator enumerates and returns collection descriptions that are part of a site.

        Yielded values are collection objects.
        """
        log.debug("site.collections: basedir: %s" % (self._entitydir))
        for f in self._base_children(Collection):
            c = Collection.load(self, f)
            # log.info("Site.colections: Collection.load %s %r"%(f, c.get_values()))
            if c:
                yield c
        return
 def setUp(self):
     # Set up basic site data
     init_annalist_test_site()
     self.testsite = Site(TestBaseUri, TestBaseDir)
     self.testcoll = Collection.create(self.testsite, "testcoll", collection_create_values("testcoll"))
     self.testtype = RecordType.create(self.testcoll, "testtype", recordtype_create_values("testtype"))
     self.testdata = RecordTypeData.create(self.testcoll, "testtype", {})
     # Login and permissions
     create_test_user(self.testcoll, "testuser", "testpassword")
     self.client = Client(HTTP_HOST=TestHost)
     loggedin = self.client.login(username="******", password="******")
     self.assertTrue(loggedin)
     return