File: test_url_cache.py

package info (click to toggle)
python-django-pgschemas 1.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 848 kB
  • sloc: python: 3,887; makefile: 33; sh: 10; sql: 2
file content (55 lines) | stat: -rw-r--r-- 1,621 bytes parent folder | download | duplicates (2)
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
import pytest
from django.apps import apps
from django.test import Client


@pytest.fixture
def UserModel():
    return apps.get_model("shared_common.User")


@pytest.fixture(autouse=True)
def _setup(tenant1, tenant2, DomainModel, UserModel):
    if DomainModel is None:
        pytest.skip("Domain model is not in use")

    DomainModel.objects.create(
        tenant=tenant1, domain="everyone.localhost", folder="tenant1", is_primary=True
    )
    DomainModel.objects.create(
        tenant=tenant2, domain="everyone.localhost", folder="tenant2", is_primary=True
    )
    with tenant1:
        UserModel.objects.create(email="user1@localhost", display_name="Admin")

    with tenant2:
        UserModel.objects.create(email="user2@localhost", display_name="Admin")


@pytest.fixture
def client():
    return Client(headers={"host": "everyone.localhost"})


@pytest.mark.bug
def test_bug_in_cached_urls_1(client):
    # Provoke redirect to login on tenant2
    client.get("/tenant2/profile/advanced/")

    # Provoke redirect to login on tenant1
    buggy_response = client.get("/tenant1/profile/advanced/")

    assert buggy_response.status_code == 302
    assert buggy_response.url == "/tenant1/login/?next=/tenant1/profile/advanced/"


@pytest.mark.bug
def test_bug_in_cached_urls_2(client):
    # Provoke redirect to login on tenant1
    client.get("/tenant1/profile/advanced/")

    # Provoke redirect to login on tenant2
    buggy_response = client.get("/tenant2/profile/advanced/")

    assert buggy_response.status_code == 302
    assert buggy_response.url == "/tenant2/login/?next=/tenant2/profile/advanced/"