-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtest_user.py
More file actions
executable file
·77 lines (63 loc) · 2.42 KB
/
Copy pathtest_user.py
File metadata and controls
executable file
·77 lines (63 loc) · 2.42 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
75
76
77
#!/usr/bin/python3
"""test for user"""
import unittest
import os
from models.user import User
from models.base_model import BaseModel
import pep8
class TestUser(unittest.TestCase):
"""this will test the User class"""
@classmethod
def setUpClass(cls):
"""set up for test"""
cls.user = User()
cls.user.first_name = "Kevin"
cls.user.last_name = "Yook"
cls.user.email = "yook00627@gmamil.com"
cls.user.password = "secret"
@classmethod
def teardown(cls):
"""at the end of the test this will tear it down"""
del cls.user
def tearDown(self):
"""teardown"""
try:
os.remove("file.json")
except Exception:
pass
def test_pep8_User(self):
"""Tests pep8 style"""
style = pep8.StyleGuide(quiet=True)
p = style.check_files(['models/user.py'])
self.assertEqual(p.total_errors, 0, "fix pep8")
def test_checking_for_docstring_User(self):
"""checking for docstrings"""
self.assertIsNotNone(User.__doc__)
def test_attributes_User(self):
"""chekcing if User have attributes"""
self.assertTrue('email' in self.user.__dict__)
self.assertTrue('id' in self.user.__dict__)
self.assertTrue('created_at' in self.user.__dict__)
self.assertTrue('updated_at' in self.user.__dict__)
self.assertTrue('password' in self.user.__dict__)
self.assertTrue('first_name' in self.user.__dict__)
self.assertTrue('last_name' in self.user.__dict__)
def test_is_subclass_User(self):
"""test if User is subclass of Basemodel"""
self.assertTrue(issubclass(self.user.__class__, BaseModel), True)
def test_attribute_types_User(self):
"""test attribute type for User"""
self.assertEqual(type(self.user.email), str)
self.assertEqual(type(self.user.password), str)
self.assertEqual(type(self.user.first_name), str)
self.assertEqual(type(self.user.first_name), str)
@unittest.skipIf(os.getenv("HBNB_TYPE_STORAGE") == "db", "No apply for db")
def test_save_User(self):
"""test if the save works"""
self.user.save()
self.assertNotEqual(self.user.created_at, self.user.updated_at)
def test_to_dict_User(self):
"""test if dictionary works"""
self.assertEqual('to_dict' in dir(self.user), True)
if __name__ == "__main__":
unittest.main()