示例#1
0
class DatabaseSaveAndFindTests(unittest.TestCase):
    def setUp(self):
        self.db = Database()
    def test_object_lookup(self):
        self.db.store(DatabaseObject(1))
        object_1 = self.db.find(1)
        self.assertEqual(object_1.ref, 1)

    def test_object_lookup_bad_object(self):
        object_1 = self.db.find(1)
        self.assertIsNone(object_1)

    def test_object_save_multiple(self):
        object_1 = DatabaseObject(1)
        self.db.store(object_1)
        found_object = self.db.find(1)
        self.assertEqual(found_object.ref, object_1.ref)

        object_2 = DatabaseObject(2)
        self.db.store(object_2)
        found_object = self.db.find(2)
        self.assertEqual(found_object.ref, object_2.ref)

    def test_stored_and_found_objects_are_same_object(self):
        db = Database()
        object_1 = DatabaseObject(1)
        object_1.name = "Random Object Name"
        db.store(object_1)
        object_2 = db.find(1)
        object_2.name = "Specific name"
        self.assertEqual(object_1.name, object_2.name)
        self.assertEqual(object_1.name, 'Specific name')
示例#2
0
 def test_stored_and_found_objects_are_same_object(self):
     db = Database()
     object_1 = DatabaseObject(1)
     object_1.name = "Random Object Name"
     db.store(object_1)
     object_2 = db.find(1)
     object_2.name = "Specific name"
     self.assertEqual(object_1.name, object_2.name)
     self.assertEqual(object_1.name, 'Specific name')
示例#3
0
    def test_persistance_between_dump_load(self):
        db = Database()
        pre_object = DatabaseObject(1)
        pre_object.name = "Michael"
        db.store(pre_object)
        persistance = DatabasePersister(self.file_name)

        persistance.dump(db)
        db = persistance.load()
        object = db.find(1)
        self.assertEqual(object.ref, 1)
        self.assertEqual(object.name, 'Michael')
示例#4
0
    def test_persistance_of_object_structure_data(self):
        db = Database()
        pre_object = DatabaseObject(1)
        pre_object.name = "Michael"
        pre_object.type = DB_TYPE_PLAYER

        db.store(pre_object)
        persistance = DatabasePersister(self.file_name)
        persistance.dump(db)
        db = persistance.load()
        object = db.find(1)
        self.assertEqual(object.name, 'Michael')
        self.assertEqual(object.type, DB_TYPE_PLAYER)
示例#5
0
 def test_old_db_is_overwritten(self):
     db = Database()
     pre_object = DatabaseObject(2)
     pre_object.name = "Michael"
     db.store(pre_object)
     db.store(DatabaseObject(5))
     persistance = DatabasePersister(self.file_name)
     persistance.dump(db)
     persistance = DatabasePersister(self.file_name)
     db = persistance.load()
     self.assertIsNone(db.find(1))
示例#6
0
 def setUp(self):
     self.db = Database()