def setUp(self):
        new_database = Work(primary_redis=test_redis,
                            description="A new database of Art and Artists",
                            title={"rda:preferredTitleOfWork":"Art and Artists",
                                   "rda:varientTitle":["Art's Aritists"]})

        new_database.save()
        self.db_redis_key = new_database.redis_key
        new_db_instance = Instance(primary_redis=test_redis,
                                   instanceOf=new_database.redis_key,
                                   uri="http://ArtAndArtists.html")
        new_db_instance.save()
        setattr(new_database,"bibframe:Instances",new_db_instance.redis_key)
        new_database.save()
def legacy_load_databases_json():
    subject_dict = {}
    alt_title_dict = {}
    for row in subjects:
        subject_dict[row['pk']] = {"name":row['fields']['name']}
        new_topic = TopicalConcept(redis_datastore=REDIS_DATASTORE,
                                   description="Topic Used for Database-by-Subject view in dbfinder",
                                   label=row['fields']['name'])
        new_topic.save()
        subject_dict[row['pk']]["redis_key"] = new_topic.redis_key
        REDIS_DATASTORE.sadd("dbfinder:subjects", new_topic.redis_key) 
    for row in alt_titles:
        db_key = row['fields']['database']
        if alt_title_dict.has_key(db_key):
            alt_title_dict[db_key].append(row['fields']['title'])
        else:
            alt_title_dict[db_key] = [row['fields']['title'],]
    for i,row in enumerate(databases):
        db_pk = row['pk']
        description = row['fields']['description']
        title = row['fields']['title']
        new_work = Work(redis_datastore=REDIS_DATASTORE,
                        description=description,
                        title={'rda:preferredTitleForTheWork':title})
        if alt_title_dict.has_key(db_pk):
            new_work.varientTitle = []
            for alt_title in alt_title_dict[db_pk]:
                new_work.varientTitle.append(alt_title)
            new_work.varientTitle = set(new_work.varientTitle)
        new_work.save()
        subject_keys = []
        for subject_id in row['fields']['subjects']:
           subject_name = subject_dict[subject_id].get("name",None)
           if subject_name is not None:
               subject_keys.append(subject_dict[subject_id].get("redis_key"))
               REDIS_DATASTORE.sadd("dbfinder:subject:{0}".format(subject_name),
                                    new_work.redis_key)
        if len(subject_keys) > 0:
            new_work.subject = set(subject_keys)
        new_work.save()
        alpha_redis_key = "dbfinder:alpha:{0}".format(title[0].upper())
        REDIS_DATASTORE.sadd(alpha_redis_key,
                             new_work.redis_key)
        REDIS_DATASTORE.sadd("dbfinder:alphas",alpha_redis_key)
        new_instance = Instance(redis_datastore=REDIS_DATASTORE,
                                instanceOf=new_work.redis_key,
                                uri=row['fields']['url'])
        new_instance.save()
        REDIS_DATASTORE.sadd("{0}:bibframe:Instances".format(new_work.redis_key),
                                 new_instance.redis_key)
        print("Added {0}".format(title))
 def setUp(self):
     db_1 = Work(primary_redis=test_redis,
                 description="Chemistry Abstracts is a citation database focusing on Chemistry peer-reviewed articles",
                 title="Chemistry Abstracts",
                 uri="http://chemabstracts.com")
     db_1.save()
     test_redis.sadd("dbfinder:alpha:C",db_1.redis_key)
     test_redis.sadd("dbfinder:alphas","dbfinder:alpha:C")
     test_redis.sadd("dbfinder:subjects:Chemistry",db_1.redis_key)
     test_redis.sadd("dbfinder:subjects","dbfinder:subjects:Chemistry")
     db_2 = Work(primary_redis=test_redis,
                 description="Philosophy and Religion Today contains historical and current articles related to the Philosophy of Religion",
                 title="Philosophy and Religion",
                 uri="http://www.philosophy_religion.net")
     db_2.save()
     test_redis.sadd("dbfinder:alpha:P",db_2.redis_key)
     test_redis.sadd("dbfinder:alphas","dbfinder:alpha:P")
     test_redis.sadd("dbfinder:subjects:Philosophy",db_2.redis_key)
     test_redis.sadd("dbfinder:subjects","dbfinder:subjects:Philosophy")