def test_will_update_on_index(self):
     obj_store = ObjectStore(indexes=['type1:index1', 'type1:index2'])
     self._test_set_and_lookup(obj_store)
     obj = self.values[277]
     obj['index1'] = '123456789'
     # Can change an indexed value if it is unique
     obj_store.set(self.names[277], obj)
     self.assertEqual(obj_store.lookup('type1:index1', '123456789'),
                      obj, "Can lookup on indexed value that has"
                      " been updated.")
Esempio n. 2
0
 def test_will_update_on_index(self):
     obj_store = ObjectStore(indexes=['type1:index1', 'type1:index2'])
     self._test_set_and_lookup(obj_store)
     obj = self.values[277]
     obj['index1'] = '123456789'
     # Can change an indexed value if it is unique
     obj_store.set(self.names[277], obj)
     self.assertEqual(obj_store.lookup('type1:index1', '123456789'),
                      obj, "Can lookup on indexed value that has"
                      " been updated.")
 def test_update(self):
     obj1 = {'object-type': 'type1', 'index1': self.index1s[126],
             'index2': self.index2s[126], 'count': 5}
     obj2 = {'object-type': 'type1', 'index1': self.index1s[126],
             'index2': self.index2s[126], 'count': 8}
     obj_store = ObjectStore(indexes=['type1:index1', 'type1:index2'])
     obj_store.set('obj1', obj1)
     obj_store.set('obj1', obj2)
     self.assertEqual(obj_store.lookup('type1:index1', self.index1s[126]),
                      obj2, "Lookup on index of updated value will find"
                      "updated value")
     self.assertEqual(obj_store.get('obj1'), obj2,
                      ".get will also get us the updated value")
Esempio n. 4
0
 def test_update(self):
     obj1 = {'object-type': 'type1', 'index1': self.index1s[126],
             'index2': self.index2s[126], 'count': 5}
     obj2 = {'object-type': 'type1', 'index1': self.index1s[126],
             'index2': self.index2s[126], 'count': 8}
     obj_store = ObjectStore(indexes=['type1:index1', 'type1:index2'])
     obj_store.set('obj1', obj1)
     obj_store.set('obj1', obj2)
     self.assertEqual(obj_store.lookup('type1:index1', self.index1s[126]),
                      obj2, "Lookup on index of updated value will find"
                      "updated value")
     self.assertEqual(obj_store.get('obj1'), obj2,
                      ".get will also get us the updated value")
    def test_late_indexing_update(self):
        obj1 = {'object-type': 'type1', 'index1': self.index1s[126],
                'index2': self.index2s[126], 'name': 'obj1'}

        obj2 = {'object-type': 'type1', 'index1': self.index1s[126],
                'index2': self.index2s[126], 'name': 'obj1'}
        obj_store = ObjectStore()
        obj_store.set('obj1', obj1)
        obj_store.set('obj1', obj2)
        self.assertEqual(obj_store.lookup('type1:index2', self.index2s[126]),
                         obj2, "Late indexing will provide us with the "
                         "updated value")
        self.assertEqual(obj_store.get('obj1'), obj2,
                         ".get will also get us the updated value")
Esempio n. 6
0
    def test_late_indexing_update(self):
        obj1 = {'object-type': 'type1', 'index1': self.index1s[126],
                'index2': self.index2s[126], 'name': 'obj1'}

        obj2 = {'object-type': 'type1', 'index1': self.index1s[126],
                'index2': self.index2s[126], 'name': 'obj1'}
        obj_store = ObjectStore()
        obj_store.set('obj1', obj1)
        obj_store.set('obj1', obj2)
        self.assertEqual(obj_store.lookup('type1:index2', self.index2s[126]),
                         obj2, "Late indexing will provide us with the "
                         "updated value")
        self.assertEqual(obj_store.get('obj1'), obj2,
                         ".get will also get us the updated value")
    def test_dup_key_late_indexing(self):
        """
        ._build_index will index the first set value with that key

        """
        obj1 = {'index1': '12345', 'index2': self.index2s[114],
                'object-type': 'type1'}

        obj_store = ObjectStore()
        obj_store.set('obj1', obj1)
        for val in self.values:
            val['index1'] = '12345'
            obj_store.set('obj2', val)

        self.assertEqual(obj_store.lookup('type1:index1', '12345'),
                         obj1, "Lookup by non-unique late-indexed"
                         "value will get the first one set")
Esempio n. 8
0
    def test_dup_key_late_indexing(self):
        """
        ._build_index will index the first set value with that key

        """
        obj1 = {'index1': '12345', 'index2': self.index2s[114],
                'object-type': 'type1'}

        obj_store = ObjectStore()
        obj_store.set('obj1', obj1)
        for val in self.values:
            val['index1'] = '12345'
            obj_store.set('obj2', val)

        self.assertEqual(obj_store.lookup('type1:index1', '12345'),
                         obj1, "Lookup by non-unique late-indexed"
                         "value will get the first one set")
    def test_unique_constraint(self):
        obj1 = {'index1': '12345', 'index2': self.index2s[114],
                'object-type': 'type1'}
        obj2 = {'index1': '12345', 'index2': self.index2s[125],
                'object-type': 'type1'}

        obj_store = ObjectStore(indexes=['type1:index1', 'type1:index2'])
        obj_store.set('obj1', obj1)

        def set_a_value_with_not_unique_key(*args, **kwargs):
            store = args[0]
            store.set('obj2', obj2)

        self.assertRaises(UniqueConstraintError,
                          set_a_value_with_not_unique_key,
                          obj_store,
                          "Setting a value with nonunique indexed "
                          "key raises an error")
Esempio n. 10
0
    def test_unique_constraint(self):
        obj1 = {'index1': '12345', 'index2': self.index2s[114],
                'object-type': 'type1'}
        obj2 = {'index1': '12345', 'index2': self.index2s[125],
                'object-type': 'type1'}

        obj_store = ObjectStore(indexes=['type1:index1', 'type1:index2'])
        obj_store.set('obj1', obj1)

        def set_a_value_with_not_unique_key(*args, **kwargs):
            store = args[0]
            store.set('obj2', obj2)

        self.assertRaises(UniqueConstraintError,
                          set_a_value_with_not_unique_key,
                          obj_store,
                          "Setting a value with nonunique indexed "
                          "key raises an error")