Exemple #1
0
    def test_update(self):
        """Test that a database will commit both inserts and deletes using the
        update method.
        """
        db = IndexedDatabase(os.path.join(self._temp_dir, 'test_db'),
                             _serialize_tuple,
                             _deserialize_tuple,
                             indexes={'name': lambda tup: [tup[1].encode()]},
                             flag='c',
                             _size=1024**2)

        db.put('1', (1, "foo", "bar"))
        db.put('2', (2, "alice", "Alice's data"))
        db.put('3', (3, "bob", "Bob's data"))

        db.update([('4', (4, 'charlie', "Charlie's data"))], ['1'])

        self.assertEqual(['2', '3', '4'], db.keys())
Exemple #2
0
    def test_update(self):
        """Test that a database will commit both inserts and deletes using the
        update method.
        """
        db = IndexedDatabase(
            os.path.join(self._temp_dir, 'test_db'),
            _serialize_tuple,
            _deserialize_tuple,
            indexes={'name': lambda tup: [tup[1].encode()]},
            flag='c',
            _size=1024**2)

        db.put('1', (1, "foo", "bar"))
        db.put('2', (2, "alice", "Alice's data"))
        db.put('3', (3, "bob", "Bob's data"))

        db.update([('4', (4, 'charlie', "Charlie's data"))], ['1'])

        self.assertEqual(['2', '3', '4'], db.keys())
Exemple #3
0
    def test_update_replace_index(self):
        """Test that update will properly update insert records that have
        the same index value of a deleted record.
        - insert items should be added
        - inserted items index should be correct
        - deleted items should be removed
        """
        db = IndexedDatabase(os.path.join(self._temp_dir, 'test_db'),
                             _serialize_tuple,
                             _deserialize_tuple,
                             indexes={'name': lambda tup: [tup[1].encode()]},
                             flag='c',
                             _size=1024**2)
        db.put('1', (1, "foo", "bar"))
        db.put('2', (2, "alice", "Alice's data"))
        db.put('3', (3, "bob", "Bob's data"))

        db.update([('4', (4, 'foo', "foo's data"))], ['1'])

        self.assertEqual(['2', '3', '4'], db.keys())
        self.assertEqual((4, 'foo', "foo's data"), db.get('foo', index='name'))
Exemple #4
0
    def test_update_replace_index(self):
        """Test that update will properly update insert records that have
        the same index value of a deleted record.
        - insert items should be added
        - inserted items index should be correct
        - deleted items should be removed
        """
        db = IndexedDatabase(
            os.path.join(self._temp_dir, 'test_db'),
            _serialize_tuple,
            _deserialize_tuple,
            indexes={'name': lambda tup: [tup[1].encode()]},
            flag='c',
            _size=1024**2)
        db.put('1', (1, "foo", "bar"))
        db.put('2', (2, "alice", "Alice's data"))
        db.put('3', (3, "bob", "Bob's data"))

        db.update([('4', (4, 'foo', "foo's data"))], ['1'])

        self.assertEqual(['2', '3', '4'], db.keys())
        self.assertEqual(
            (4, 'foo', "foo's data"),
            db.get('foo', index='name'))