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)
 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 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)
 def from_hash(self, obj):
     """Convert the hash into the object."""
     super(TransactionKeyValue, self).from_hash(obj)
     if 'transaction_id' in obj:
         self.transaction = Transactions.get(Transactions.id == obj['transaction_id'])
     if 'value_id' in obj:
         self.value = Values.get(Values.id == obj['value_id'])
     if 'key_id' in obj:
         self.key = Keys.get(Keys.id == obj['key_id'])
Example #5
0
 def from_hash(self, obj):
     """Convert the hash into the object."""
     super(FileKeyValue, self).from_hash(obj)
     if 'file_id' in obj:
         self.file = Files.get(Files.id == obj['file_id'])
     if 'key_id' in obj:
         self.key = Keys.get(Keys.id == obj['key_id'])
     if 'value_id' in obj:
         self.value = Values.get(Values.id == obj['value_id'])
 def from_hash(self, obj):
     """
     Converts the hash into the object
     """
     super(TransactionKeyValue, self).from_hash(obj)
     if 'transaction_id' in obj:
         self.transaction = Transactions.get(Transactions.id == obj['transaction_id'])
     if 'value_id' in obj:
         self.value = Values.get(Values.id == obj['value_id'])
     if 'key_id' in obj:
         self.key = Keys.get(Keys.id == obj['key_id'])
 def from_hash(self, obj):
     """
     Converts the hash into the object
     """
     super(FileKeyValue, self).from_hash(obj)
     if 'file_id' in obj:
         self.file = Files.get(Files.id == obj['file_id'])
     if 'key_id' in obj:
         self.key = Keys.get(Keys.id == obj['key_id'])
     if 'value_id' in obj:
         self.value = Values.get(Values.id == obj['value_id'])
 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'])
 def where_clause(self, kwargs):
     """Where clause for the various elements."""
     where_clause = super(TransactionKeyValue, self).where_clause(kwargs)
     if 'transaction_id' in kwargs:
         trans = Transactions.get(Transactions.id == kwargs['transaction_id'])
         where_clause &= Expression(TransactionKeyValue.transaction, OP.EQ, trans)
     if 'key_id' in kwargs:
         key = Keys.get(Keys.id == kwargs['key_id'])
         where_clause &= Expression(TransactionKeyValue.key, OP.EQ, key)
     if 'value_id' in kwargs:
         value = Values.get(Values.id == kwargs['value_id'])
         where_clause &= Expression(TransactionKeyValue.value, OP.EQ, value)
     return where_clause
Example #10
0
 def where_clause(self, kwargs):
     """Where clause for the various elements."""
     where_clause = super(FileKeyValue, self).where_clause(kwargs)
     if 'file_id' in kwargs:
         file_ = Files.get(Files.id == kwargs['file_id'])
         where_clause &= Expression(FileKeyValue.file, OP.EQ, file_)
     if 'key_id' in kwargs:
         key = Keys.get(Keys.id == kwargs['key_id'])
         where_clause &= Expression(FileKeyValue.key, OP.EQ, key)
     if 'value_id' in kwargs:
         value = Values.get(Values.id == kwargs['value_id'])
         where_clause &= Expression(FileKeyValue.value, OP.EQ, value)
     return where_clause
 def where_clause(self, kwargs):
     """
     Where clause for the various elements.
     """
     where_clause = super(TransactionKeyValue, self).where_clause(kwargs)
     if 'transaction_id' in kwargs:
         trans = Transactions.get(Transactions.id == kwargs['transaction_id'])
         where_clause &= Expression(TransactionKeyValue.transaction, OP.EQ, trans)
     if 'key_id' in kwargs:
         key = Keys.get(Keys.id == kwargs['key_id'])
         where_clause &= Expression(TransactionKeyValue.key, OP.EQ, key)
     if 'value_id' in kwargs:
         value = Values.get(Values.id == kwargs['value_id'])
         where_clause &= Expression(TransactionKeyValue.value, OP.EQ, value)
     return where_clause
 def where_clause(self, kwargs):
     """
     Where clause for the various elements.
     """
     where_clause = super(FileKeyValue, self).where_clause(kwargs)
     if 'file_id' in kwargs:
         file_ = Files.get(Files.id == kwargs['file_id'])
         where_clause &= Expression(FileKeyValue.file, OP.EQ, file_)
     if 'key_id' in kwargs:
         key = Keys.get(Keys.id == kwargs['key_id'])
         where_clause &= Expression(FileKeyValue.key, OP.EQ, key)
     if 'value_id' in kwargs:
         value = Values.get(Values.id == kwargs['value_id'])
         where_clause &= Expression(FileKeyValue.value, OP.EQ, value)
     return where_clause
 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)
Example #14
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)
 def test_primary_keys_with_keys(self):
     """Test the method to check primary keys with Keys."""
     check_list = Keys.get_primary_keys()
     self.assertTrue(isinstance(check_list, list))
     self.assertTrue(len(check_list) == 1)
     self.assertTrue('id' in check_list)