Commit abf08118 by Albert St. Aubin

first test round

parent dc280977
...@@ -202,7 +202,7 @@ class EntitlementViewSetTest(ModuleStoreTestCase): ...@@ -202,7 +202,7 @@ class EntitlementViewSetTest(ModuleStoreTestCase):
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
@patch("openedx.core.djangoapps.catalog.utils.get_course_runs_for_course") # @patch("openedx.core.djangoapps.catalog.utils.get_course_runs_for_course")
class EntitlementEnrollmentViewSetTest(ModuleStoreTestCase): class EntitlementEnrollmentViewSetTest(ModuleStoreTestCase):
ENTITLEMENTS_ENROLLMENT_NAMESPACE = 'entitlements_api:v1:enrollments' ENTITLEMENTS_ENROLLMENT_NAMESPACE = 'entitlements_api:v1:enrollments'
...@@ -212,36 +212,17 @@ class EntitlementEnrollmentViewSetTest(ModuleStoreTestCase): ...@@ -212,36 +212,17 @@ class EntitlementEnrollmentViewSetTest(ModuleStoreTestCase):
self.client.login(username=self.user.username, password=TEST_PASSWORD) self.client.login(username=self.user.username, password=TEST_PASSWORD)
self.course = CourseFactory.create(org='edX', number='DemoX', display_name='Demo_Course') self.course = CourseFactory.create(org='edX', number='DemoX', display_name='Demo_Course')
self.course2 = CourseFactory.create(org='edX', number='DemoX2', display_name='Demo_Course 2') self.course2 = CourseFactory.create(org='edX', number='DemoX2', display_name='Demo_Course 2')
self.patcher = patch("openedx.core.djangoapps.catalog.utils.get_course_runs_for_course")
def test_user_can_enroll(self, mock_get_course_runs): self.mock_get_course_runs = self.patcher.start()
course_entitlement = CourseEntitlementFactory( self.mock_get_course_runs.return_value = [
user=self.user {'key': str(self.course.id)},
) {'key': str(self.course2.id)}
url = reverse(
self.ENTITLEMENTS_ENROLLMENT_NAMESPACE,
args=[str(course_entitlement.uuid)]
)
assert course_entitlement.enrollment_course_run is None
mock_get_course_runs.method.return_value = [
{'key': str(self.course.id)}
] ]
data = { def tearDown(self):
'course_run_id': str(self.course.id) self.patcher.stop()
}
response = self.client.post(
url,
data=json.dumps(data),
content_type='application/json',
)
course_entitlement.refresh_from_db()
assert response.status_code == 201 def test_user_can_enroll(self):
assert CourseEnrollment.is_enrolled(self.user, self.course.id)
assert course_entitlement.enrollment_course_run is not None
def test_user_can_unenroll(self, mock_get_course_runs):
course_entitlement = CourseEntitlementFactory( course_entitlement = CourseEntitlementFactory(
user=self.user user=self.user
) )
...@@ -251,10 +232,6 @@ class EntitlementEnrollmentViewSetTest(ModuleStoreTestCase): ...@@ -251,10 +232,6 @@ class EntitlementEnrollmentViewSetTest(ModuleStoreTestCase):
) )
assert course_entitlement.enrollment_course_run is None assert course_entitlement.enrollment_course_run is None
mock_get_course_runs.return_value = [
{'key': str(self.course.id)}
]
data = { data = {
'course_run_id': str(self.course.id) 'course_run_id': str(self.course.id)
} }
...@@ -267,18 +244,43 @@ class EntitlementEnrollmentViewSetTest(ModuleStoreTestCase): ...@@ -267,18 +244,43 @@ class EntitlementEnrollmentViewSetTest(ModuleStoreTestCase):
assert response.status_code == 201 assert response.status_code == 201
assert CourseEnrollment.is_enrolled(self.user, self.course.id) assert CourseEnrollment.is_enrolled(self.user, self.course.id)
assert course_entitlement.enrollment_course_run is not None
response = self.client.delete( def test_user_can_unenroll(self):
url, course_entitlement = CourseEntitlementFactory(
content_type='application/json', user=self.user
) )
assert response.status_code == 204 url = reverse(
self.ENTITLEMENTS_ENROLLMENT_NAMESPACE,
course_entitlement.refresh_from_db() args=[str(course_entitlement.uuid)]
assert not CourseEnrollment.is_enrolled(self.user, self.course.id) )
assert course_entitlement.enrollment_course_run is None assert course_entitlement.enrollment_course_run is None
data = {
'course_run_id': str(self.course.id)
}
response = self.client.post(
url,
data=json.dumps(data),
content_type='application/json',
)
course_entitlement.refresh_from_db()
assert response.status_code == 201
assert CourseEnrollment.is_enrolled(self.user, self.course.id)
response = self.client.delete(
url,
content_type='application/json',
)
assert response.status_code == 204
course_entitlement.refresh_from_db()
assert not CourseEnrollment.is_enrolled(self.user, self.course.id)
assert course_entitlement.enrollment_course_run is None
def test_user_can_switch(self):
def test_user_can_switch(self, mock_get_course_runs):
course_entitlement = CourseEntitlementFactory( course_entitlement = CourseEntitlementFactory(
user=self.user user=self.user
) )
...@@ -288,11 +290,6 @@ class EntitlementEnrollmentViewSetTest(ModuleStoreTestCase): ...@@ -288,11 +290,6 @@ class EntitlementEnrollmentViewSetTest(ModuleStoreTestCase):
) )
assert course_entitlement.enrollment_course_run is None assert course_entitlement.enrollment_course_run is None
mock_get_course_runs.return_value = [
{'key': str(self.course.id)},
{'key': str(self.course2.id)}
]
data = { data = {
'course_run_id': str(self.course.id) 'course_run_id': str(self.course.id)
} }
...@@ -319,4 +316,4 @@ class EntitlementEnrollmentViewSetTest(ModuleStoreTestCase): ...@@ -319,4 +316,4 @@ class EntitlementEnrollmentViewSetTest(ModuleStoreTestCase):
course_entitlement.refresh_from_db() course_entitlement.refresh_from_db()
assert CourseEnrollment.is_enrolled(self.user, self.course2.id) assert CourseEnrollment.is_enrolled(self.user, self.course2.id)
assert course_entitlement.enrollment_course_run is not None assert course_entitlement.enrollment_course_run is not None
print course_entitlement.enrollment_course_run.course_id
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment