Better naming of test fixtures

This commit is contained in:
Tobias Kunze 2025-12-10 12:48:33 +01:00
parent 4dab8e4f92
commit 457bbaadc2
4 changed files with 151 additions and 128 deletions

View file

@ -59,76 +59,76 @@ def test_organization_linked_in_sidebar(
@pytest.mark.django_db
def test_service_detail_redirects_with_single_offering(
client, org_owner, organization, test_service, test_service_offering
client, org_owner, organization, service, service_offering
):
client.force_login(org_owner)
url = f"/org/{organization.slug}/services/{test_service.slug}/"
url = f"/org/{organization.slug}/services/{service.slug}/"
response = client.get(url)
assert response.status_code == 302
expected_url = f"/org/{organization.slug}/services/{test_service.slug}/offering/{test_service_offering.pk}/"
expected_url = f"/org/{organization.slug}/services/{service.slug}/offering/{service_offering.pk}/"
assert response.url == expected_url
@pytest.mark.django_db
def test_service_detail_shows_multiple_offerings(
client, org_owner, organization, test_service, test_service_offering
client, org_owner, organization, service, service_offering
):
second_provider = CloudProvider.objects.create(
name="AWS", description="Amazon Web Services"
)
second_offering = ServiceOffering.objects.create(
service=test_service,
service=service,
provider=second_provider,
description="Redis on AWS",
osb_plan_id="test-plan-456",
)
client.force_login(org_owner)
url = f"/org/{organization.slug}/services/{test_service.slug}/"
url = f"/org/{organization.slug}/services/{service.slug}/"
response = client.get(url)
assert response.status_code == 200
content = response.content.decode()
assert test_service_offering.provider.name in content
assert service_offering.provider.name in content
assert second_offering.provider.name in content
assert "Create Instance" in content
@pytest.mark.django_db
def test_service_detail_respects_cloud_provider_restrictions(
client, org_owner, organization, test_service, test_service_offering
client, org_owner, organization, service, service_offering
):
second_provider = CloudProvider.objects.create(
name="AWS", description="Amazon Web Services"
)
ServiceOffering.objects.create(
service=test_service,
service=service,
provider=second_provider,
description="Redis on AWS",
osb_plan_id="test-plan-456",
)
organization.origin.limit_cloudproviders.add(test_service_offering.provider)
organization.origin.limit_cloudproviders.add(service_offering.provider)
client.force_login(org_owner)
url = f"/org/{organization.slug}/services/{test_service.slug}/"
url = f"/org/{organization.slug}/services/{service.slug}/"
response = client.get(url)
assert response.status_code == 302
expected_url = f"/org/{organization.slug}/services/{test_service.slug}/offering/{test_service_offering.pk}/"
expected_url = f"/org/{organization.slug}/services/{service.slug}/offering/{service_offering.pk}/"
assert response.url == expected_url
@pytest.mark.django_db
def test_service_detail_no_redirect_with_restricted_multiple_offerings(
client, org_owner, organization, test_service, test_service_offering
client, org_owner, organization, service, service_offering
):
second_provider = CloudProvider.objects.create(
name="AWS", description="Amazon Web Services"
)
second_offering = ServiceOffering.objects.create(
service=test_service,
service=service,
provider=second_provider,
description="Redis on AWS",
osb_plan_id="test-plan-456",
@ -137,35 +137,35 @@ def test_service_detail_no_redirect_with_restricted_multiple_offerings(
name="Azure", description="Microsoft Azure"
)
third_offering = ServiceOffering.objects.create(
service=test_service,
service=service,
provider=third_provider,
description="Redis on Azure",
osb_plan_id="test-plan-789",
)
organization.origin.limit_cloudproviders.add(
test_service_offering.provider, second_provider
service_offering.provider, second_provider
)
client.force_login(org_owner)
url = f"/org/{organization.slug}/services/{test_service.slug}/"
url = f"/org/{organization.slug}/services/{service.slug}/"
response = client.get(url)
assert response.status_code == 200
content = response.content.decode()
assert test_service_offering.provider.name in content
assert service_offering.provider.name in content
assert second_offering.provider.name in content
assert third_offering.provider.name not in content
@pytest.mark.django_db
def test_service_instance_update_spec_pushes_display_name_annotation(
organization, test_control_plane_crd, org_owner
organization, control_plane_crd, org_owner
):
instance = ServiceInstance.objects.create(
name="test-instance",
display_name="Original Name",
organization=organization,
context=test_control_plane_crd,
context=control_plane_crd,
)
mock_api = MagicMock()
with (