Reduce test verbosity
This commit is contained in:
parent
84c0220af0
commit
7fc85108cf
1 changed files with 59 additions and 131 deletions
|
|
@ -187,28 +187,68 @@ def test_build_billing_annotations_empty():
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_hour_unit():
|
@pytest.mark.parametrize(
|
||||||
|
"unit_key,expected_display",
|
||||||
|
[
|
||||||
|
("hour", "Hour"),
|
||||||
|
("day", "Day"),
|
||||||
|
("year", "Year"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_billing_unit_choices(unit_key, expected_display):
|
||||||
choices = dict(ComputePlanAssignment.BILLING_UNIT_CHOICES)
|
choices = dict(ComputePlanAssignment.BILLING_UNIT_CHOICES)
|
||||||
assert "hour" in choices
|
assert unit_key in choices
|
||||||
assert str(choices["hour"]) == "Hour"
|
assert str(choices[unit_key]) == expected_display
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_all_billing_units():
|
def test_billing_unit_month():
|
||||||
|
"""Month has a special display format with additional info."""
|
||||||
choices = dict(ComputePlanAssignment.BILLING_UNIT_CHOICES)
|
choices = dict(ComputePlanAssignment.BILLING_UNIT_CHOICES)
|
||||||
|
|
||||||
assert "hour" in choices
|
|
||||||
assert "day" in choices
|
|
||||||
assert "month" in choices
|
assert "month" in choices
|
||||||
assert "year" in choices
|
|
||||||
|
|
||||||
assert str(choices["hour"]) == "Hour"
|
|
||||||
assert str(choices["day"]) == "Day"
|
|
||||||
assert "Month" in str(choices["month"])
|
assert "Month" in str(choices["month"])
|
||||||
assert str(choices["year"]) == "Year"
|
|
||||||
|
|
||||||
|
|
||||||
def test_build_billing_annotations_by_service_grouping():
|
@pytest.mark.parametrize(
|
||||||
|
"invoice_grouping,org_name,osb_guid,expected_group_desc,expected_item_desc",
|
||||||
|
[
|
||||||
|
pytest.param(
|
||||||
|
InvoiceGroupingChoice.BY_SERVICE,
|
||||||
|
"ACME Corp",
|
||||||
|
"some-guid",
|
||||||
|
"Servala Service: Redis",
|
||||||
|
"MyProdRedis on Exoscale Geneva (CH-GVA-2)",
|
||||||
|
id="by_service",
|
||||||
|
),
|
||||||
|
pytest.param(
|
||||||
|
InvoiceGroupingChoice.BY_ORGANIZATION,
|
||||||
|
"ACME",
|
||||||
|
"01998651-dc86-7d43-9e49-cdb790fcc4f0",
|
||||||
|
"Organization: ACME (01998651-dc86-7d43-9e49-cdb790fcc4f0)",
|
||||||
|
"MyProdRedis on Geneva (CH-GVA-2) [Org: 01998651-dc86-7d43-9e49-cdb790fcc4f0]",
|
||||||
|
id="by_organization_with_guid",
|
||||||
|
),
|
||||||
|
pytest.param(
|
||||||
|
InvoiceGroupingChoice.BY_ORGANIZATION,
|
||||||
|
"ACME Corp",
|
||||||
|
None,
|
||||||
|
"Organization: ACME Corp",
|
||||||
|
"MyProdRedis on Geneva (CH-GVA-2)",
|
||||||
|
id="by_organization_without_guid",
|
||||||
|
),
|
||||||
|
pytest.param(
|
||||||
|
InvoiceGroupingChoice.BY_ORGANIZATION,
|
||||||
|
"ACME Corp",
|
||||||
|
"",
|
||||||
|
"Organization: ACME Corp",
|
||||||
|
"MyProdRedis on Geneva (CH-GVA-2)",
|
||||||
|
id="by_organization_with_empty_guid",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_build_billing_annotations_item_description(
|
||||||
|
invoice_grouping, org_name, osb_guid, expected_group_desc, expected_item_desc
|
||||||
|
):
|
||||||
control_plane = Mock()
|
control_plane = Mock()
|
||||||
control_plane.storage_plan_odoo_product_id = None
|
control_plane.storage_plan_odoo_product_id = None
|
||||||
control_plane.storage_plan_odoo_unit_id = None
|
control_plane.storage_plan_odoo_unit_id = None
|
||||||
|
|
@ -217,10 +257,10 @@ def test_build_billing_annotations_by_service_grouping():
|
||||||
control_plane.name = "Geneva (CH-GVA-2)"
|
control_plane.name = "Geneva (CH-GVA-2)"
|
||||||
|
|
||||||
organization = Mock()
|
organization = Mock()
|
||||||
organization.name = "ACME Corp"
|
organization.name = org_name
|
||||||
organization.osb_guid = "01998651-dc86-7d43-9e49-cdb790fcc4f0"
|
organization.osb_guid = osb_guid
|
||||||
organization.origin = Mock()
|
organization.origin = Mock()
|
||||||
organization.origin.invoice_grouping = InvoiceGroupingChoice.BY_SERVICE
|
organization.origin.invoice_grouping = invoice_grouping
|
||||||
|
|
||||||
service = Mock()
|
service = Mock()
|
||||||
service.name = "Redis"
|
service.name = "Redis"
|
||||||
|
|
@ -233,119 +273,8 @@ def test_build_billing_annotations_by_service_grouping():
|
||||||
service=service,
|
service=service,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert annotations["servala.com/erp_item_group_description"] == expected_group_desc
|
||||||
annotations["servala.com/erp_item_group_description"]
|
assert annotations["servala.com/erp_item_description"] == expected_item_desc
|
||||||
== "Servala Service: Redis"
|
|
||||||
)
|
|
||||||
assert (
|
|
||||||
annotations["servala.com/erp_item_description"]
|
|
||||||
== "MyProdRedis on Exoscale Geneva (CH-GVA-2)"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_build_billing_annotations_by_organization_grouping_with_osb_guid():
|
|
||||||
control_plane = Mock()
|
|
||||||
control_plane.storage_plan_odoo_product_id = None
|
|
||||||
control_plane.storage_plan_odoo_unit_id = None
|
|
||||||
control_plane.cloud_provider = Mock()
|
|
||||||
control_plane.cloud_provider.name = "Exoscale"
|
|
||||||
control_plane.name = "Geneva (CH-GVA-2)"
|
|
||||||
|
|
||||||
organization = Mock()
|
|
||||||
organization.name = "ACME"
|
|
||||||
organization.osb_guid = "01998651-dc86-7d43-9e49-cdb790fcc4f0"
|
|
||||||
organization.origin = Mock()
|
|
||||||
organization.origin.invoice_grouping = InvoiceGroupingChoice.BY_ORGANIZATION
|
|
||||||
|
|
||||||
service = Mock()
|
|
||||||
service.name = "Redis"
|
|
||||||
|
|
||||||
annotations = ServiceInstance._build_billing_annotations(
|
|
||||||
compute_plan_assignment=None,
|
|
||||||
control_plane=control_plane,
|
|
||||||
instance_name="MyProdRedis",
|
|
||||||
organization=organization,
|
|
||||||
service=service,
|
|
||||||
)
|
|
||||||
|
|
||||||
assert (
|
|
||||||
annotations["servala.com/erp_item_group_description"]
|
|
||||||
== "Organization: ACME (01998651-dc86-7d43-9e49-cdb790fcc4f0)"
|
|
||||||
)
|
|
||||||
assert (
|
|
||||||
annotations["servala.com/erp_item_description"]
|
|
||||||
== "MyProdRedis on Geneva (CH-GVA-2) [Org: 01998651-dc86-7d43-9e49-cdb790fcc4f0]"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_build_billing_annotations_by_organization_grouping_without_osb_guid():
|
|
||||||
control_plane = Mock()
|
|
||||||
control_plane.storage_plan_odoo_product_id = None
|
|
||||||
control_plane.storage_plan_odoo_unit_id = None
|
|
||||||
control_plane.cloud_provider = Mock()
|
|
||||||
control_plane.cloud_provider.name = "Exoscale"
|
|
||||||
control_plane.name = "Geneva (CH-GVA-2)"
|
|
||||||
|
|
||||||
organization = Mock()
|
|
||||||
organization.name = "ACME Corp"
|
|
||||||
organization.osb_guid = None # No OSB GUID
|
|
||||||
organization.origin = Mock()
|
|
||||||
organization.origin.invoice_grouping = InvoiceGroupingChoice.BY_ORGANIZATION
|
|
||||||
|
|
||||||
service = Mock()
|
|
||||||
service.name = "Redis"
|
|
||||||
|
|
||||||
annotations = ServiceInstance._build_billing_annotations(
|
|
||||||
compute_plan_assignment=None,
|
|
||||||
control_plane=control_plane,
|
|
||||||
instance_name="MyProdRedis",
|
|
||||||
organization=organization,
|
|
||||||
service=service,
|
|
||||||
)
|
|
||||||
|
|
||||||
assert (
|
|
||||||
annotations["servala.com/erp_item_group_description"]
|
|
||||||
== "Organization: ACME Corp"
|
|
||||||
)
|
|
||||||
assert (
|
|
||||||
annotations["servala.com/erp_item_description"]
|
|
||||||
== "MyProdRedis on Geneva (CH-GVA-2)"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_build_billing_annotations_by_organization_grouping_with_empty_osb_guid():
|
|
||||||
control_plane = Mock()
|
|
||||||
control_plane.storage_plan_odoo_product_id = None
|
|
||||||
control_plane.storage_plan_odoo_unit_id = None
|
|
||||||
control_plane.cloud_provider = Mock()
|
|
||||||
control_plane.cloud_provider.name = "Exoscale"
|
|
||||||
control_plane.name = "Geneva (CH-GVA-2)"
|
|
||||||
|
|
||||||
organization = Mock()
|
|
||||||
organization.name = "ACME Corp"
|
|
||||||
organization.osb_guid = "" # Empty string OSB GUID
|
|
||||||
organization.origin = Mock()
|
|
||||||
organization.origin.invoice_grouping = InvoiceGroupingChoice.BY_ORGANIZATION
|
|
||||||
|
|
||||||
service = Mock()
|
|
||||||
service.name = "Redis"
|
|
||||||
|
|
||||||
annotations = ServiceInstance._build_billing_annotations(
|
|
||||||
compute_plan_assignment=None,
|
|
||||||
control_plane=control_plane,
|
|
||||||
instance_name="MyProdRedis",
|
|
||||||
organization=organization,
|
|
||||||
service=service,
|
|
||||||
)
|
|
||||||
|
|
||||||
assert (
|
|
||||||
annotations["servala.com/erp_item_group_description"]
|
|
||||||
== "Organization: ACME Corp"
|
|
||||||
)
|
|
||||||
assert (
|
|
||||||
annotations["servala.com/erp_item_description"]
|
|
||||||
== "MyProdRedis on Geneva (CH-GVA-2)"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_build_billing_annotations_no_item_description_without_organization():
|
def test_build_billing_annotations_no_item_description_without_organization():
|
||||||
|
|
@ -357,13 +286,12 @@ def test_build_billing_annotations_no_item_description_without_organization():
|
||||||
compute_plan_assignment=None,
|
compute_plan_assignment=None,
|
||||||
control_plane=control_plane,
|
control_plane=control_plane,
|
||||||
instance_name="MyProdRedis",
|
instance_name="MyProdRedis",
|
||||||
organization=None, # No organization
|
organization=None,
|
||||||
service=None,
|
service=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert "servala.com/erp_item_group_description" not in annotations
|
assert "servala.com/erp_item_group_description" not in annotations
|
||||||
assert "servala.com/erp_item_description" not in annotations
|
assert "servala.com/erp_item_description" not in annotations
|
||||||
# Storage annotations should still be there
|
|
||||||
assert annotations["servala.com/erp_product_id_storage"] == "storage-product"
|
assert annotations["servala.com/erp_product_id_storage"] == "storage-product"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue