63 lines
1.8 KiB
Python
63 lines
1.8 KiB
Python
import uuid
|
||
|
||
import pytest
|
||
from django.contrib.auth.models import User
|
||
from django.test import Client
|
||
|
||
from address.models import AddressObject, House
|
||
from address.tests.paths import admin_url
|
||
|
||
|
||
@pytest.fixture
|
||
def admin_client(db):
|
||
user = User.objects.create_superuser("admin", "admin@example.com", "secret")
|
||
client = Client()
|
||
client.force_login(user)
|
||
return client
|
||
|
||
|
||
@pytest.mark.django_db
|
||
def test_address_admin_has_children_filter_link(admin_client):
|
||
parent = AddressObject.objects.create(
|
||
fias_id=uuid.uuid4(),
|
||
name="Владивосток",
|
||
type_name="г",
|
||
level=AddressObject.Level.CITY,
|
||
region_code=25,
|
||
)
|
||
child = AddressObject.objects.create(
|
||
fias_id=uuid.uuid4(),
|
||
name="Светланская",
|
||
type_name="ул",
|
||
level=AddressObject.Level.STREET,
|
||
region_code=25,
|
||
parent=parent,
|
||
)
|
||
House.objects.create(
|
||
object_id=500,
|
||
fias_id=uuid.uuid4(),
|
||
region_code=25,
|
||
house_number="10",
|
||
house_type=House.Type.HOUSE,
|
||
parent=parent,
|
||
)
|
||
|
||
response = admin_client.get(admin_url("address/addressobject/"))
|
||
assert response.status_code == 200
|
||
html = response.content.decode()
|
||
assert f"?parent={parent.pk}" in html
|
||
assert "объекты (1)" in html
|
||
assert "дома (1)" in html
|
||
|
||
response = admin_client.get(
|
||
admin_url("address/addressobject/"), {"parent": parent.pk}
|
||
)
|
||
assert response.status_code == 200
|
||
html = response.content.decode()
|
||
assert child.name in html
|
||
assert parent.name not in html or html.count(child.name) >= 1
|
||
|
||
response = admin_client.get(admin_url("address/house/"), {"parent": parent.pk})
|
||
assert response.status_code == 200
|
||
assert "д. 10" in response.content.decode()
|