Commit abf08118 by Albert St. Aubin

first test round

parent dc280977
......@@ -202,7 +202,7 @@ class EntitlementViewSetTest(ModuleStoreTestCase):
@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):
ENTITLEMENTS_ENROLLMENT_NAMESPACE = 'entitlements_api:v1:enrollments'
......@@ -212,36 +212,17 @@ class EntitlementEnrollmentViewSetTest(ModuleStoreTestCase):
self.client.login(username=self.user.username, password=TEST_PASSWORD)
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')
def test_user_can_enroll(self, mock_get_course_runs):
course_entitlement = CourseEntitlementFactory(
user=self.user
)
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)}
self.patcher = patch("openedx.core.djangoapps.catalog.utils.get_course_runs_for_course")
self.mock_get_course_runs = self.patcher.start()
self.mock_get_course_runs.return_value = [
{'key': str(self.course.id)},
{'key': str(self.course2.id)}
]
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()
def tearDown(self):
self.patcher.stop()
assert response.status_code == 201
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):
def test_user_can_enroll(self):
course_entitlement = CourseEntitlementFactory(
user=self.user
)
......@@ -251,10 +232,6 @@ class EntitlementEnrollmentViewSetTest(ModuleStoreTestCase):
)
assert course_entitlement.enrollment_course_run is None
mock_get_course_runs.return_value = [
{'key': str(self.course.id)}
]
data = {
'course_run_id': str(self.course.id)
}
......@@ -267,18 +244,43 @@ class EntitlementEnrollmentViewSetTest(ModuleStoreTestCase):
assert response.status_code == 201
assert CourseEnrollment.is_enrolled(self.user, self.course.id)
assert course_entitlement.enrollment_course_run is not None
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_unenroll(self):
course_entitlement = CourseEntitlementFactory(
user=self.user
)
url = reverse(
self.ENTITLEMENTS_ENROLLMENT_NAMESPACE,
args=[str(course_entitlement.uuid)]
)
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(
user=self.user
)
......@@ -288,11 +290,6 @@ class EntitlementEnrollmentViewSetTest(ModuleStoreTestCase):
)
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 = {
'course_run_id': str(self.course.id)
}
......@@ -319,4 +316,4 @@ class EntitlementEnrollmentViewSetTest(ModuleStoreTestCase):
course_entitlement.refresh_from_db()
assert CourseEnrollment.is_enrolled(self.user, self.course2.id)
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