diff --git a/poetry.lock b/poetry.lock index 601bba6..c2ee037 100644 --- a/poetry.lock +++ b/poetry.lock @@ -53,6 +53,21 @@ docs = ["furo", "sphinx", "zope.interface", "sphinx-notfound-page"] tests = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "zope.interface", "cloudpickle"] tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "cloudpickle"] +[[package]] +name = "beautifulsoup4" +version = "4.11.1" +description = "Screen-scraping library" +category = "dev" +optional = false +python-versions = ">=3.6.0" + +[package.dependencies] +soupsieve = ">1.2" + +[package.extras] +html5lib = ["html5lib"] +lxml = ["lxml"] + [[package]] name = "black" version = "22.6.0" @@ -746,6 +761,14 @@ category = "main" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" +[[package]] +name = "soupsieve" +version = "2.3.2.post1" +description = "A modern CSS selector implementation for Beautiful Soup." +category = "dev" +optional = false +python-versions = ">=3.6" + [[package]] name = "sqlparse" version = "0.4.2" @@ -880,7 +903,7 @@ testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest- [metadata] lock-version = "1.1" python-versions = ">=3.7,<4.0.0" -content-hash = "efbe068c32696bda78b96c5bc9d05217a92a8f19ef832d444cdd6e6b99a5223c" +content-hash = "0262d33ea15ad4ec9e8234cd55634c1c34df4ce3f878c268fb1b3c8da5b94f7a" [metadata.files] asgiref = [ @@ -902,6 +925,10 @@ attrs = [ {file = "attrs-21.4.0-py2.py3-none-any.whl", hash = "sha256:2d27e3784d7a565d36ab851fe94887c5eccd6a463168875832a1be79c82828b4"}, {file = "attrs-21.4.0.tar.gz", hash = "sha256:626ba8234211db98e869df76230a137c4c40a12d72445c45d5f5b716f076e2fd"}, ] +beautifulsoup4 = [ + {file = "beautifulsoup4-4.11.1-py3-none-any.whl", hash = "sha256:58d5c3d29f5a36ffeb94f02f0d786cd53014cf9b3b3951d42e0080d8a9498d30"}, + {file = "beautifulsoup4-4.11.1.tar.gz", hash = "sha256:ad9aa55b65ef2808eb405f46cf74df7fcb7044d5cbc26487f96eb2ef2e436693"}, +] black = [ {file = "black-22.6.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:f586c26118bc6e714ec58c09df0157fe2d9ee195c764f630eb0d8e7ccce72e69"}, {file = "black-22.6.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:b270a168d69edb8b7ed32c193ef10fd27844e5c60852039599f9184460ce0807"}, @@ -1193,6 +1220,10 @@ six = [ {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"}, {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"}, ] +soupsieve = [ + {file = "soupsieve-2.3.2.post1-py3-none-any.whl", hash = "sha256:3b2503d3c7084a42b1ebd08116e5f81aadfaea95863628c80a3b774a11b7c759"}, + {file = "soupsieve-2.3.2.post1.tar.gz", hash = "sha256:fc53893b3da2c33de295667a0e19f078c14bf86544af307354de5fcf12a3f30d"}, +] sqlparse = [ {file = "sqlparse-0.4.2-py3-none-any.whl", hash = "sha256:48719e356bb8b42991bdbb1e8b83223757b93789c00910a616a071910ca4a64d"}, {file = "sqlparse-0.4.2.tar.gz", hash = "sha256:0c00730c74263a94e5a9919ade150dfc3b19c574389985446148402998287dae"}, diff --git a/pyproject.toml b/pyproject.toml index 3ef718f..25fd370 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,6 +30,7 @@ flake8 = "*" flynt = "*" darker = "*" # https://github.com/akaihola/darker pyupgrade = "*" +beautifulsoup4 = "*" [build-system] requires = ["poetry-core>=1.0.0"] diff --git a/tests/test_django_project.py b/tests/test_django_project.py index 7141f9f..b12b967 100644 --- a/tests/test_django_project.py +++ b/tests/test_django_project.py @@ -1,8 +1,12 @@ from pathlib import Path -from bx_django_utils.test_utils.html_assertion import HtmlAssertionMixin +from bx_django_utils.test_utils.html_assertion import ( + HtmlAssertionMixin, + assert_html_response_snapshot, +) from django.conf import LazySettings, settings from django.contrib.auth.models import User +from django.http import FileResponse, HttpResponse from django.test import override_settings from django.test.testcases import TestCase from django.urls import NoReverseMatch @@ -10,7 +14,7 @@ from django.urls.base import reverse from django_yunohost_integration.test_utils import generate_basic_auth from django_yunohost_integration.views import request_media_debug_view -import findmydevice +from findmydevice import __version__ @override_settings(DEBUG=False) @@ -57,23 +61,43 @@ class DjangoYnhTestCase(HtmlAssertionMixin, TestCase): ) response = self.client.get('/app_path/', secure=True) - self.assertRedirects( - response, expected_url='/app_path/group_management/', fetch_redirect_response=False - ) - - response = self.client.get('/app_path/group_management/', secure=True) - self.assertRedirects( + self.assertTemplateUsed(response, 'fmd/login_info.html') + self.assert_html_parts( response, - expected_url='/app_path/admin/login/?next=/app_path/group_management/', - fetch_redirect_response=False, + parts=( + '
To find your device, you must be logged in.
', + 'Log in', + ), ) + assert_html_response_snapshot(response, query_selector=None, validate=False) - response = self.client.get('/app_path/admin/', secure=True) - self.assertRedirects( - response, - expected_url='/app_path/admin/login/?next=/app_path/admin/', - fetch_redirect_response=False, + def test_web_page_as_sso_user(self): + assert User.objects.count() == 0 + self.client.cookies['SSOwAuthUser'] = 'test' + response = self.client.get( + path='/app_path/', + HTTP_REMOTE_USER='test', + HTTP_AUTH_USER='test', + HTTP_AUTHORIZATION='basic dGVzdDp0ZXN0MTIz', + secure=True, ) + assert isinstance(response, FileResponse) + + assert User.objects.count() == 1 + user = User.objects.first() + assert user.username == 'test' + + response2 = HttpResponse(response.getvalue()) + self.assert_html_parts( + response2, + parts=( + '
+ This server tracks all your registered devices.
+
+ Please enter the device-id to receive the latest
+ location:
+