use pytest.xfail
@@ -159,37 +159,38 @@ class TestDocumentSearch:
assert len(data) == 1
assert data[0]['project'] == project.slug
- # def test_doc_search_pagination(self, api_client, project):
- # """Test Doc search result can be paginated"""
- # latest_version = project.versions.all()[0]
- # html_file = HTMLFile.objects.filter(version=latest_version)[0]
- # title = html_file.processed_json['title']
- # query = title.split()[0]
-
- # # Create 60 more same html file
- # for _ in range(60):
- # # Make primary key to None, so django will create new object
- # html_file.pk = None
- # html_file.save()
- # PageDocument().update(html_file)
-
- # search_params = {'q': query, 'project': project.slug, 'version': latest_version.slug}
- # resp = api_client.get(self.url, search_params)
- # assert resp.status_code == 200
-
- # # Check the count is 61 (1 existing and 60 new created)
- # assert resp.data['count'] == 61
- # # Check there are next url
- # assert resp.data['next'] is not None
- # # There should be only 50 data as the pagination is 50 by default
- # assert len(resp.data['results']) == 50
-
- # # Add `page_size` parameter and check the data is paginated accordingly
- # search_params['page_size'] = 5
- # resp = api_client.get(self.url, search_params)
- # assert resp.status_code == 200
-
- # assert len(resp.data['results']) == 5
+ def test_doc_search_pagination(self, api_client, project):
+ """Test Doc search result can be paginated"""
+ latest_version = project.versions.all()[0]
+ html_file = HTMLFile.objects.filter(version=latest_version)[0]
+ title = html_file.processed_json['title']
+ query = title.split()[0]
+
+ # Create 60 more same html file
+ for _ in range(60):
+ # Make primary key to None, so django will create new object
+ html_file.pk = None
+ html_file.save()
+ PageDocument().update(html_file)
+
+ search_params = {'q': query, 'project': project.slug, 'version': latest_version.slug}
+ resp = api_client.get(self.url, search_params)
+ assert resp.status_code == 200
+
+ # Check the count is 61 (1 existing and 60 new created)
+ if not resp.data['count'] == 61:
+ pytest.xfail('Failing because the value of "count" is wrong.')
+ # Check there are next url
+ assert resp.data['next'] is not None
+ # There should be only 50 data as the pagination is 50 by default
+ assert len(resp.data['results']) == 50
+
+ # Add `page_size` parameter and check the data is paginated accordingly
+ search_params['page_size'] = 5
+ resp = api_client.get(self.url, search_params)
+ assert resp.status_code == 200
+
+ assert len(resp.data['results']) == 5
def test_doc_search_without_parameters(self, api_client, project):
"""Hitting Document Search endpoint without query parameters should return error"""
