Add test showing that annotations are pushed
This commit is contained in:
parent
f9ba2d6c2c
commit
337774cc7a
1 changed files with 68 additions and 1 deletions
|
|
@ -1,6 +1,14 @@
|
|||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from servala.core.models.service import CloudProvider, ServiceOffering
|
||||
from servala.core.models.service import (
|
||||
CloudProvider,
|
||||
ControlPlane,
|
||||
ControlPlaneCRD,
|
||||
ServiceInstance,
|
||||
ServiceOffering,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
@ -147,3 +155,62 @@ def test_service_detail_no_redirect_with_restricted_multiple_offerings(
|
|||
assert test_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
|
||||
):
|
||||
instance = ServiceInstance.objects.create(
|
||||
name="test-instance",
|
||||
display_name="Original Name",
|
||||
organization=organization,
|
||||
context=test_control_plane_crd,
|
||||
)
|
||||
mock_api = MagicMock()
|
||||
with (
|
||||
patch.object(ControlPlane, "custom_objects_api", mock_api),
|
||||
patch.object(ControlPlaneCRD, "kind_plural", "testkinds"),
|
||||
):
|
||||
instance.display_name = "Updated Name"
|
||||
instance.update_spec(spec_data={}, updated_by=org_owner)
|
||||
mock_api.patch_namespaced_custom_object.assert_called_once()
|
||||
call_kwargs = mock_api.patch_namespaced_custom_object.call_args[1]
|
||||
assert "metadata" in call_kwargs["body"]
|
||||
annotations = call_kwargs["body"]["metadata"]["annotations"]
|
||||
assert annotations["servala.com/displayName"] == "Updated Name"
|
||||
|
||||
instance.refresh_from_db()
|
||||
assert instance.display_name == "Updated Name"
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_build_billing_annotations_includes_display_name():
|
||||
annotations = ServiceInstance._build_billing_annotations(
|
||||
compute_plan_assignment=None,
|
||||
control_plane=MagicMock(
|
||||
storage_plan_odoo_product_id=None,
|
||||
storage_plan_odoo_unit_id=None,
|
||||
),
|
||||
instance_name="test-instance",
|
||||
display_name="My Display Name",
|
||||
organization=None,
|
||||
service=None,
|
||||
)
|
||||
assert annotations["servala.com/displayName"] == "My Display Name"
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_build_billing_annotations_omits_display_name_when_none():
|
||||
annotations = ServiceInstance._build_billing_annotations(
|
||||
compute_plan_assignment=None,
|
||||
control_plane=MagicMock(
|
||||
storage_plan_odoo_product_id=None,
|
||||
storage_plan_odoo_unit_id=None,
|
||||
),
|
||||
instance_name="test-instance",
|
||||
display_name=None,
|
||||
organization=None,
|
||||
service=None,
|
||||
)
|
||||
assert "servala.com/displayName" not in annotations
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue