Skip to content
Snippets Groups Projects
Commit 3c618ad0 authored by Feanil Patel's avatar Feanil Patel
Browse files

Fixup CourseEnrollmentFactory

Historically, the CourseEnrollment model used to have a `course_id`
field.  A lot of tests still call the factory using that.  Instead of a
`course_id` field this model now has a `course` field which is a foreign
key to the CourseOverview model.

The factory still accepts the course_id but uses it to create the
relevant CourseOverview object where necessary.  This commit fixes two
issues with the factory.

1. If the course id is passed in as`course_id` instead of `course__id`
then, the generated CourseOverview does not have the correct course_id.

2. Even though the CourseEnrollment model no longer needs the
`course_id` parameter, we were still passing it through.  We now remove
it so that it is not passed through to the CourseEnrollment model
instantiation.
parent 7c115cca
No related branches found
No related tags found
No related merge requests found
......@@ -142,6 +142,11 @@ class CourseEnrollmentFactory(DjangoModelFactory):
course_id = kwargs.get('course_id')
course_overview = None
if course_id is not None:
# 'course_id' is not needed by the model when course is passed.
# This arg used to be called course_id before we added the CourseOverview
# foreign key constraint to CourseEnrollment.
del kwargs['course_id']
if isinstance(course_id, six.string_types):
course_id = CourseKey.from_string(course_id)
course_kwargs.setdefault('id', course_id)
......@@ -152,6 +157,9 @@ class CourseEnrollmentFactory(DjangoModelFactory):
pass
if course_overview is None:
if 'id' not in course_kwargs and course_id:
course_kwargs['id'] = course_id
course_overview = CourseOverviewFactory(**course_kwargs)
kwargs['course'] = course_overview
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment