示例#1
0
    def test_get(self):
        """ tests the get method"""
        storage = FileStorage()
        state_ins = State()
        state_ins.id = 12345
        state_ins.name = 'CA'
        storage.new(state_ins)
        storage.save()
        obj = storage.all()
        for k, v in obj.items():
            if v.id == state_ins.id:
            st = v
        assertEqual(st.name, storage.get("State", 12345))

    def test_count(self):
        """ tests the count method"""
        storage = FileStorage()
        state_ins = State()
        state_ins.id = 12345
        state_ins.name = 'CA'
        storage.new(state_ins)
        storage.save()
        assertEqual(type(storage.count()), int)
        assertIsNotNone(storage.count("State"))
        assertGreater(storage.count("State"), 0)
 def test_change_id(self):
     """
         tests when id is changed manually.
     """
     m1 = State()
     m2 = State()
     m1.id = m2.id
     self.assertEqual(m1.id, m2.id)
 def test_str_return_new_id(self):
     """
         tests that str will update with an updated id.
     """
     m1 = State()
     class_name = "State"
     m1.id = "1"
     m1_dict = str(m1.__dict__)
     str_m1 = "[{}] (1) {}".format(class_name, m1_dict)
     self.assertEqual(str_m1, str(m1))
示例#4
0
 def test_get(self):
     """ Tests DBStorage get method """
     new_state = State()
     new_state.id = '1234'
     new_state.save()
     expected = new_state
     actual = models.storage.get(State, '1234')
     self.assertEqual(expected, actual)
     new_state.delete()
     models.storage.save()
示例#5
0
 def test_str_representation(self):
     dt = datetime.today()
     dt_repr = repr(dt)
     st = State()
     st.id = "123456"
     st.created_at = st.updated_at = dt
     ststr = st.__str__()
     self.assertIn("[State] (123456)", ststr)
     self.assertIn("'id': '123456'", ststr)
     self.assertIn("'created_at': " + dt_repr, ststr)
     self.assertIn("'updated_at': " + dt_repr, ststr)
示例#6
0
 def test_count(self):
     """ tests the count method"""
     storage = FileStorage()
     state_ins = State()
     state_ins.id = 12345
     state_ins.name = 'CA'
     storage.new(state_ins)
     storage.save()
     assertEqual(type(storage.count()), int)
     assertIsNotNone(storage.count("State"))
     assertGreater(storage.count("State"), 0)
示例#7
0
 def test_delete(self):
     """Tests the method delete (obj, called from destroy method)"""
     storage = FileStorage()
     state = State()
     state.id = 123455
     state.name = "Medellin"
     key = state.__class__.__name__ + "." + str(state.id)
     storage.new(state)
     storage.delete(state)
     obj = storage.all()
     self.assertTrue(key not in obj.keys())
示例#8
0
 def test_all_state(self):
     """Tests all method with State class"""
     storage = FileStorage()
     state = State()
     state.name = "Minnesota"
     state.id = "55975"
     storage.new(state)
     obj = storage.all(State)
     key = state.__class__.__name__ + "." + str(state.id)
     self.assertIn(key, obj)
     self.assertIsInstance(obj[key], State)
示例#9
0
 def test_to_dict_output(self):
     dt = datetime.today()
     st = State()
     st.id = "123456"
     st.created_at = st.updated_at = dt
     tdict = {
         'id': '123456',
         '__class__': 'State',
         'created_at': dt.isoformat(),
         'updated_at': dt.isoformat(),
     }
     self.assertDictEqual(st.to_dict(), tdict)
示例#10
0
 def test_delete(self):
     """Tests the method to delete obj from __objects if its inside
     """
     storage = FileStorage()
     state = State()
     state.id = 123455
     state.name = "California"
     key = state.__class__.__name__ + "." + str(state.id)
     storage.new(state)
     storage.delete(state)
     obj = storage.all()
     self.assertTrue(key not in obj.keys())
 def test_all_by_class(self):
     """Tests that it returns the list of objects of one type of class
     """
     state = State()
     state.id = 1234553
     state.name = "California"
     models.storage.new(state)
     models.storage.save()
     key = type(state).__name__ + "." + str(state.id)
     obj = models.storage.all(State)
     self.assertTrue(key in obj.keys())
     self.assertTrue(type(obj[key]) is State)
示例#12
0
 def test_delete_obj(self):
     """Test for delete method"""
     storage = FileStorage()
     state = State()
     state.name = "California"
     state.id = 123123
     storage.new(state)
     obj = storage.all()
     key = state.__class__.__name__ + "." + str(state.id)
     self.assertIn(key, obj)
     storage.delete(state)
     self.assertNotIn(key, obj)
 def test_delete(self):
     """Tests for if an object is deleted in FileStorage"""
     try:
         os.remove("file.json")
     except:
         pass
     storage = FileStorage()
     state = State()
     state.name = "California"
     state.id = "54321"
     state.save()
     self.assertTrue(storage.all(State))
     storage.delete(state)
     self.assertFalse(storage.all(State))
     self.assertNotIsInstance(state.id, dict)
示例#14
0
 def test_id_public(self):
     msj = "Id isn't public"
     my_model1 = State()
     my_model1.id = "HELLO"
     self.assertEqual(my_model1.id, "HELLO")