Debian Codegraph @

tests/test_configuration.py

raw
1 """
2 test_configuration
3 ~~~~~~~~~~~~~~~~~~
4
5 Basic configuration tests
6 """
7
8 import base64
9
10 import pytest
11 from tests.test_utils import authenticate, logout
12
13
14 @pytest.mark.settings(
15 logout_url="/custom_logout",
16 login_url="/custom_login",
17 post_login_view="/post_login",
18 post_logout_view="/post_logout",
19 default_http_auth_realm="Custom Realm",
20 )
21 def test_view_configuration(client, get_message):
22 response = client.get("/custom_login")
23 assert b"<h1>Login</h1>" in response.data
24
25 response = authenticate(client, endpoint="/custom_login")
26 assert "location" in response.headers
27 assert "/post_login" in response.location
28
29 response = logout(client, endpoint="/custom_logout")
30 assert "location" in response.headers
31 assert "/post_logout" in response.location
32
33 response = client.get(
34 "/http",
35 headers={"Authorization": "Basic %s" % base64.b64encode(b"[email protected]:bogus")},
36 )
37 assert response.status_code == 401
38 assert get_message("UNAUTHENTICATED") in response.data
39 assert "WWW-Authenticate" in response.headers
40 assert 'Basic realm="Custom Realm"' == response.headers["WWW-Authenticate"]
41
42
43 @pytest.mark.settings(login_user_template="custom_security/login_user.html")
44 def test_template_configuration(client):
45 response = client.get("/login")
46 assert b"CUSTOM LOGIN USER" in response.data