Пример #1
0
 def test_save(self):
     for item in self.test_objects:
         self.storage.new(item[2])
     self.storage.save()
     new_storage = FileStorage()
     new_storage._FileStorage__objects = {}
     new_storage._FileStorage__file_path = "atestfile.json"
     new_storage.reload()
     for key in self.storage.all():
         self.assertIn(key, new_storage.all())
Пример #2
0
    def test_file_path(self):
        """Tests that the class attribute is used in the case that
            an instance attribute with the same name as __file_path
            is created"""
        a = FileStorage()
        fake_file = 'fake.json'
        a._FileStorage__file_path = fake_file
        a.save()

        b = BaseModel()
        b.save()
        self.assertEqual(False, os.path.exists(fake_file))
        self.assertEqual(True, os.path.exists('file.json'))