/
test_page_filters.py
71 lines (66 loc) · 3.76 KB
/
test_page_filters.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from __future__ import annotations
from urllib.parse import urlencode
import pytest
from django.test.client import Client
from django.urls import reverse
@pytest.mark.django_db
def test_page_filters(load_test_data: None, admin_client: Client) -> None:
"""
Test whether duplicating regions works as expected
:param load_test_data: The fixture providing the test data (see :meth:`~tests.conftest.load_test_data`)
:param admin_client: The fixture providing the logged in admin
"""
page_tree = reverse(
"pages", kwargs={"region_slug": "augsburg", "language_slug": "en"}
)
# Get with no data should result in the normal, unfiltered view with only root pages
response = admin_client.get(page_tree)
print(response.headers)
assert response.status_code == 200
# Root pages should be in the result
assert "Welcome" in response.content.decode("utf-8")
# Sub-pages should not be in the result
assert "Trivia about Augsburg" not in response.content.decode("utf-8")
assert "About the Integreat App Augsburg" not in response.content.decode("utf-8")
# Searching for a page should return all results, independently of their level
filter_params: dict[str, str | list[str]] = {"query": "Augsburg"}
response = admin_client.get(f"{page_tree}?{urlencode(filter_params)}")
print(response.headers)
assert response.status_code == 200
# Pages without the query in the title should not be in the result
assert "Welcome" not in response.content.decode("utf-8")
# Pages with the query in the title should be in the result
assert "Trivia about Augsburg" in response.content.decode("utf-8")
assert "About the Integreat App Augsburg" in response.content.decode("utf-8")
# Test filtering for the translation status
filter_params = {"translation_status": ["OUTDATED", "MISSING"]}
response = admin_client.get(f"{page_tree}?{urlencode(filter_params, True)}")
print(f"{page_tree}?{urlencode(filter_params, True)}")
print(response.headers)
assert response.status_code == 200
# Up-to-date pages should not be in the result
assert "Welcome" not in response.content.decode("utf-8")
# Missing and outdated pages should be in the result
assert "Trivia about Augsburg" in response.content.decode("utf-8")
assert "About the Integreat App Augsburg" in response.content.decode("utf-8")
# Test filtering for the translation status and searching at the same time
filter_params = {"query": "Trivia", "translation_status": ["OUTDATED", "MISSING"]}
response = admin_client.get(f"{page_tree}?{urlencode(filter_params, True)}")
print(response.headers)
assert response.status_code == 200
# Up-to-date pages should not be in the result
assert "Welcome" not in response.content.decode("utf-8")
# Missing and outdated pages with "Trivia" in the title should be in the result
assert "Trivia about Augsburg" in response.content.decode("utf-8")
# Missing and outdated pages without "Trivia" should not be in the result
assert "About the Integreat App Augsburg" not in response.content.decode("utf-8")
# Test filtering for the translation status and searching at the same time
filter_params = {"query": "Welco", "translation_status": ["OUTDATED", "MISSING"]}
response = admin_client.get(f"{page_tree}?{urlencode(filter_params, True)}")
print(response.headers)
assert response.status_code == 200
# Up-to-date pages should not be in the result, even if they contain "Welco" in the title
assert "Welcome" not in response.content.decode("utf-8")
# Missing and outdated pages without "Welco" should not be in the result
assert "Trivia about Augsburg" not in response.content.decode("utf-8")
assert "About the Integreat App Augsburg" not in response.content.decode("utf-8")