コード例 #1
0
    def test_nested(self):
        """
        Test nesting of objects, with different revisions.
        """

        server = Server()

        server.commit(2)
        server.commit(3)
        server.commit(4)
        server.commit(5)
        server.commit(6)

        database = Database(id=1, name="Database A")

        server.databases.add(database)
        server.databases.remove(database)

        database = Database(id=2, name="Database B")

        item = Item(id=3, name="Item A")
        database.items.add(item)

        server.databases.add(database)
        database.items.add(item)

        self.assertListEqual(server.databases.keys(), [2])
        self.assertListEqual(server.databases(revision=6).keys(), [2])
        self.assertListEqual(server.databases(revision=5).keys(), [])
        self.assertListEqual(server.databases(revision=4).keys(), [])
        self.assertListEqual(server.databases(revision=3).keys(), [])
        self.assertListEqual(server.databases(revision=2).keys(), [])
        self.assertListEqual(server.databases(revision=1).keys(), [])

        with self.assertRaises(KeyError):
            server.databases[1]

        self.assertListEqual(server.databases[2].items.keys(), [3])
        self.assertListEqual(server.databases[2].items(revision=1).keys(), [3])

        with self.assertRaises(ValueError):
            # Item was added to a database that was not in a server before
            # adding.
            self.assertListEqual(
                server.databases[2].items(revision=2).keys(), [3])

        server.commit(7)

        self.assertListEqual(server.databases[2].items.keys(), [3])
        self.assertListEqual(server.databases[2].items(revision=7).keys(), [3])
        self.assertListEqual(server.databases[2].items(revision=6).keys(), [3])
        self.assertListEqual(server.databases[2].items(revision=5).keys(), [3])
        self.assertListEqual(server.databases[2].items(revision=4).keys(), [3])
        self.assertListEqual(server.databases[2].items(revision=3).keys(), [3])
        self.assertListEqual(server.databases[2].items(revision=2).keys(), [3])
        self.assertListEqual(server.databases[2].items(revision=1).keys(), [3])
コード例 #2
0
    def test_store(self):
        """
        Test store references stay the same.
        """

        server = Server()

        database = Database(id=1, name="Database A")
        server.databases.add(database)

        item = Item(id=2, name="Item A")
        database.items.add(item)

        self.assertEqual(
            server.databases.store,
            server.databases(revision=1).store)
        self.assertEqual(
            server.databases[1].items.store,
            server.databases[1].items(revision=1).store)
        self.assertEqual(
            server.databases(revision=1)[1].items.store,
            server.databases[1].items(revision=1).store)
コード例 #3
0
    def test_basis(self):
        """
        Test basic functionality.
        """

        server = Server()
        database = Database(id=1, name="Database A")
        server.databases.add(database)

        self.assertListEqual(server.databases.keys(), [1])

        database = Database(id=2, name="Database B")
        server.databases.add(database)

        self.assertListEqual(server.databases.keys(), [2, 1])

        server.commit(2)
        server.databases.remove(database)
        server.commit(3)

        self.assertListEqual(server.databases.keys(), [1])
        self.assertListEqual(server.databases(revision=2).keys(), [1])
        self.assertListEqual(server.databases(revision=1).keys(), [2, 1])

        with self.assertRaises(KeyError):
            server.databases[2]

        database = Database(id=3, name="Database C")

        server.databases.add(database)
        server.commit(4)

        self.assertListEqual(server.databases.keys(), [3, 1])
        self.assertListEqual(server.databases(revision=3).keys(), [3, 1])
        self.assertListEqual(server.databases(revision=2).keys(), [1])
        self.assertListEqual(server.databases(revision=1).keys(), [2, 1])
コード例 #4
0
    def test_basis(self):
        """
        Test basic functionality.
        """

        server = Server()

        database = Database()
        database.id = 1
        database.name = "Database A"
        server.databases.add(database)

        self.assertEqual(server.databases.keys(), [1])

        database = Database()
        database.id = 2
        database.name = "Database B"
        server.databases.add(database)

        self.assertEqual(server.databases.keys(), [1, 2])

        server.databases.remove(database)

        self.assertEqual(server.databases.keys(), [1])
        self.assertEqual(server.databases(revision=2).keys(), [1, 2])

        with self.assertRaises(KeyError):
            server.databases[2]

        database = Database()
        database.id = 3
        database.name = "Database C"
        server.databases.add(database)

        self.assertEqual(server.databases.keys(), [1, 3])
        self.assertEqual(server.databases(revision=4).keys(), [1, 3])