def base_create_dep_objs(cls):
     """Create all objects that FileKeyValue need."""
     keys = Keys()
     TestKeys.base_create_dep_objs()
     keys.from_hash(SAMPLE_KEY_HASH)
     keys.save(force_insert=True)
     values = Values()
     TestValues.base_create_dep_objs()
     values.from_hash(SAMPLE_VALUE_HASH)
     values.save(force_insert=True)
     files = Files()
     TestFiles.base_create_dep_objs()
     files.from_hash(SAMPLE_FILE_HASH)
     files.save(force_insert=True)
Ejemplo n.º 2
0
 def base_create_dep_objs(cls):
     """Create all objects that TransactionKeyValue need."""
     trans = Transactions()
     keys = Keys()
     values = Values()
     TestTransactions.base_create_dep_objs()
     trans.from_hash(SAMPLE_TRANSACTION_HASH)
     trans.save(force_insert=True)
     TestKeys.base_create_dep_objs()
     keys.from_hash(SAMPLE_KEY_HASH)
     keys.save(force_insert=True)
     TestValues.base_create_dep_objs()
     values.from_hash(SAMPLE_VALUE_HASH)
     values.save(force_insert=True)
Ejemplo n.º 3
0
 def test_set_or_create(self):
     """Test the internal set or create method."""
     key = '{"_id": 4096, "key": "bigger"}'
     obj = Keys()
     # pylint: disable=protected-access
     obj._set_or_create(key)
     keys = '[{"_id": 4097, "key": "blah"}]'
     obj._set_or_create(keys)
     obj._set_or_create(key)
     hit_exception = False
     try:
         obj._set_or_create('{ bad json }')
     except ValueError:
         hit_exception = True
     self.assertTrue(hit_exception)
     obj._meta.database.close()
 def test_hash_list_with_keys(self):
     """Test method to check the results of available hash list."""
     sample_key1 = {'_id': 127, 'key': 'proposal', 'encoding': 'UTF8'}
     sample_key2 = {'_id': 128, 'key': 'proposal', 'encoding': 'UTF8'}
     sample_key3 = {'_id': 130, 'key': 'proposal', 'encoding': 'UTF8'}
     with test_database(SqliteDatabase(':memory:'), [Keys]):
         self.base_create_obj(Keys, sample_key1)
         self.base_create_obj(Keys, sample_key2)
         self.base_create_obj(Keys, sample_key3)
         third_obj = Keys()
         hash_list, hash_dict = third_obj.available_hash_list()
         self.assertTrue(len(hash_list) == 3)
         # some sanity checking for the layout of the two objects
         for hashed_key in hash_list:
             self.assertTrue(hashed_key in hash_dict)
             obj_key_meta = hash_dict[hashed_key]
             self.assertTrue('index_hash' in obj_key_meta)
             self.assertTrue('key_list' in obj_key_meta)
             self.assertTrue('id' in obj_key_meta['key_list'])
             self.assertTrue(hashed_key == obj_key_meta['index_hash'])