|
1 | 1 | import re
|
2 |
| -import pytest |
3 | 2 |
|
| 3 | +import pytest |
4 | 4 | from django.core.urlresolvers import reverse
|
5 | 5 | from django_dynamic_fixture import G
|
6 | 6 |
|
7 | 7 | from readthedocs.builds.models import Version
|
8 |
| -from readthedocs.projects.models import HTMLFile |
| 8 | +from readthedocs.projects.models import HTMLFile, Project |
| 9 | +from readthedocs.search.documents import PageDocument |
9 | 10 | from readthedocs.search.tests.utils import (
|
10 |
| - get_search_query_from_project_file, |
11 |
| - SECTION_FIELDS, |
12 | 11 | DOMAIN_FIELDS,
|
| 12 | + SECTION_FIELDS, |
| 13 | + get_search_query_from_project_file, |
13 | 14 | )
|
14 |
| -from readthedocs.search.documents import PageDocument |
15 | 15 |
|
16 | 16 |
|
17 | 17 | @pytest.mark.django_db
|
@@ -224,3 +224,30 @@ def test_doc_search_subprojects(self, api_client, all_projects):
|
224 | 224 | # Check the link is the subproject document link
|
225 | 225 | document_link = subproject.get_docs_url(version_slug=version.slug)
|
226 | 226 | assert document_link in first_result['link']
|
| 227 | + |
| 228 | + def test_doc_search_unexisting_project(self, api_client): |
| 229 | + project = 'notfound' |
| 230 | + assert not Project.objects.filter(slug=project).exists() |
| 231 | + |
| 232 | + search_params = { |
| 233 | + 'q': 'documentation', |
| 234 | + 'project': project, |
| 235 | + 'version': 'latest', |
| 236 | + } |
| 237 | + resp = api_client.get(self.url, search_params) |
| 238 | + assert resp.status_code == 404 |
| 239 | + |
| 240 | + def test_doc_search_unexisting_version(self, api_client, project): |
| 241 | + version = 'notfound' |
| 242 | + assert not project.versions.filter(slug=version).exists() |
| 243 | + |
| 244 | + search_params = { |
| 245 | + 'q': 'documentation', |
| 246 | + 'project': project.slug, |
| 247 | + 'version': version, |
| 248 | + } |
| 249 | + resp = api_client.get(self.url, search_params) |
| 250 | + assert resp.status_code == 200 |
| 251 | + |
| 252 | + data = resp.data['results'] |
| 253 | + assert len(data) == 0 |
0 commit comments