Exemplo n.º 1
0
    def test_init_no_id(self):
        lookup = Lookup(key='key1', value='value1')

        self.assertIsNotNone(lookup)
        self.assertIsNone(lookup.id)
        self.assertEqual('key1', lookup.key)
        self.assertEqual('value1', lookup.value)
        self.assertEqual({
            'key': 'key1',
            'value': 'value1'
        }, lookup.to_document())
Exemplo n.º 2
0
    def test_from_document(self):
        lookup1 = Lookup.from_document({'key': 'key1', 'value': 'value1'})
        self.assertIsNotNone(lookup1)
        self.assertIsNone(lookup1.id)
        self.assertEqual('key1', lookup1.key)
        self.assertEqual('value1', lookup1.value)

        lookup2 = Lookup.from_document({
            '_id': '666',
            'key': 'key1',
            'value': 'value1'
        })
        self.assertIsNotNone(lookup2)
        self.assertIsNotNone(lookup2.id)
        self.assertEqual('666', lookup2.id)
        self.assertEqual('key1', lookup2.key)
        self.assertEqual('value1', lookup2.value)
Exemplo n.º 3
0
 def add_to_lookup(self, key, value, overwrite_existing=False):
     collection = self.collection()
     lookup = collection.find_one({'key': key})
     if lookup is not None:
         if overwrite_existing is True:
             YLogger.debug(self, "Updating lookup in Mongo [%s] [%s]", key,
                           value)
             lookup['value'] = value
             collection.replace_one({'key': key}, lookup)
         else:
             YLogger.error(self,
                           "Existing value in Mongo lookup [%s] = [%s]",
                           key, value)
             return False
     else:
         YLogger.debug(self, "Adding lookup to Mongo [%s] = [%s]", key,
                       value)
         lookup = Lookup(key, value)
         self.add_document(lookup)
     return True