Skip to content

Commit 73cb70b

Browse files
authored
Merge pull request #186 from AAdewunmi/feat/test-forbidden-rendering-and-seed-idempotency
Feat/test forbidden rendering and seed idempotency
2 parents 11fdaea + 8f2dd92 commit 73cb70b

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

tests/test_forbidden_template.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""Integration tests for shared forbidden page rendering."""
2+
3+
from __future__ import annotations
4+
5+
import pytest
6+
from django.contrib.auth.models import Group
7+
from django.urls import reverse
8+
9+
from accounts.constants import GROUP_NAMES, ROLE_CUSTOMER
10+
11+
pytestmark = pytest.mark.django_db
12+
13+
14+
def test_wrong_role_renders_shared_403_page(client, django_user_model):
15+
"""Authenticated wrong-role access should render the shared forbidden template."""
16+
17+
group, _ = Group.objects.get_or_create(name=GROUP_NAMES[ROLE_CUSTOMER])
18+
user = django_user_model.objects.create_user(
19+
"customer.nav",
20+
"customer.nav@example.com",
21+
"pass-12345",
22+
)
23+
user.groups.add(group)
24+
25+
client.force_login(user)
26+
response = client.get(reverse("accounts:console_ops"))
27+
28+
assert response.status_code == 403
29+
assert b"403 Forbidden" in response.content
30+
assert b"This surface is outside your current access level." in response.content
31+
assert b"Go to sign in" in response.content

tests/test_seed_returnhub_demo.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""Integration tests for the deterministic demo seed command."""
2+
3+
from __future__ import annotations
4+
5+
import pytest
6+
from django.core.management import call_command
7+
8+
from accounts.models import CustomerProfile, MerchantProfile
9+
from returns.models import ReturnCase
10+
11+
pytestmark = pytest.mark.django_db
12+
13+
14+
def test_seed_returnhub_demo_is_idempotent():
15+
"""Running the seed command twice should keep stable totals."""
16+
17+
call_command("seed_returnhub_demo")
18+
first_case_count = ReturnCase.objects.count()
19+
first_customer_count = CustomerProfile.objects.count()
20+
first_merchant_count = MerchantProfile.objects.count()
21+
22+
call_command("seed_returnhub_demo")
23+
24+
assert first_case_count == 32
25+
assert ReturnCase.objects.count() == 32
26+
assert CustomerProfile.objects.count() == first_customer_count == 2
27+
assert MerchantProfile.objects.count() == first_merchant_count == 2
28+
29+
30+
def test_seed_returnhub_demo_creates_page_two_coverage():
31+
"""Seeded data should provide enough cases for page 2 in customer and merchant portals."""
32+
33+
call_command("seed_returnhub_demo")
34+
35+
customer_one_cases = ReturnCase.objects.filter(customer__user__username="customer.one").count()
36+
merchant_one_cases = ReturnCase.objects.filter(merchant__user__username="merchant.one").count()
37+
38+
assert customer_one_cases == 16
39+
assert merchant_one_cases == 16
40+
assert ReturnCase.objects.filter(customer__user__username="customer.two").count() == 16
41+
assert ReturnCase.objects.filter(merchant__user__username="merchant.two").count() == 16

0 commit comments

Comments
 (0)