address-service/address/tests/test_admin.py

62 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import uuid
import pytest
from django.contrib.auth.models import User
from django.test import Client
from address.models import AddressObject, House
@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("/api-address/admin/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(
f"/api-address/admin/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(f"/api-address/admin/address/house/?parent={parent.pk}")
assert response.status_code == 200
assert "д. 10" in response.content.decode()