コード例 #1
0
    def test_instanceattributes(self):
        """Tests storage for attributes"""

        Storage = FileStorage()
        Storage.reset()
        self.assertTrue(hasattr(Storage, "_FileStorage__file_path"))
        self.assertTrue(hasattr(Storage, "_FileStorage__objects"))
コード例 #2
0
 def test_02_working_save(self):
     """Test to validate save works."""
     fs = FileStorage()
     fs.reset()
     fs.new(BaseModel())
     fs.save()
     self.assertTrue(os.path.isfile("file.json"))
コード例 #3
0
 def test_01a_all_return_type(self):
     """Test to validate all() returns an empty dict"""
     fs = FileStorage()
     fs.reset()
     self.assertFalse(fs.all())
     fs.new(BaseModel())
     self.assertTrue(fs.all())
コード例 #4
0
 def test_save(self):
     """Tests the save method of File Storage class"""
     Storage = FileStorage()
     Storage.reset()
     b1 = BaseModel()
     Storage.new(b1)
     self.assertFalse(path.exists("file.json"))
     Storage.save()
     self.assertTrue(path.exists("file.json"))
コード例 #5
0
 def test_savebyreadingfile(self):
     """Tests the save method by reading file"""
     Storage = FileStorage()
     Storage.reset()
     b1 = BaseModel()
     Storage.new(b1)
     Storage.save()
     with open("file.json", "r", encoding='utf-8') as r:
         content = r.read()
         self.assertTrue("BaseModel.{}".format(b1.id) in content)
コード例 #6
0
 def test_reset(self):
     """ Tests if the reset method empties the database
     """
     storage = FileStorage()
     storage.reload()
     jur1 = Jurisdiction(**{"name": "Cauca", "victims": 3})
     storage.save()
     storage.reset()
     data = storage.all()
     self.assertTrue(data == {})
コード例 #7
0
 def test_03a_working_reload(self):
     """Checks reload functionality if file_path doesn't exist"""
     fs = FileStorage()
     b = BaseModel()
     key = "BaseModel" + '.' + b.id
     fs.new(b)
     fs.save()
     fs.reset()
     fs.reload()
     self.assertTrue(fs.all()[key])
コード例 #8
0
 def test_reload_2(self):
     '''Tests reload normal'''
     Storage = FileStorage()
     b1 = BaseModel()
     Storage.new(b1)
     Storage.save()
     Storage.reset()
     Storage.reload()
     self.assertTrue(Storage.all()["BaseModel.{}".format(b1.id)])
     self.assertTrue(Storage._FileStorage__objects["BaseModel.{}".format(
         b1.id)])
コード例 #9
0
 def test_reloadbyclearingdictionary(self):
     """Tests the reload method of File Storage class"""
     Storage = FileStorage()
     b1 = BaseModel()
     Storage.new(b1)
     olddict = Storage.all()
     Storage.save()
     Storage.reset()
     Storage.reload()
     newdict = Storage.all()
     for key, value in olddict.items():
         self.assertTrue(key in newdict)
コード例 #10
0
 def test_json_reload_times(self):
     '''Tests updated and created are same for json'''
     f1 = FileStorage()
     b1 = BaseModel()
     f1.reset()
     f1.new(b1)
     bcreate = datetime.isoformat(b1.created_at)
     bupdate = datetime.isoformat(b1.updated_at)
     f1.save()
     with open("file.json", "r", encoding='utf-8') as f:
         content = f.read()
         self.assertTrue(bcreate in content)
         self.assertTrue(bupdate in content)
コード例 #11
0
 def test_attributes(self):
     '''Tests storage for attributes'''
     Storage = FileStorage()
     Storage.reset()
     self.assertTrue(hasattr(FileStorage, "_FileStorage__file_path"))
     self.assertTrue(hasattr(FileStorage, "_FileStorage__objects"))