-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_student.py
70 lines (56 loc) · 2.45 KB
/
test_student.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
from datetime import timedelta
import unittest
from student import Student
from unittest.mock import patch
class TestStudent(unittest.TestCase):
"""
- Create a new test method called test_apply_extension
- Inside test_apply_extension, store the current end_date for our student
instance in a variable called old_end_date
- Call a method named apply_extension that takes a no.
of days as an arg on the student instance to update the end_date
- Assert whether the instance's end_date equals the old end date plus the days arg that was passed in using timedelta
- Run the tests to confirm that the new method is failing
- In the Student class, create a new method called apply_extension that has a parameter called days
- Use the timedelta method from datetime to update the end_date property
- Run the tests to confirm they are working, with the new method now passing
"""
@classmethod
def setUpClass(cls):
print('setUpClass...')
@classmethod
def tearDownClass(cls):
print('tearDownClass...')
def setUp(self):
print('setUp...')
self.student = Student('John', 'Doe')
def tearDown(self):
print('tearDown...')
def test_full_name(self):
print('test_full_name')
self.assertEqual(self.student.full_name, 'John Doe')
def test_email(self):
print('test_email')
self.assertEqual(self.student.email, '[email protected]')
def test_alert_santa(self):
print('test_alert_santa')
self.student.alert_santa()
self.assertTrue(self.student.naughty_list)
def test_apply_extension(self):
print('test_apply_extension')
old_end_date = self.student.end_date
self.student.apply_extension(5)
self.assertEqual(self.student.end_date, old_end_date + timedelta(days=5))
def test_course_schedule_success(self):
with patch("student.requests.get") as mocked_get:
mocked_get.return_value.ok = True
mocked_get.return_value.text = "Success!!!"
schedule = self.student.course_schedule()
self.assertEqual(schedule, "Success!!!")
def test_course_schedule_failure(self):
with patch("student.requests.get") as mocked_get:
mocked_get.return_value.ok = False
schedule = self.student.course_schedule()
self.assertEqual(schedule, "Something went wrong with your request!")
if __name__ == '__main__':
unittest.main()