Skip to content

Commit 277304f

Browse files
martin056RadoRado
authored andcommitted
Add tests for student_create
1 parent 12ca7d4 commit 277304f

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

styleguide_example/test_examples/services/students.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def student_create(
3434
roster_create(
3535
student=student,
3636
school_course=school_course,
37-
start_date=None
37+
start_date=start_date,
38+
end_date=school_course.end_date
3839
)
3940

4041
return student
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from unittest.mock import patch
2+
3+
from django.test import TestCase
4+
5+
from styleguide_example.utils.tests import faker
6+
7+
from styleguide_example.test_examples.services import student_create
8+
from styleguide_example.test_examples.tests.factories import SchoolFactory, SchoolCourseFactory
9+
10+
11+
class StudentCreateTests(TestCase):
12+
@patch('styleguide_example.test_examples.services.students.school_list_school_courses')
13+
@patch('styleguide_example.test_examples.services.students.roster_create')
14+
def test_student_is_rostered_to_all_active_school_courses(
15+
self,
16+
roster_create_mock,
17+
school_courses_mock
18+
):
19+
school = SchoolFactory()
20+
start_date = faker.date()
21+
email = faker.unique.email()
22+
23+
school_courses_mock.select_related.return_value = SchoolCourseFactory.stub_batch(size=5)
24+
25+
student = student_create(
26+
email=email,
27+
school=school,
28+
start_date=start_date
29+
)
30+
31+
self.assertEqual(student.email, email)
32+
self.assertEqual(student.school, school)
33+
34+
for school_course in school_courses_mock.return_value:
35+
roster_create_mock.assert_called_with(
36+
school_course=school_course,
37+
student=student,
38+
start_date=start_date,
39+
end_date=school_course.end_date
40+
)

0 commit comments

Comments
 (0)