Exemple #1
0
 def test_all_dict(self):
     """
     Test that returns the FileStorage.__objects
     """
     storage = FileStorage()
     new_dict = storage.all()
     self.assertEqual(type(new_dict), dict)
Exemple #2
0
 def test_new(self):
     """
     test that new adds an object
     """
     objects = BaseModel()
     storage = FileStorage()
     storage.new(objects)
     self.assertNotEqual(storage.all(), 0)
 def test_new(self):
     """test that new adds an object to the FileStorage.__objects attr"""
     storage_temp = FileStorage()
     new_dict = storage_temp.all()
     pancho = User()
     pancho.id = 2000
     pancho.name = "Gato"
     storage_temp.new(pancho)
     class_name = pancho.__class__.__name__
     key = "{}.{}".format(class_name, str(Holberton.id))
     self.assertIsNotNone(storage_temp[key])
 def test_new(self):
     """Tests the new method"""
     temp_storage = FileStorage()
     temp_dict = temp_storage.all()
     Dionisio = User()
     Dionisio.id = 1991
     Dionisio.name = "SDVSF"
     temp_storage.new(Dionisio)
     class_name = Dionisio.__class__.__name__
     key = "{}.{}".format(class_name, str(Holberton.id))
     self.assertIsNotNone(temp_dict[key])
Exemple #5
0
 def test_save(self):
     """test save function"""
     objects = BaseModel()
     objects.name = "stranger"
     storage = FileStorage()
     objects.save()
     with open('file.json', 'r') as file:
         dic_json = json.load(file)
     val_dic = dic_json.get("BaseModel.{}".format(objects.id))
     self.assertEqual(val_dic['name'], "stranger")
    def test_has_attr(self):
        """ Method to test File Storage dict attrs """

        meowski = FileStorage()

        self.assertTrue(hasattr(meowski, "all"))
        self.assertTrue(hasattr(meowski, "new"))
        self.assertTrue(hasattr(meowski, "save"))
        self.assertTrue(hasattr(meowski, "reload"))
        self.assertTrue(hasattr(meowski, "__init__"))
    def setUp(self):
        """ Method to set up unittests """
        self.file = 'file.json'

        if os.path.isfile(self.file):
            os.remove(self.file)

        self.meow1 = BaseModel()
        self.meow2 = BaseModel(name="Bre", number="2326")
        self.meow3 = BaseModel(name="Aleia")
        self.meow4 = BaseModel(name=None, id=None, number=None)
        self.meow5 = BaseModel()
        self.storeMeow = FileStorage()
        self.allMeows = models.storage.all()
        self.reloadMeows = models.storage.reload()
Exemple #8
0
 def test_reload(self):
     """test reload"""
     objects = BaseModel()
     storage = FileStorage()
     objects.name = "sober"
     objects.age = 23.45
     objects.save()
     storage._FileStorage__objects = {}
     storage.reload()
     self.assertEqual(storage.all(), {})
 def test_reload(self):
     """Tests the reaload method """
     JohnLen = FileStorage()
     sizeofobj = len(JohnLen._FileStorage.__objects)
     self.assertGreater(sizeofobj, 0)
 def test_3_arguments(self):
     """ test class arguments """
     with self.assertRaises(TypeError) as error:
         instance = FileStorage(1, 2, 3)
     messg = "object() takes no parameters"
     self.assertEqual(str(error.exception), messg)
 def test_all_returns_dict(self):
     """Test that all returns the FileStorage.__objects attr"""
     storage_temp = FileStorage()
     new_dict = storage_temp.all()
     self.assertEqual(type(new_dict), dict)
     self.assertIs(new_dict, storage_temp._FileStorage.__objects)
Exemple #12
0
 def test_file_path(self):
     """test file path"""
     storage = FileStorage()
     self.assertIsInstance(storage._FileStorage__file_path, str)
Exemple #13
0
 def test_objects(self):
     """test if objects exists"""
     storage = FileStorage()
     self.assertIsInstance(storage._FileStorage__objects, dict)
 def test_instantiation(self):
     """Tests for proper instantiation"""
     temp_storage = FileStorage()
     self.assertIsInstance(temp_storage, FileStorage)
 def test_all(self):
     """Tests the all method"""
     temp_storage = FileStorage()
     temp_dict = temp_storage.all()
     self.assertIsNotNone(temp_dict)
     self.assertEqual(type(temp_dict), dict)
    def test_new_inst_attr(self):
        """ Method to test if instance of file storage inherits attr """

        self.storeMeow = FileStorage()
        self.assertTrue(hasattr(self.storeMeow, "_FileStorage__objects"))
        self.assertTrue(hasattr(self.storeMeow, "_FileStorage__file_path"))
 def test_reload(self):
     """Tests the reaload method """
     Dionisio = FileStorage()
     sizeofobj = len(Dionisio._FileStorage__objects)
     self.assertGreater(sizeofobj, 0)