-
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 generator testcase for a product with a nested product block
Signed-off-by: Mark90 <[email protected]>
- Loading branch information
Showing
19 changed files
with
573 additions
and
6 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
101 changes: 101 additions & 0 deletions
101
...ests/cli/data/generate/migrations/versions/schema/2024-06-07_380a5b0c928c_add_example4.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,101 @@ | ||
"""Add example4 product. | ||
Revision ID: 380a5b0c928c | ||
Revises: 44667c4d16cd | ||
Create Date: 2024-06-07 10:23:26.761903 | ||
""" | ||
|
||
from uuid import uuid4 | ||
|
||
from alembic import op | ||
from orchestrator.migrations.helpers import create, create_workflow, delete, delete_workflow, ensure_default_workflows | ||
from orchestrator.targets import Target | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "380a5b0c928c" | ||
down_revision = "ea9e6c9de75c" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
new_products = { | ||
"products": { | ||
"example4": { | ||
"product_id": uuid4(), | ||
"product_type": "Example4", | ||
"description": "Product example 4", | ||
"tag": "EXAMPLE4", | ||
"status": "active", | ||
"root_product_block": "Example4", | ||
"fixed_inputs": {}, | ||
}, | ||
}, | ||
"product_blocks": { | ||
"Example4Sub": { | ||
"product_block_id": uuid4(), | ||
"description": "example 4 sub product block", | ||
"tag": "EXAMPLE4SUB", | ||
"status": "active", | ||
"resources": { | ||
"str_val": "", | ||
}, | ||
"depends_on_block_relations": [], | ||
}, | ||
"Example4": { | ||
"product_block_id": uuid4(), | ||
"description": "Example 4 root product block", | ||
"tag": "EXAMPLE4", | ||
"status": "active", | ||
"resources": { | ||
"num_val": "", | ||
}, | ||
"depends_on_block_relations": [ | ||
"Example4Sub", | ||
], | ||
}, | ||
}, | ||
"workflows": {}, | ||
} | ||
|
||
new_workflows = [ | ||
{ | ||
"name": "create_example4", | ||
"target": Target.CREATE, | ||
"description": "Create example4", | ||
"product_type": "Example4", | ||
}, | ||
{ | ||
"name": "modify_example4", | ||
"target": Target.MODIFY, | ||
"description": "Modify example4", | ||
"product_type": "Example4", | ||
}, | ||
{ | ||
"name": "terminate_example4", | ||
"target": Target.TERMINATE, | ||
"description": "Terminate example4", | ||
"product_type": "Example4", | ||
}, | ||
{ | ||
"name": "validate_example4", | ||
"target": Target.SYSTEM, | ||
"description": "Validate example4", | ||
"product_type": "Example4", | ||
}, | ||
] | ||
|
||
|
||
def upgrade() -> None: | ||
conn = op.get_bind() | ||
create(conn, new_products) | ||
for workflow in new_workflows: | ||
create_workflow(conn, workflow) | ||
ensure_default_workflows(conn) | ||
|
||
|
||
def downgrade() -> None: | ||
conn = op.get_bind() | ||
for workflow in new_workflows: | ||
delete_workflow(conn, workflow["name"]) | ||
|
||
delete(conn, new_products) |
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
26 changes: 26 additions & 0 deletions
26
test/unit_tests/cli/data/generate/products/product_blocks/example4.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,26 @@ | ||
from orchestrator.domain.base import ProductBlockModel | ||
from orchestrator.types import SubscriptionLifecycle | ||
from pydantic import computed_field | ||
|
||
from products.product_blocks.example4sub import Example4SubBlock, Example4SubBlockInactive, Example4SubBlockProvisioning | ||
|
||
|
||
class Example4BlockInactive(ProductBlockModel, product_block_name="Example4"): | ||
num_val: int | None = None | ||
sub_block: Example4SubBlockInactive | None = None | ||
|
||
|
||
class Example4BlockProvisioning(Example4BlockInactive, lifecycle=[SubscriptionLifecycle.PROVISIONING]): | ||
num_val: int | None = None | ||
sub_block: Example4SubBlockProvisioning | ||
|
||
@computed_field | ||
@property | ||
def title(self) -> str: | ||
# TODO: format correct title string | ||
return f"{self.name}" | ||
|
||
|
||
class Example4Block(Example4BlockProvisioning, lifecycle=[SubscriptionLifecycle.ACTIVE]): | ||
num_val: int | None = None | ||
sub_block: Example4SubBlock |
21 changes: 21 additions & 0 deletions
21
test/unit_tests/cli/data/generate/products/product_blocks/example4sub.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,21 @@ | ||
from orchestrator.domain.base import ProductBlockModel | ||
from orchestrator.types import SubscriptionLifecycle | ||
from pydantic import computed_field | ||
|
||
|
||
class Example4SubBlockInactive(ProductBlockModel, product_block_name="Example4 Sub"): | ||
str_val: str | None = None | ||
|
||
|
||
class Example4SubBlockProvisioning(Example4SubBlockInactive, lifecycle=[SubscriptionLifecycle.PROVISIONING]): | ||
str_val: str | None = None | ||
|
||
@computed_field | ||
@property | ||
def title(self) -> str: | ||
# TODO: format correct title string | ||
return f"{self.name}" | ||
|
||
|
||
class Example4SubBlock(Example4SubBlockProvisioning, lifecycle=[SubscriptionLifecycle.ACTIVE]): | ||
str_val: str | None = None |
16 changes: 16 additions & 0 deletions
16
test/unit_tests/cli/data/generate/products/product_types/example4.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,16 @@ | ||
from orchestrator.domain.base import SubscriptionModel | ||
from orchestrator.types import SubscriptionLifecycle | ||
|
||
from products.product_blocks.example4 import Example4Block, Example4BlockInactive, Example4BlockProvisioning | ||
|
||
|
||
class Example4Inactive(SubscriptionModel, is_base=True): | ||
example4: Example4BlockInactive | ||
|
||
|
||
class Example4Provisioning(Example4Inactive, lifecycle=[SubscriptionLifecycle.PROVISIONING]): | ||
example4: Example4BlockProvisioning | ||
|
||
|
||
class Example4(Example4Provisioning, lifecycle=[SubscriptionLifecycle.ACTIVE]): | ||
example4: Example4Block |
53 changes: 53 additions & 0 deletions
53
test/unit_tests/cli/data/generate/test/unit_tests/domain/product_types/test_example4.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,53 @@ | ||
from uuid import uuid4 | ||
|
||
from orchestrator.db import ProductTable, db | ||
from orchestrator.types import SubscriptionLifecycle | ||
|
||
from products.product_types.example4 import Example4, Example4Inactive | ||
|
||
|
||
def test_example4_new(): | ||
product = ProductTable.query.filter(ProductTable.name == "example4").one() | ||
|
||
diff = Example4.diff_product_in_database(product.product_id) | ||
assert diff == {} | ||
|
||
example4 = Example4Inactive.from_product_id( | ||
product_id=product.product_id, | ||
customer_id=uuid4(), | ||
status=SubscriptionLifecycle.INITIAL, | ||
) | ||
|
||
assert example4.subscription_id is not None | ||
assert example4.insync is False | ||
|
||
# TODO: Add more product specific asserts | ||
|
||
assert example4.description == f"Initial subscription of {product.description}" | ||
example4.save() | ||
|
||
example42 = Example4Inactive.from_subscription(example4.subscription_id) | ||
assert example4 == example42 | ||
|
||
|
||
def test_example4_load_and_save_db(example4_subscription): | ||
example4 = Example4.from_subscription(example4_subscription) | ||
|
||
assert example4.insync is True | ||
|
||
# TODO: Add more product specific asserts | ||
|
||
example4.description = "Changed description" | ||
|
||
# TODO: add a product specific change | ||
|
||
example4.save() | ||
|
||
# Explicit commit here as we are not running in the context of a step | ||
db.session.commit() | ||
|
||
example4 = Example4.from_subscription(example4_subscription) | ||
|
||
# TODO: Add more product specific asserts | ||
|
||
assert example4.description == "Changed description" |
32 changes: 32 additions & 0 deletions
32
test/unit_tests/cli/data/generate/test/unit_tests/workflows/example4/test_create_example4.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,32 @@ | ||
import pytest | ||
from orchestrator.db import ProductTable | ||
|
||
from products.product_types.example4 import Example4 | ||
from test.unit_tests.workflows import assert_complete, extract_state, run_workflow | ||
|
||
|
||
@pytest.mark.workflow() | ||
def test_happy_flow(responses): | ||
# given | ||
|
||
# TODO insert additional mocks, if needed (ImsMocks) | ||
|
||
product = db.session.scalars(select(ProductTable).where(ProductTable.name == "example4")).one() | ||
|
||
# when | ||
|
||
init_state = { | ||
"customer_id": customer_id, | ||
# TODO add initial state | ||
} | ||
|
||
result, process, step_log = run_workflow("create_example4", [{"product": product.product_id}, init_state]) | ||
|
||
# then | ||
|
||
assert_complete(result) | ||
state = extract_state(result) | ||
|
||
subscription = Example4.from_subscription(state["subscription_id"]) | ||
assert subscription.status == "active" | ||
assert subscription.description == "TODO add correct description" |
33 changes: 33 additions & 0 deletions
33
test/unit_tests/cli/data/generate/test/unit_tests/workflows/example4/test_modify_example4.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,33 @@ | ||
import pytest | ||
from orchestrator.types import SubscriptionLifecycle | ||
|
||
from products.product_types.example4 import Example4 | ||
from test.unit_tests.workflows import assert_complete, extract_state, run_workflow | ||
|
||
|
||
@pytest.mark.workflow() | ||
def test_happy_flow(responses, example4_subscription): | ||
# given | ||
|
||
customer_id = "3f4fc287-0911-e511-80d0-005056956c1a" | ||
crm = CrmMocks(responses) | ||
crm.get_customer_by_uuid(customer_id) | ||
|
||
# TODO insert additional mocks, if needed (ImsMocks) | ||
|
||
# when | ||
|
||
init_state = {} | ||
|
||
result, process, step_log = run_workflow( | ||
"modify_example4", | ||
[{"subscription_id": example4_subscription}, init_state, {}], | ||
) | ||
|
||
# then | ||
|
||
assert_complete(result) | ||
state = extract_state(result) | ||
|
||
example4 = Example4.from_subscription(state["subscription_id"]) | ||
assert example4.status == SubscriptionLifecycle.ACTIVE |
26 changes: 26 additions & 0 deletions
26
...nit_tests/cli/data/generate/test/unit_tests/workflows/example4/test_terminate_example4.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,26 @@ | ||
import pytest | ||
from orchestrator.types import SubscriptionLifecycle | ||
|
||
from products.product_types.example4 import Example4 | ||
from test.unit_tests.workflows import assert_complete, extract_state, run_workflow | ||
|
||
|
||
@pytest.mark.workflow() | ||
def test_happy_flow(responses, example4_subscription): | ||
# when | ||
|
||
# TODO: insert mocks here if needed | ||
|
||
result, _, _ = run_workflow("terminate_example4", [{"subscription_id": example4_subscription}, {}]) | ||
|
||
# then | ||
|
||
assert_complete(result) | ||
state = extract_state(result) | ||
assert "subscription" in state | ||
|
||
# Check subscription in DB | ||
|
||
example4 = Example4.from_subscription(example4_subscription) | ||
assert example4.end_date is not None | ||
assert example4.status == SubscriptionLifecycle.TERMINATED |
16 changes: 16 additions & 0 deletions
16
...unit_tests/cli/data/generate/test/unit_tests/workflows/example4/test_validate_example4.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,16 @@ | ||
import pytest | ||
|
||
from test.unit_tests.workflows import assert_complete, extract_state, run_workflow | ||
|
||
|
||
@pytest.mark.workflow() | ||
def test_happy_flow(responses, example4_subscription): | ||
# when | ||
|
||
result, _, _ = run_workflow("validate_example4", {"subscription_id": example4_subscription}) | ||
|
||
# then | ||
|
||
assert_complete(result) | ||
state = extract_state(result) | ||
assert state["check_core_db"] is True |
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
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
Oops, something went wrong.