예제 #1
0
 def test_db_wildcard_query(self):
     random_id = create_unique_hash()
     test_obj = {"random_id": random_id}
     self.database.set(self.collection, test_obj)
     wildcard_query_obj = {"random_id": {"$regex": "%s" % random_id[:10]}}
     results = self.database.query(self.collection, wildcard_query_obj)
     assert len(results) == 1
     assert results[0].get('random_id') == random_id
예제 #2
0
 def create(self, datmo_entity):
     # translate datmo_entity to a standard dictionary (document) to be stored
     if hasattr(datmo_entity, 'to_dictionary'):
         dict_obj = datmo_entity.to_dictionary()
     else:
         dict_obj = self.entity_class(datmo_entity).to_dictionary()
     # create a unique hash from misc_functions.py
     # TODO: find efficient way to get previous hash for entity
     # latest_entity = self.query({"id": latest})
     # dict_obj['id'] = create_unique_hash(base_hash=latest_entity['id'])
     dict_obj['id'] = dict_obj['id'] if 'id' in dict_obj.keys() and dict_obj['id'] else \
         create_unique_hash()
     response = self.driver.set(self.collection, dict_obj)
     entity_instance = self.entity_class(response)
     return entity_instance
예제 #3
0
    def test_create_unique_hash(self):
        result_hash_1 = create_unique_hash()
        result_hash_2 = create_unique_hash()

        assert result_hash_1 != result_hash_2