-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add testcase for a list of nested blocks
- Loading branch information
Showing
5 changed files
with
287 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
test/unit_tests/domain/products/product_blocks/product_block_list_nested.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from typing import List, Optional | ||
|
||
import pytest | ||
|
||
from orchestrator.db import ProductBlockTable, db | ||
from orchestrator.domain.base import ProductBlockModel | ||
from orchestrator.types import SubscriptionLifecycle | ||
|
||
|
||
class ProductBlockListNestedForTestInactive(ProductBlockModel, product_block_name="ProductBlockListNestedForTest"): | ||
sub_block_list: List["ProductBlockListNestedForTestInactive"] | ||
int_field: Optional[int] = None | ||
|
||
|
||
class ProductBlockListNestedForTestProvisioning( | ||
ProductBlockListNestedForTestInactive, lifecycle=[SubscriptionLifecycle.PROVISIONING] | ||
): | ||
sub_block_list: List["ProductBlockListNestedForTestProvisioning"] # type: ignore | ||
int_field: int | ||
|
||
|
||
class ProductBlockListNestedForTest( | ||
ProductBlockListNestedForTestProvisioning, lifecycle=[SubscriptionLifecycle.ACTIVE] | ||
): | ||
sub_block_list: List["ProductBlockListNestedForTest"] # type: ignore | ||
int_field: int | ||
|
||
|
||
@pytest.fixture | ||
def test_product_block_list_nested(): | ||
# Classes defined at module level, otherwise they remain in local namespace and | ||
# `get_type_hints()` can't evaluate the ForwardRefs | ||
return ( | ||
ProductBlockListNestedForTestInactive, | ||
ProductBlockListNestedForTestProvisioning, | ||
ProductBlockListNestedForTest, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def test_product_block_list_nested_db_parent(resource_type_list, resource_type_int, resource_type_str): | ||
parent_block = ProductBlockTable( | ||
name="ProductBlockListNestedForTest", description="Test Block Parent", tag="TEST", status="active" | ||
) | ||
parent_block.resource_types = [resource_type_int] | ||
|
||
db.session.add(parent_block) | ||
db.session.commit() | ||
|
||
return parent_block |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
test/unit_tests/domain/products/product_types/product_type_list_nested.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import pytest | ||
|
||
from orchestrator.db import FixedInputTable, ProductTable, db | ||
from orchestrator.domain import SUBSCRIPTION_MODEL_REGISTRY | ||
from orchestrator.domain.base import ProductModel, SubscriptionModel | ||
from orchestrator.domain.lifecycle import ProductLifecycle | ||
from orchestrator.types import SubscriptionLifecycle | ||
from test.unit_tests.domain.products.product_blocks.product_block_list_nested import ( | ||
ProductBlockListNestedForTest, | ||
ProductBlockListNestedForTestInactive, | ||
ProductBlockListNestedForTestProvisioning, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def test_product_type_list_nested(): | ||
class ProductTypeListNestedForTestInactive(SubscriptionModel, is_base=True): | ||
test_fixed_input: bool | ||
block: ProductBlockListNestedForTestInactive | ||
|
||
class ProductTypeListNestedForTestProvisioning( | ||
ProductTypeListNestedForTestInactive, lifecycle=[SubscriptionLifecycle.PROVISIONING] | ||
): | ||
test_fixed_input: bool | ||
block: ProductBlockListNestedForTestProvisioning | ||
|
||
class ProductTypeListNestedForTest( | ||
ProductTypeListNestedForTestProvisioning, lifecycle=[SubscriptionLifecycle.ACTIVE] | ||
): | ||
test_fixed_input: bool | ||
block: ProductBlockListNestedForTest | ||
|
||
SUBSCRIPTION_MODEL_REGISTRY["TestProductListNested"] = ProductTypeListNestedForTest | ||
yield ProductTypeListNestedForTestInactive, ProductTypeListNestedForTestProvisioning, ProductTypeListNestedForTest | ||
del SUBSCRIPTION_MODEL_REGISTRY["TestProductListNested"] | ||
|
||
|
||
@pytest.fixture | ||
def test_product_list_nested(test_product_block_list_nested_db_parent): | ||
product = ProductTable( | ||
name="TestProductListNested", description="Test ProductTable", product_type="Test", tag="TEST", status="active" | ||
) | ||
|
||
fixed_input = FixedInputTable(name="test_fixed_input", value="False") | ||
|
||
product_block = test_product_block_list_nested_db_parent | ||
product.fixed_inputs = [fixed_input] | ||
product.product_blocks = [product_block] | ||
|
||
db.session.add(product) | ||
db.session.commit() | ||
|
||
return product.product_id | ||
|
||
|
||
@pytest.fixture | ||
def test_product_model_list_nested(test_product_list_nested): | ||
return ProductModel( | ||
product_id=test_product_list_nested, | ||
name="TestProductListNested", | ||
description="Test ProductTable", | ||
product_type="Test", | ||
tag="TEST", | ||
status=ProductLifecycle.ACTIVE, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters