-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtest_place.py
executable file
·98 lines (84 loc) · 3.57 KB
/
test_place.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/python3
"""test for place"""
import unittest
import os
from models.place import Place
from models.base_model import BaseModel
import pep8
class TestPlace(unittest.TestCase):
"""this will test the place class"""
@classmethod
def setUpClass(cls):
"""set up for test"""
cls.place = Place()
cls.place.city_id = "1234-abcd"
cls.place.user_id = "4321-dcba"
cls.place.name = "Death Star"
cls.place.description = "UNLIMITED POWER!!!!!"
cls.place.number_rooms = 1000000
cls.place.number_bathrooms = 1
cls.place.max_guest = 607360
cls.place.price_by_night = 10
cls.place.latitude = 160.0
cls.place.longitude = 120.0
cls.place.amenity_ids = ["1324-lksdjkl"]
@classmethod
def teardown(cls):
"""at the end of the test this will tear it down"""
del cls.place
def tearDown(self):
"""teardown"""
try:
os.remove("file.json")
except Exception:
pass
def test_pep8_Place(self):
"""Tests pep8 style"""
style = pep8.StyleGuide(quiet=True)
p = style.check_files(['models/place.py'])
self.assertEqual(p.total_errors, 0, "fix pep8")
def test_checking_for_docstring_Place(self):
"""checking for docstrings"""
self.assertIsNotNone(Place.__doc__)
def test_attributes_Place(self):
"""chekcing if amenity have attributes"""
self.assertTrue('id' in self.place.__dict__)
self.assertTrue('created_at' in self.place.__dict__)
self.assertTrue('updated_at' in self.place.__dict__)
self.assertTrue('city_id' in self.place.__dict__)
self.assertTrue('user_id' in self.place.__dict__)
self.assertTrue('name' in self.place.__dict__)
self.assertTrue('description' in self.place.__dict__)
self.assertTrue('number_rooms' in self.place.__dict__)
self.assertTrue('number_bathrooms' in self.place.__dict__)
self.assertTrue('max_guest' in self.place.__dict__)
self.assertTrue('price_by_night' in self.place.__dict__)
self.assertTrue('latitude' in self.place.__dict__)
self.assertTrue('longitude' in self.place.__dict__)
self.assertTrue('amenity_ids' in self.place.__dict__)
def test_is_subclass_Place(self):
"""test if Place is subclass of Basemodel"""
self.assertTrue(issubclass(self.place.__class__, BaseModel), True)
def test_attribute_types_Place(self):
"""test attribute type for Place"""
self.assertEqual(type(self.place.city_id), str)
self.assertEqual(type(self.place.user_id), str)
self.assertEqual(type(self.place.name), str)
self.assertEqual(type(self.place.description), str)
self.assertEqual(type(self.place.number_rooms), int)
self.assertEqual(type(self.place.number_bathrooms), int)
self.assertEqual(type(self.place.max_guest), int)
self.assertEqual(type(self.place.price_by_night), int)
self.assertEqual(type(self.place.latitude), float)
self.assertEqual(type(self.place.longitude), float)
self.assertEqual(type(self.place.amenity_ids), list)
@unittest.skipIf(os.getenv("HBNB_TYPE_STORAGE") == "db", "No apply for db")
def test_save_Place(self):
"""test if the save works"""
self.place.save()
self.assertNotEqual(self.place.created_at, self.place.updated_at)
def test_to_dict_Place(self):
"""test if dictionary works"""
self.assertEqual('to_dict' in dir(self.place), True)
if __name__ == "__main__":
unittest.main()