Commit 43fdf9a6 by Ehtesham

[MA-1862] converting function signature to take kwargs

parent 1297f0af
...@@ -47,7 +47,6 @@ class DiscussionAPIPagination(NamespacedPageNumberPagination): ...@@ -47,7 +47,6 @@ class DiscussionAPIPagination(NamespacedPageNumberPagination):
""" """
self.page = _Page(page_num, num_pages) self.page = _Page(page_num, num_pages)
self.base_url = request.build_absolute_uri() self.base_url = request.build_absolute_uri()
self.num_pages = num_pages
super(DiscussionAPIPagination, self).__init__() super(DiscussionAPIPagination, self).__init__()
...@@ -63,7 +62,7 @@ class DiscussionAPIPagination(NamespacedPageNumberPagination): ...@@ -63,7 +62,7 @@ class DiscussionAPIPagination(NamespacedPageNumberPagination):
""" """
Returns total number of pages the response is divided into Returns total number of pages the response is divided into
""" """
return self.num_pages return self.page.num_pages
def get_next_link(self): def get_next_link(self):
""" """
......
...@@ -695,7 +695,7 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto ...@@ -695,7 +695,7 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto
] ]
expected_result = make_paginated_api_response( expected_result = make_paginated_api_response(
expected_threads, 0, 1, None, None results=expected_threads, count=0, num_pages=1, next_link=None, previous_link=None
) )
expected_result.update({"text_search_rewrite": None}) expected_result.update({"text_search_rewrite": None})
self.assertEqual( self.assertEqual(
...@@ -728,7 +728,9 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto ...@@ -728,7 +728,9 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto
def test_pagination(self): def test_pagination(self):
# N.B. Empty thread list is not realistic but convenient for this test # N.B. Empty thread list is not realistic but convenient for this test
expected_result = make_paginated_api_response([], 0, 3, "http://testserver/test_path?page=2", None) expected_result = make_paginated_api_response(
results=[], count=0, num_pages=3, next_link="http://testserver/test_path?page=2", previous_link=None
)
expected_result.update({"text_search_rewrite": None}) expected_result.update({"text_search_rewrite": None})
self.assertEqual( self.assertEqual(
self.get_thread_list([], page=1, num_pages=3).data, self.get_thread_list([], page=1, num_pages=3).data,
...@@ -736,7 +738,11 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto ...@@ -736,7 +738,11 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto
) )
expected_result = make_paginated_api_response( expected_result = make_paginated_api_response(
[], 0, 3, "http://testserver/test_path?page=3", "http://testserver/test_path?page=1" results=[],
count=0,
num_pages=3,
next_link="http://testserver/test_path?page=3",
previous_link="http://testserver/test_path?page=1"
) )
expected_result.update({"text_search_rewrite": None}) expected_result.update({"text_search_rewrite": None})
self.assertEqual( self.assertEqual(
...@@ -745,7 +751,7 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto ...@@ -745,7 +751,7 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto
) )
expected_result = make_paginated_api_response( expected_result = make_paginated_api_response(
[], 0, 3, None, "http://testserver/test_path?page=2" results=[], count=0, num_pages=3, next_link=None, previous_link="http://testserver/test_path?page=2"
) )
expected_result.update({"text_search_rewrite": None}) expected_result.update({"text_search_rewrite": None})
self.assertEqual( self.assertEqual(
...@@ -761,7 +767,7 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto ...@@ -761,7 +767,7 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto
@ddt.data(None, "rewritten search string") @ddt.data(None, "rewritten search string")
def test_text_search(self, text_search_rewrite): def test_text_search(self, text_search_rewrite):
expected_result = make_paginated_api_response( expected_result = make_paginated_api_response(
[], 0, 0, None, None results=[], count=0, num_pages=0, next_link=None, previous_link=None
) )
expected_result.update({"text_search_rewrite": text_search_rewrite}) expected_result.update({"text_search_rewrite": text_search_rewrite})
self.register_get_threads_search_response([], text_search_rewrite, num_pages=0) self.register_get_threads_search_response([], text_search_rewrite, num_pages=0)
...@@ -796,7 +802,9 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto ...@@ -796,7 +802,9 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto
following=True, following=True,
).data ).data
expected_result = make_paginated_api_response([], 0, 0, None, None) expected_result = make_paginated_api_response(
results=[], count=0, num_pages=0, next_link=None, previous_link=None
)
expected_result.update({"text_search_rewrite": None}) expected_result.update({"text_search_rewrite": None})
self.assertEqual( self.assertEqual(
result, result,
...@@ -827,7 +835,7 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto ...@@ -827,7 +835,7 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto
).data ).data
expected_result = make_paginated_api_response( expected_result = make_paginated_api_response(
[], 0, 0, None, None results=[], count=0, num_pages=0, next_link=None, previous_link=None
) )
expected_result.update({"text_search_rewrite": None}) expected_result.update({"text_search_rewrite": None})
self.assertEqual( self.assertEqual(
...@@ -872,7 +880,9 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto ...@@ -872,7 +880,9 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto
order_by=http_query, order_by=http_query,
).data ).data
expected_result = make_paginated_api_response([], 0, 0, None, None) expected_result = make_paginated_api_response(
results=[], count=0, num_pages=0, next_link=None, previous_link=None
)
expected_result.update({"text_search_rewrite": None}) expected_result.update({"text_search_rewrite": None})
self.assertEqual(result, expected_result) self.assertEqual(result, expected_result)
self.assertEqual( self.assertEqual(
...@@ -900,7 +910,9 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto ...@@ -900,7 +910,9 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto
order_direction=http_query, order_direction=http_query,
).data ).data
expected_result = make_paginated_api_response([], 0, 0, None, None) expected_result = make_paginated_api_response(
results=[], count=0, num_pages=0, next_link=None, previous_link=None
)
expected_result.update({"text_search_rewrite": None}) expected_result.update({"text_search_rewrite": None})
self.assertEqual(result, expected_result) self.assertEqual(result, expected_result)
self.assertEqual( self.assertEqual(
...@@ -1065,7 +1077,7 @@ class GetCommentListTest(CommentsServiceMockMixin, SharedModuleStoreTestCase): ...@@ -1065,7 +1077,7 @@ class GetCommentListTest(CommentsServiceMockMixin, SharedModuleStoreTestCase):
) )
self.assertEqual( self.assertEqual(
self.get_comment_list(discussion_thread).data, self.get_comment_list(discussion_thread).data,
make_paginated_api_response([], 0, 1, None, None) make_paginated_api_response(results=[], count=0, num_pages=1, next_link=None, previous_link=None)
) )
question_thread = self.make_minimal_cs_thread({ question_thread = self.make_minimal_cs_thread({
...@@ -1076,11 +1088,11 @@ class GetCommentListTest(CommentsServiceMockMixin, SharedModuleStoreTestCase): ...@@ -1076,11 +1088,11 @@ class GetCommentListTest(CommentsServiceMockMixin, SharedModuleStoreTestCase):
}) })
self.assertEqual( self.assertEqual(
self.get_comment_list(question_thread, endorsed=False).data, self.get_comment_list(question_thread, endorsed=False).data,
make_paginated_api_response([], 0, 1, None, None) make_paginated_api_response(results=[], count=0, num_pages=1, next_link=None, previous_link=None)
) )
self.assertEqual( self.assertEqual(
self.get_comment_list(question_thread, endorsed=True).data, self.get_comment_list(question_thread, endorsed=True).data,
make_paginated_api_response([], 0, 1, None, None) make_paginated_api_response(results=[], count=0, num_pages=1, next_link=None, previous_link=None)
) )
def test_basic_query_params(self): def test_basic_query_params(self):
......
...@@ -23,31 +23,39 @@ class PaginationSerializerTest(TestCase): ...@@ -23,31 +23,39 @@ class PaginationSerializerTest(TestCase):
def test_empty(self): def test_empty(self):
self.do_case( self.do_case(
[], 1, 0, make_paginated_api_response([], 0, 0, None, None) [], 1, 0, make_paginated_api_response(
results=[], count=0, num_pages=0, next_link=None, previous_link=None
)
) )
def test_only_page(self): def test_only_page(self):
self.do_case( self.do_case(
["foo"], 1, 1, make_paginated_api_response(["foo"], 0, 1, None, None) ["foo"], 1, 1, make_paginated_api_response(
results=["foo"], count=0, num_pages=1, next_link=None, previous_link=None
)
) )
def test_first_of_many(self): def test_first_of_many(self):
self.do_case( self.do_case(
["foo"], 1, 3, make_paginated_api_response( ["foo"], 1, 3, make_paginated_api_response(
["foo"], 0, 3, "http://testserver/test?page=2", None results=["foo"], count=0, num_pages=3, next_link="http://testserver/test?page=2", previous_link=None
) )
) )
def test_last_of_many(self): def test_last_of_many(self):
self.do_case( self.do_case(
["foo"], 3, 3, make_paginated_api_response( ["foo"], 3, 3, make_paginated_api_response(
["foo"], 0, 3, None, "http://testserver/test?page=2" results=["foo"], count=0, num_pages=3, next_link=None, previous_link="http://testserver/test?page=2"
) )
) )
def test_middle_of_many(self): def test_middle_of_many(self):
self.do_case( self.do_case(
["foo"], 2, 3, make_paginated_api_response( ["foo"], 2, 3, make_paginated_api_response(
["foo"], 0, 3, "http://testserver/test?page=3", "http://testserver/test?page=1" results=["foo"],
count=0,
num_pages=3,
next_link="http://testserver/test?page=3",
previous_link="http://testserver/test?page=1"
) )
) )
...@@ -309,11 +309,11 @@ class ThreadViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase): ...@@ -309,11 +309,11 @@ class ThreadViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
self.register_get_threads_response(source_threads, page=1, num_pages=2) self.register_get_threads_response(source_threads, page=1, num_pages=2)
response = self.client.get(self.url, {"course_id": unicode(self.course.id), "following": ""}) response = self.client.get(self.url, {"course_id": unicode(self.course.id), "following": ""})
expected_respoonse = make_paginated_api_response( expected_respoonse = make_paginated_api_response(
expected_threads, results=expected_threads,
0, count=0,
2, num_pages=2,
"http://testserver/api/discussion/v1/threads/?course_id=x%2Fy%2Fz&page=2", next_link="http://testserver/api/discussion/v1/threads/?course_id=x%2Fy%2Fz&page=2",
None previous_link=None
) )
expected_respoonse.update({"text_search_rewrite": None}) expected_respoonse.update({"text_search_rewrite": None})
self.assert_response_correct( self.assert_response_correct(
...@@ -384,7 +384,9 @@ class ThreadViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase): ...@@ -384,7 +384,9 @@ class ThreadViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
{"course_id": unicode(self.course.id), "text_search": "test search string"} {"course_id": unicode(self.course.id), "text_search": "test search string"}
) )
expected_response = make_paginated_api_response([], 0, 0, None, None) expected_response = make_paginated_api_response(
results=[], count=0, num_pages=0, next_link=None, previous_link=None
)
expected_response.update({"text_search_rewrite": None}) expected_response.update({"text_search_rewrite": None})
self.assert_response_correct( self.assert_response_correct(
response, response,
...@@ -414,7 +416,9 @@ class ThreadViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase): ...@@ -414,7 +416,9 @@ class ThreadViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
} }
) )
expected_response = make_paginated_api_response([], 0, 0, None, None) expected_response = make_paginated_api_response(
results=[], count=0, num_pages=0, next_link=None, previous_link=None
)
expected_response.update({"text_search_rewrite": None}) expected_response.update({"text_search_rewrite": None})
self.assert_response_correct( self.assert_response_correct(
response, response,
...@@ -949,7 +953,9 @@ class CommentViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase): ...@@ -949,7 +953,9 @@ class CommentViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
self.assert_response_correct( self.assert_response_correct(
response, response,
200, 200,
make_paginated_api_response(expected_comments, 0, 10, next_link, None) make_paginated_api_response(
results=expected_comments, count=0, num_pages=10, next_link=next_link, previous_link=None
)
) )
self.assert_query_params_equal( self.assert_query_params_equal(
httpretty.httpretty.latest_requests[-2], httpretty.httpretty.latest_requests[-2],
......
...@@ -373,7 +373,7 @@ def make_minimal_cs_comment(overrides=None): ...@@ -373,7 +373,7 @@ def make_minimal_cs_comment(overrides=None):
return ret return ret
def make_paginated_api_response(results, count, num_pages, next_link, previous_link): def make_paginated_api_response(results=[], count=0, num_pages=0, next_link=None, previous_link=None):
""" """
Generates the response dictionary of paginated APIs with passed data Generates the response dictionary of paginated APIs with passed data
""" """
......
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