-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtest_review.py
More file actions
executable file
·74 lines (60 loc) · 2.28 KB
/
test_review.py
File metadata and controls
executable file
·74 lines (60 loc) · 2.28 KB
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
#!/usr/bin/python3
"""test for review"""
import unittest
import os
from models.review import Review
from models.base_model import BaseModel
import pep8
class TestReview(unittest.TestCase):
"""this will test the place class"""
@classmethod
def setUpClass(cls):
"""set up for test"""
cls.rev = Review()
cls.rev.place_id = "4321-dcba"
cls.rev.user_id = "123-bca"
cls.rev.text = "The srongest in the Galaxy"
@classmethod
def teardown(cls):
"""at the end of the test this will tear it down"""
del cls.rev
def tearDown(self):
"""teardown"""
try:
os.remove("file.json")
except Exception:
pass
def test_pep8_Review(self):
"""Tests pep8 style"""
style = pep8.StyleGuide(quiet=True)
p = style.check_files(['models/review.py'])
self.assertEqual(p.total_errors, 0, "fix pep8")
def test_checking_for_docstring_Review(self):
"""checking for docstrings"""
self.assertIsNotNone(Review.__doc__)
def test_attributes_review(self):
"""chekcing if review have attributes"""
self.assertTrue('id' in self.rev.__dict__)
self.assertTrue('created_at' in self.rev.__dict__)
self.assertTrue('updated_at' in self.rev.__dict__)
self.assertTrue('place_id' in self.rev.__dict__)
self.assertTrue('text' in self.rev.__dict__)
self.assertTrue('user_id' in self.rev.__dict__)
def test_is_subclass_Review(self):
"""test if review is subclass of BaseModel"""
self.assertTrue(issubclass(self.rev.__class__, BaseModel), True)
def test_attribute_types_Review(self):
"""test attribute type for Review"""
self.assertEqual(type(self.rev.text), str)
self.assertEqual(type(self.rev.place_id), str)
self.assertEqual(type(self.rev.user_id), str)
@unittest.skipIf(os.getenv("HBNB_TYPE_STORAGE") == "db", "No apply for db")
def test_save_Review(self):
"""test if the save works"""
self.rev.save()
self.assertNotEqual(self.rev.created_at, self.rev.updated_at)
def test_to_dict_Review(self):
"""test if dictionary works"""
self.assertEqual('to_dict' in dir(self.rev), True)
if __name__ == "__main__":
unittest.main()