Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
f4d5bc22
Commit
f4d5bc22
authored
4 years ago
by
Kyle McCormick
Committed by
Kyle McCormick
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Improve repr() output of program_enrollments models
parent
568dcf56
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lms/djangoapps/program_enrollments/models.py
+25
-2
25 additions, 2 deletions
lms/djangoapps/program_enrollments/models.py
lms/djangoapps/program_enrollments/tests/test_models.py
+52
-19
52 additions, 19 deletions
lms/djangoapps/program_enrollments/tests/test_models.py
with
77 additions
and
21 deletions
lms/djangoapps/program_enrollments/models.py
+
25
−
2
View file @
f4d5bc22
...
...
@@ -17,7 +17,7 @@ from student.models import CourseEnrollment
from
.constants
import
ProgramCourseEnrollmentStatuses
,
ProgramEnrollmentStatuses
class
ProgramEnrollment
(
TimeStampedModel
):
# pylint: disable=model-missing-unicode
class
ProgramEnrollment
(
TimeStampedModel
):
"""
This is a model for Program Enrollments from the registrar service
...
...
@@ -78,8 +78,20 @@ class ProgramEnrollment(TimeStampedModel): # pylint: disable=model-missing-unic
def
__str__
(
self
):
return
'
[ProgramEnrollment id={}]
'
.
format
(
self
.
id
)
def
__repr__
(
self
):
return
(
"
<ProgramEnrollment
"
# pylint: disable=missing-format-attribute
"
id={self.id}
"
"
user={self.user!r}
"
"
external_user_key={self.external_user_key!r}
"
"
program_uuid={self.program_uuid!r}
"
"
curriculum_uuid={self.curriculum_uuid!r}
"
"
status={self.status!r}
"
"
>
"
).
format
(
self
=
self
)
class
ProgramCourseEnrollment
(
TimeStampedModel
):
# pylint: disable=model-missing-unicode
class
ProgramCourseEnrollment
(
TimeStampedModel
):
"""
This is a model to represent a learner
'
s enrollment in a course
in the context of a program from the registrar service
...
...
@@ -126,3 +138,14 @@ class ProgramCourseEnrollment(TimeStampedModel): # pylint: disable=model-missin
def
__str__
(
self
):
return
'
[ProgramCourseEnrollment id={}]
'
.
format
(
self
.
id
)
def
__repr__
(
self
):
return
(
"
<ProgramCourseEnrollment
"
# pylint: disable=missing-format-attribute
"
id={self.id}
"
"
program_enrollment={self.program_enrollment!r}
"
"
course_enrollment=<{self.course_enrollment}>
"
"
course_key={self.course_key}
"
"
status={self.status!r}
"
"
>
"
).
format
(
self
=
self
)
This diff is collapsed.
Click to expand it.
lms/djangoapps/program_enrollments/tests/test_models.py
+
52
−
19
View file @
f4d5bc22
...
...
@@ -3,7 +3,7 @@ Unit tests for ProgramEnrollment models.
"""
from
uuid
import
uuid4
from
uuid
import
UUID
import
ddt
from
django.db.utils
import
IntegrityError
...
...
@@ -12,11 +12,12 @@ from edx_django_utils.cache import RequestCache
from
opaque_keys.edx.keys
import
CourseKey
from
course_modes.models
import
CourseMode
from
lms.djangoapps.program_enrollments.models
import
ProgramCourseEnrollment
,
ProgramEnrollment
from
openedx.core.djangoapps.catalog.tests.factories
import
generate_course_run_key
from
openedx.core.djangoapps.content.course_overviews.tests.factories
import
CourseOverviewFactory
from
student.tests.factories
import
CourseEnrollmentFactory
,
UserFactory
from
..models
import
ProgramEnrollment
from
.factories
import
ProgramCourseEnrollmentFactory
,
ProgramEnrollmentFactory
class
ProgramEnrollmentModelTests
(
TestCase
):
"""
...
...
@@ -27,11 +28,11 @@ class ProgramEnrollmentModelTests(TestCase):
Set up the test data used in the specific tests
"""
super
(
ProgramEnrollmentModelTests
,
self
).
setUp
()
self
.
user
=
UserFactory
.
create
(
)
self
.
program_uuid
=
uuid4
(
)
self
.
other_program_uuid
=
uuid4
(
)
self
.
curriculum_uuid
=
uuid4
(
)
self
.
enrollment
=
ProgramEnrollment
.
objects
.
create
(
self
.
user
=
UserFactory
(
username
=
"
rocko
"
)
self
.
program_uuid
=
UUID
(
"
88888888-4444-2222-1111-000000000000
"
)
self
.
other_program_uuid
=
UUID
(
"
88888888-4444-3333-1111-000000000000
"
)
self
.
curriculum_uuid
=
UUID
(
"
77777777-4444-2222-1111-000000000000
"
)
self
.
enrollment
=
ProgramEnrollment
Factory
(
user
=
self
.
user
,
external_user_key
=
'
abc
'
,
program_uuid
=
self
.
program_uuid
,
...
...
@@ -39,12 +40,24 @@ class ProgramEnrollmentModelTests(TestCase):
status
=
'
enrolled
'
)
def
test_str_and_repr
(
self
):
"""
Make sure str() and repr() work correctly on instances of this model.
"""
assert
str
(
self
.
enrollment
)
==
"
[ProgramEnrollment id=1]
"
assert
repr
(
self
.
enrollment
)
==
(
"
<ProgramEnrollment id=1 user=<User: rocko> external_user_key=
'
abc
'"
"
program_uuid=UUID(
'
88888888-4444-2222-1111-000000000000
'
)
"
"
curriculum_uuid=UUID(
'
77777777-4444-2222-1111-000000000000
'
)
"
"
status=
'
enrolled
'
>
"
)
def
test_unique_external_key_program_curriculum
(
self
):
"""
A record with the same (external_user_key, program_uuid, curriculum_uuid) cannot be duplicated.
"""
with
self
.
assertRaises
(
IntegrityError
):
_
=
ProgramEnrollment
.
objects
.
create
(
_
=
ProgramEnrollment
Factory
(
user
=
None
,
external_user_key
=
'
abc
'
,
program_uuid
=
self
.
program_uuid
,
...
...
@@ -57,7 +70,7 @@ class ProgramEnrollmentModelTests(TestCase):
A record with the same (user, program_uuid, curriculum_uuid) cannot be duplicated.
"""
with
self
.
assertRaises
(
IntegrityError
):
_
=
ProgramEnrollment
.
objects
.
create
(
_
=
ProgramEnrollment
Factory
(
user
=
self
.
user
,
external_user_key
=
None
,
program_uuid
=
self
.
program_uuid
,
...
...
@@ -104,18 +117,38 @@ class ProgramCourseEnrollmentModelTests(TestCase):
"""
super
(
ProgramCourseEnrollmentModelTests
,
self
).
setUp
()
RequestCache
.
clear_all_namespaces
()
self
.
user
=
UserFactory
.
create
()
self
.
program_uuid
=
uuid4
()
self
.
program_enrollment
=
ProgramEnrollment
.
objects
.
create
(
self
.
user
=
UserFactory
(
username
=
"
rocko
"
)
self
.
program_uuid
=
UUID
(
"
88888888-4444-2222-1111-000000000000
"
)
self
.
curriculum_uuid
=
UUID
(
"
77777777-4444-2222-1111-000000000000
"
)
self
.
program_enrollment
=
ProgramEnrollmentFactory
(
user
=
self
.
user
,
external_user_key
=
'
abc
'
,
program_uuid
=
self
.
program_uuid
,
curriculum_uuid
=
uuid
4
()
,
curriculum_uuid
=
self
.
curriculum_
uuid
,
status
=
'
enrolled
'
)
self
.
course_key
=
CourseKey
.
from_string
(
generate_course_run_key
()
)
self
.
course_key
=
CourseKey
.
from_string
(
"
course-v1:blah+blah+blah
"
)
CourseOverviewFactory
(
id
=
self
.
course_key
)
def
test_str_and_repr
(
self
):
"""
Make sure str() and repr() work correctly on instances of this model.
"""
pce
=
self
.
_create_completed_program_course_enrollment
()
assert
str
(
pce
)
==
"
[ProgramCourseEnrollment id=1]
"
# The course enrollment contains timestamp information,
# so to avoid dealing with that, let's just test the parts of the repr()
# that come before that.
assert
(
"
<ProgramCourseEnrollment id=1
"
"
program_enrollment=<ProgramEnrollment id=1 user=<User: rocko>
"
"
external_user_key=
'
abc
'"
"
program_uuid=UUID(
'
88888888-4444-2222-1111-000000000000
'
)
"
"
curriculum_uuid=UUID(
'
77777777-4444-2222-1111-000000000000
'
)
"
"
status=
'
enrolled
'
>
"
"
course_enrollment=<[CourseEnrollment] rocko: course-v1:blah+blah+blah
"
)
in
repr
(
pce
)
def
test_duplicate_enrollments_allowed
(
self
):
"""
A record with the same (program_enrollment, course_enrollment)
...
...
@@ -123,7 +156,7 @@ class ProgramCourseEnrollmentModelTests(TestCase):
same course_enrollment
"""
pce
=
self
.
_create_completed_program_course_enrollment
()
ProgramCourseEnrollment
.
objects
.
create
(
ProgramCourseEnrollment
Factory
(
program_enrollment
=
pce
.
program_enrollment
,
course_key
=
"
course-v1:dummy+value+101
"
,
course_enrollment
=
pce
.
course_enrollment
,
...
...
@@ -137,7 +170,7 @@ class ProgramCourseEnrollmentModelTests(TestCase):
"""
pce
=
self
.
_create_waiting_program_course_enrollment
()
with
self
.
assertRaises
(
IntegrityError
):
ProgramCourseEnrollment
.
objects
.
create
(
ProgramCourseEnrollment
Factory
(
program_enrollment
=
pce
.
program_enrollment
,
course_key
=
pce
.
course_key
,
course_enrollment
=
None
,
...
...
@@ -151,7 +184,7 @@ class ProgramCourseEnrollmentModelTests(TestCase):
user
=
self
.
user
,
mode
=
CourseMode
.
MASTERS
)
program_course_enrollment
=
ProgramCourseEnrollment
.
objects
.
create
(
program_course_enrollment
=
ProgramCourseEnrollment
Factory
(
program_enrollment
=
self
.
program_enrollment
,
course_key
=
self
.
course_key
,
course_enrollment
=
course_enrollment
,
...
...
@@ -161,7 +194,7 @@ class ProgramCourseEnrollmentModelTests(TestCase):
def
_create_waiting_program_course_enrollment
(
self
):
"""
helper function create program course enrollment with no lms user
"""
return
ProgramCourseEnrollment
.
objects
.
create
(
return
ProgramCourseEnrollment
Factory
(
program_enrollment
=
self
.
program_enrollment
,
course_key
=
self
.
course_key
,
course_enrollment
=
None
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment