예제 #1
0
 def test_basic(self):
     """Test for BaseModel
     """
     s = State()
     s.name = "Holberton"
     s.number = 89
     self.assertEqual([s.name, s.number], ["Holberton", 89])
예제 #2
0
 def test_state_dict_to_instance_with_kwargs(self):
     """State can instantiate new object with dictionary"""
     state = State()
     state.name = "Betty"
     state.number = 972
     state_dict = state.to_dict()
     new_state = State(**state_dict)
     new_state_dict = new_state.to_dict()
     self.assertFalse(new_state is state)
     self.assertDictEqual(new_state_dict, state_dict)
예제 #3
0
 def test_attr(self):
     """ Tests creation of new attributes """
     m1 = State()
     m1.name = "John"
     self.assertAlmostEqual(m1.name, "John")
     m1.number = 123
     self.assertAlmostEqual(m1.number, 123)
     self.assertEqual(type(m1.id), str)
     self.assertEqual(type(m1.created_at), datetime.datetime)
     self.assertEqual(type(m1.updated_at), datetime.datetime)
     self.assertEqual(type(m1.name), str)
예제 #4
0
 def test_06a_to_dict_values(self):
     """Test to validate to_dict values are all strings"""
     s = State()
     s.name = "Tu"
     s.number = 1987
     d = s.to_dict()
     self.assertEqual(type(d['name']), str)
     self.assertEqual(type(d['number']), int)
     self.assertEqual(type(d['created_at']), str)
     self.assertEqual(type(d['updated_at']), str)
     self.assertEqual(type(d['id']), str)
     self.assertEqual(type(d['__class__']), str)
예제 #5
0
 def test_06_to_dict(self):
     """Test to validate to_dict is outputting correctly"""
     s = State()
     s.name = "Tu"
     s.number = 1987
     d = s.to_dict()
     self.assertTrue('number' in d)
     self.assertTrue('name' in d)
     self.assertTrue('id' in d)
     self.assertTrue('created_at' in d)
     self.assertTrue('updated_at' in d)
     self.assertTrue('__class__' in d)
예제 #6
0
 def test_to_dict(self):
     """ dictionary conversion test """
     i = State()
     i.name = "Cute_anime_girl"
     i.number = 25
     j = i.to_dict()
     self.assertTrue("name" in j)
     self.assertEqual(type(j["name"]), str)
     self.assertTrue("number" in j)
     self.assertEqual(type(j["number"]), int)
     self.assertTrue("created_at" in j)
     self.assertTrue("updated_at" in j)
     self.assertTrue("id" in j)
예제 #7
0
 def test_07_recreate_instance(self):
     """Test to create instances from to_dict"""
     s = State()
     s.name = "Tim"
     s.number = 1993
     d = s.to_dict()
     new_s = State(**d)
     self.assertEqual(s.id, new_s.id)
     self.assertEqual(s.created_at, new_s.created_at)
     self.assertEqual(s.updated_at, new_s.updated_at)
     self.assertEqual(s.name, new_s.name)
     self.assertEqual(s.number, new_s.number)
     self.assertEqual(type(new_s.id), str)
     self.assertEqual(new_s.created_at.__class__.__name__, "datetime")
예제 #8
0
 def test_reCreate_kwarg(self):
     """Recreate dictionary from saved dictionary"""
     k = State()
     k.name = "Cute_anime_girl"
     k.number = 99
     j = k.to_dict()
     l = State(**j)
     self.assertEqual(k.name, l.name)
     self.assertEqual(k.number, l.number)
     self.assertEqual(k.id, l.id)
     self.assertEqual(k.created_at, l.created_at)
     self.assertEqual(k.updated_at, l.updated_at)
     self.assertEqual(type(k.id), str)
     self.assertFalse(k is j)
예제 #9
0
 def test_03_adding_extra_parameters(self):
     """Test for manually adding parameters to empty BaseModel"""
     s = State()
     s.string = "Tu"
     s.number = 1106
     s.list = [1, 2, 3]
     s.dict = {"a": 1}
     self.assertTrue(hasattr(s, "string"))
     self.assertTrue(hasattr(s, "number"))
     self.assertTrue(hasattr(s, "list"))
     self.assertTrue(hasattr(s, "dict"))
     self.assertEqual(type(s.string), str)
     self.assertEqual(type(s.number), int)
     self.assertEqual(type(s.list), list)
     self.assertEqual(type(s.dict), dict)
예제 #10
0
    def test_5_dict_method(self):
        """test to_dict methods return"""
        model_1 = State()
        model_1.name = "Alejandra"
        model_1.number = 89
        my_model_dict = model_1.to_dict()

        # checks it is a type dictionary
        self.assertEqual(type(my_model_dict), dict)

        # check ISOFORMAT
        date_model1 = model_1.created_at
        str_date = date_model1.strftime("%Y-%m-%dT%H:%M:%S.%f")

        self.assertEqual(my_model_dict['created_at'], str_date)

        # check other key
        self.assertEqual(model_1.name, my_model_dict['name'])