def test_objects_dict(self): """Tests that the class attribute __objects is used in the case that an instance attribute with the same name has been created""" storage = FileStorage() storage._FileStorage__objects = {} self.assertNotEqual(id(storage._FileStorage__objects), id(storage.all()))
def test_for_reload(self): """test for reload function""" f1 = FileStorage() f2 = BaseModel() key = "BaseModel" + "." + f2.id f1.new(f2) f1.save() f1._FileStorage__objects = {} f1.reload() self.assertTrue(f1.all()[key])
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())
def test_for_save(self): """test for save function""" s = FileStorage() s._FileStorage__objects = {} s.new(BaseModel()) self.assertFalse(os.path.exists("file.json")) s.save() self.assertTrue(os.path.exists("file.json")) with open("file.json", 'r') as f: self.assertEqual(type(f.read()), str) self.assertNotEqual(os.stat("file.json").st_size, 0)