unit test for mobile api org filter, query string args for api calls
This commit is contained in:
@@ -71,13 +71,13 @@ class MobileAPITestCase(ModuleStoreTestCase, APITestCase):
|
||||
self.login()
|
||||
self.enroll(course_id)
|
||||
|
||||
def api_response(self, reverse_args=None, expected_response_code=200, **kwargs):
|
||||
def api_response(self, reverse_args=None, expected_response_code=200, qargs={}, **kwargs):
|
||||
"""
|
||||
Helper method for calling endpoint, verifying and returning response.
|
||||
If expected_response_code is None, doesn't verify the response' status_code.
|
||||
"""
|
||||
url = self.reverse_url(reverse_args, **kwargs)
|
||||
response = self.url_method(url, **kwargs)
|
||||
response = self.url_method(url, qargs=qargs, **kwargs)
|
||||
if expected_response_code is not None:
|
||||
self.assertEqual(response.status_code, expected_response_code)
|
||||
return response
|
||||
@@ -91,9 +91,9 @@ class MobileAPITestCase(ModuleStoreTestCase, APITestCase):
|
||||
reverse_args.update({'username': kwargs.get('username', self.user.username)})
|
||||
return reverse(self.REVERSE_INFO['name'], kwargs=reverse_args)
|
||||
|
||||
def url_method(self, url, **kwargs): # pylint: disable=unused-argument
|
||||
def url_method(self, url, qargs={}, **kwargs): # pylint: disable=unused-argument
|
||||
"""Base implementation that returns response from the GET method of the URL."""
|
||||
return self.client.get(url)
|
||||
return self.client.get(url, qargs)
|
||||
|
||||
|
||||
class MobileAuthTestMixin(object):
|
||||
|
||||
@@ -270,6 +270,35 @@ class TestUserEnrollmentApi(UrlResetMixin, MobileAPITestCase, MobileAuthUserTest
|
||||
self.assertIn('/api/discussion/v1/courses/{}'.format(self.course.id), response_discussion_url)
|
||||
|
||||
|
||||
def test_org_query(self):
|
||||
self.login()
|
||||
|
||||
# Create list of courses with various organizations
|
||||
courses = [
|
||||
CourseFactory.create(org='edX', mobile_available=True),
|
||||
CourseFactory.create(org='edX', mobile_available=True),
|
||||
CourseFactory.create(org='edX', mobile_available=True, visible_to_staff_only=True),
|
||||
CourseFactory.create(org='Proversity.org', mobile_available=True),
|
||||
CourseFactory.create(org='MITx', mobile_available=True),
|
||||
CourseFactory.create(org='HarvardX', mobile_available=True),
|
||||
]
|
||||
|
||||
# Enroll in all the courses
|
||||
for course in courses:
|
||||
self.enroll(course.id)
|
||||
|
||||
response = self.api_response(qargs={'org':'edX'})
|
||||
|
||||
# Verify only edX courses are returned
|
||||
self.assertEqual(len(response.data), 3)
|
||||
for course_index in range(3):
|
||||
result = response.data[course_index]['course']
|
||||
self.assertEqual(result['org'], 'edX')
|
||||
|
||||
# Verify most recently enrolled course is staff only but still returned
|
||||
self.assertFalse(response.data[0]['course']['courseware_access']['has_access'])
|
||||
|
||||
|
||||
@attr('shard_2')
|
||||
class CourseStatusAPITestCase(MobileAPITestCase):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user