Exemplo n.º 1
0
 def test_created_at_format(self):
     b = BaseModel()
     b.created_at = datetime.datetime(2017, 9, 28, 21, 5, 54, 119427)
     b_dict = b.to_dict()
     real = b_dict["created_at"]
     exp = "2017-09-28T21:05:54.119427"
     self.assertEqual(exp, real)
Exemplo n.º 2
0
    def test_created_at(self):
        """Task 3. BaseModel
        Tests public instance attribute `created_at`.
        """
        # Normal use:
        bm1 = BaseModel()
        test_default_created_at(self, bm1)

        # created_at is public attr, can be manually reassigned
        bm2 = BaseModel()
        bm1.created_at = bm2.created_at
        self.assertEqual(bm1.created_at, bm2.created_at)

        # direct manual reassignment risks invalid format
        bm2.created_at = '1234567890'
        self.assertNotIsInstance(bm2.created_at, datetime.datetime)
Exemplo n.º 3
0
 def test_iso(self):
     base1 = BaseModel()
     cre = upd = datetime.now()
     base1.created_at = cre
     base1.updated_at = upd
     d = base1.to_dict()
     self.assertEqual(d["created_at"], cre.isoformat())
     self.assertEqual(d["updated_at"], upd.isoformat())
Exemplo n.º 4
0
 def test_empty_input_format(self):
     b = BaseModel()
     b.created_at = datetime.datetime(2017, 9, 28, 21, 5, 54, 119427)
     b.updated_at = datetime.datetime(2017, 9, 28, 21, 5, 54, 119572)
     real = b.to_dict()
     exp = {
         '__class__': 'BaseModel',
         'updated_at': '2017-09-28T21:05:54.119572',
         'id': 'b6a6e15c-c67d-4312-9a75-9d084935e579',
         'created_at': '2017-09-28T21:05:54.119427'
     }
Exemplo n.º 5
0
    def test_isoformat(self):
        """ Checks if date is converted to string in isoformat """
        b1 = BaseModel()
        ctime = datetime.now()
        uptime = datetime.now()
        b1.created_at = ctime
        b1.updated_at = uptime

        dic = b1.to_dict()
        self.assertEqual(dic["created_at"], ctime.isoformat())
        self.assertEqual(dic["updated_at"], uptime.isoformat())
Exemplo n.º 6
0
 def test_basestr(self):
     """ Test for str method """
     date1 = datetime.today()
     test1 = BaseModel()
     test1.id = 712456769374
     test1.created_at = date1
     test1.updated_at = date1
     testerstr = test1.__str__()
     self.assertIn("[BaseModel] (712456769374)", testerstr)
     self.assertIn("'id': 712456769374", testerstr)
     self.assertIn("'created_at': " + repr(date1), testerstr)
     self.assertIn("'updated_at': " + repr(date1), testerstr)
Exemplo n.º 7
0
 def test_str(self):
     """Test __str___"""
     date1 = datetime.today()
     tester1 = BaseModel()
     tester1.id = 821983719274
     tester1.created_at = date1
     tester1.updated_at = date1
     testerstr = tester1.__str__()
     self.assertIn("[BaseModel] (821983719274)", testerstr)
     self.assertIn("'id': 821983719274", testerstr)
     self.assertIn("'created_at': " + repr(date1), testerstr)
     self.assertIn("'updated_at': " + repr(date1), testerstr)
Exemplo n.º 8
0
    def test_correct_dict_input(self):
        b1 = BaseModel()
        b1.created_at = datetime.datetime(2017, 9, 28, 21, 5, 54, 119427)
        b1.updated_at = datetime.datetime(2017, 9, 28, 21, 5, 54, 119572)
        b1.name = "Holberton"
        b1.my_number = "89"
        b1_dict = b1.to_dict()

        b2 = BaseModel(**b1_dict)
        b2_dict = b2.to_dict()

        self.assertEqual(b1_dict, b2_dict)
        self.assertEqual(datetime.datetime, type(b2.created_at))
        self.assertFalse(b1 is b2)
Exemplo n.º 9
0
 def test_new_attr_format(self):
     b = BaseModel()
     b.created_at = datetime.datetime(2017, 9, 28, 21, 5, 54, 119427)
     b.updated_at = datetime.datetime(2017, 9, 28, 21, 5, 54, 119572)
     b.name = "Holberton"
     b.my_number = "89"
     real = b.to_dict()
     exp = {
         'my_number': 89,
         'name': 'Holberton',
         '__class__': 'BaseModel',
         'updated_at': '2017-09-28T21:05:54.119572',
         'id': 'b6a6e15c-c67d-4312-9a75-9d084935e579',
         'created_at': '2017-09-28T21:05:54.119427'
     }
Exemplo n.º 10
0
 def test_base_model_change_created_at(self):
     a = BaseModel()
     a.created_at = 10
     self.assertEqual(a.created_at, 10)