-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_city.py
executable file
·53 lines (41 loc) · 1.37 KB
/
test_city.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
52
53
#!/usr/bin/python3
"""Unittest module for the City Class."""
import unittest
from datetime import datetime
import time
from models.city import City
import re
import json
from models.engine.file_storage import FileStorage
import os
from models import storage
from models.base_model import BaseModel
class TestCity(unittest.TestCase):
"""Test Cases for the City class."""
def setUp(self):
"""Sets up test methods."""
pass
def tearDown(self):
"""Tears down test methods."""
self.resetStorage()
pass
def resetStorage(self):
"""Resets FileStorage data."""
FileStorage._FileStorage__objects = {}
if os.path.isfile(FileStorage._FileStorage__file_path):
os.remove(FileStorage._FileStorage__file_path)
def test_8_instantiation(self):
"""Tests instantiation of City class."""
b = City()
self.assertEqual(str(type(b)), "<class 'models.city.City'>")
self.assertIsInstance(b, City)
self.assertTrue(issubclass(type(b), BaseModel))
def test_8_attributes(self):
"""Tests the attributes of City class."""
attributes = storage.attributes()["City"]
o = City()
for k, v in attributes.items():
self.assertTrue(hasattr(o, k))
self.assertEqual(type(getattr(o, k, None)), v)
if __name__ == "__main__":
unittest.main()