-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_base_model.py
executable file
·51 lines (37 loc) · 1.61 KB
/
test_base_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python3
""" Module of Unittests """
import os
import unittest
import datetime
from models.base_model import BaseModel
import os
from models import storage
from models.engine.file_storage import FileStorage
class BaseModelTests(unittest.TestCase):
my_model = BaseModel()
def testBaseModel1(self):
""" This Tests attribute values of a BaseModel instance """
self.my_model.name = "myFirstModel"
self.my_model.my_number = 89
self.my_model.save()
my_model_json = self.my_model.to_dict()
self.assertEqual(self.my_model.name, my_model_json['name'])
self.assertEqual(self.my_model.my_number, my_model_json['my_number'])
self.assertEqual('BaseModel', my_model_json['__class__'])
self.assertEqual(self.my_model.id, my_model_json['id'])
def testSave(self):
""" This tests Checks if save method updates the public instance
attribute updated_at """
self.my_model.first_name = "First"
self.my_model.save()
self.assertIsInstance(self.my_model.id, str)
self.assertIsInstance(self.my_model.created_at, datetime.datetime)
self.assertIsInstance(self.my_model.updated_at, datetime.datetime)
first_dict = self.my_model.to_dict()
self.my_model.first_name = "Second"
self.my_model.save()
sec_dict = self.my_model.to_dict()
self.assertEqual(first_dict['created_at'], sec_dict['created_at'])
self.assertNotEqual(first_dict['updated_at'], sec_dict['updated_at'])
if __name__ == '__main__':
unittest.main()