@@ -59,19 +59,13 @@ class Meta:
59
59
60
60
student = factory .SubFactory (StudentFactory )
61
61
# Make sure the student and the school_course are from the same school
62
- school_course = factory .SubFactory (SchoolCourseFactory , school = factory .SelfAttribute ('..student.school' ))
62
+ school_course = factory .SubFactory (
63
+ SchoolCourseFactory ,
64
+ school = factory .SelfAttribute ('..student.school' )
65
+ )
63
66
64
- # The code below might cause bugs because of the school_course period
65
- # start_date = factory.LazyAttribute(lambda _: faker.past_date())
66
- # end_date = factory.LazyAttribute(lambda _: faker.future_date())
67
- start_date = factory .LazyAttribute (lambda self : faker .date_between_dates (
68
- date_start = self .school_course .start_date ,
69
- date_end = self .school_course .end_date - timedelta (days = 2 )
70
- ))
71
- end_date = factory .LazyAttribute (lambda self : faker .date_between_dates (
72
- date_start = self .start_date + timedelta (days = 1 ),
73
- date_end = self .school_course .end_date
74
- ))
67
+ start_date = factory .SelfAttribute ('school_course.start_date' )
68
+ end_date = factory .SelfAttribute ('school_course.end_date' )
75
69
76
70
active = True
77
71
deactivated_at = factory .Maybe (
@@ -84,6 +78,20 @@ class Meta:
84
78
)
85
79
86
80
81
+ def get_future_roster_start_date (roster_obj ):
82
+ if not roster_obj .start_after :
83
+ return faker .future_date ()
84
+
85
+ return roster_obj .start_after + timedelta (days = faker .pyint (2 , 100 ))
86
+
87
+
88
+ class FutureRosterFactory (RosterFactory ):
89
+ class Params :
90
+ start_after = None
91
+
92
+ start_date = factory .LazyAttribute (get_future_roster_start_date )
93
+
94
+
87
95
class SchoolCourseWithRostersFactory (SchoolCourseFactory ):
88
96
@factory .post_generation
89
97
def rosters (obj , create , extracted , ** kwargs ):
0 commit comments