def test_All(self): """ test all """ fstorage = file_storage.FileStorage() dic = fstorage.all() self.assertIsNotNone(dic) self.assertEqual(type(dic), dict) self.assertIs(dic, fstorage._FileStorage__objects)
def test_storage_all(self): """Test that storage returns the FileStorage.__objects attr""" storage = engine.FileStorage() new_dict = storage.all() self.assertEqual(type(new_dict), dict) # Take name of private attribute from __dict__ self.assertIs(new_dict, storage._FileStorage__objects)
def setUpClass(class_test): """ setup """ class_test.usr = User() class_test.usr.first_name = "Joe" class_test.usr.last_name = "Black" class_test.usr.email = "*****@*****.**" class_test.storage = file_storage.FileStorage()
def test_All(self): """ test all """ astorage = file_storage.FileStorage() instances_dic = astorage.all() self.assertIsNotNone(instances_dic) self.assertEqual(type(instances_dic), dict) self.assertIs(instances_dic, astorage._FileStorage__objects)
def test_reload(self): """Test reload when the file is not present""" storage = engine.FileStorage() try: os.remove("file.json") except Exception: pass fname = "file.json" self.assertFalse(os.path.isfile(fname)) storage.reload()
def test_New(self): """ test new """ fstorage = file_storage.FileStorage() dic = fstorage.all() check = User() check.id = 2112 check.name = "Bob" fstorage.new(check) key = check.__class__.__name__ + "." + str(check.id) self.assertIsNotNone(dic[key])
def test_New(self): """ test new """ nstorage = file_storage.FileStorage() dic = nstorage.all() rev = User() rev.id = 1121 rev.name = "Alexander" nstorage.new(rev) key = rev.__class__.__name__ + "." + str(rev.id) self.assertIsNotNone(dic[key])
def test_new(self): """Test that add an object to the FileStorage instance""" storage = engine.FileStorage() back_up = storage._FileStorage__objects my_base = base.BaseModel() storage._FileStorage__objects = {} new_dict = storage._FileStorage__objects count_new = len(new_dict) count_back_up = len(back_up) self.assertNotEqual(count_new, count_back_up, "Both dictionaries have same number of items")
def test_save_json(self): """Test that save properly saves objects to file.json""" try: os.remove("file.json") except Exception: pass storage = engine.FileStorage() back_up = storage.all() storage.save() # FILE -> json.load() -> <dict> with open("file.json", encoding="utf-8") as fd: json_data = json.load(fd) # <obj> -> <dict> for key in back_up: back_up[key] = back_up[key].to_dict() # compare both back_up and json_data self.assertDictEqual(json_data, back_up)
from models.engine import file_storage from models.base_model import BaseModel from models.amenity import Amenity from models.city import City from models.place import Place from models.review import Review from models.state import State from models.user import User storage = file_storage.FileStorage() storage.reload() CNC = file_storage.FileStorage.CNC
#!/usr/bin/env python3 ''' Initializes module ''' import models.engine.file_storage as fs storage = fs.FileStorage() storage.reload()
#!/usr/bin/python3 """ init """ import models.engine.file_storage as f storage = f.FileStorage() storage.reload()
def test_intance_type(self): """Test that variable storage is a FileStorage instance""" storage = engine.FileStorage() self.assertIsInstance(storage, engine.FileStorage)
def setUpClass(clase): clase.usr = User() clase.usr.first_name = "Jessica" clase.usr.last_name = "Sandoval" clase.usr.email = "*****@*****.**" clase.storage = file_storage.FileStorage()