def seed(): ProductBlockTable.query.delete() resources = [ ResourceTypeTable(resource_type=IMS_CIRCUIT_ID, description="IMS Circuit Id") ] product_blocks = [ ProductBlockTable( product_block_id=PRODUCT_BLOCK_ID, name="Ethernet", description="desc", status="active", resource_types=resources, tag="tag", ) ] product = ProductTable( name="ProductTable", description="description", product_type="Port", tag="Port", status="active", product_blocks=product_blocks, fixed_inputs=[], ) db.session.add(product) db.session.commit()
def generic_resource_type_3(): rt = ResourceTypeTable(description="Resource Type three", resource_type="rt_3") db.session.add(rt) db.session.commit() return rt
def seed(): # Delete current resource types ResourceTypeTable.query.delete() resource_types = [ResourceTypeTable(resource_type_id=RESOURCE_TYPE_ID, resource_type="some_resource_type")] product_block = ProductBlockTable( name="Ethernet", description="desc", status="active", resource_types=resource_types ) db.session.add(product_block) db.session.commit()
def test_autouse_fixture_rolls_back_bbb(): # We want to test whether a change committed to the database in one test is visible to other tests (as in really # persisted to the database). Of course such a change should not be visible if our `fastapi_app` and `database` # autouse fixtures work as advertised. # # However, tests should be independent of each other and we cannot assume one test runs before the other. Hence # this test comes in two versions: one with the `_aaa` postfix and one with the `_bbb` postfix. Both will test # for the presence of a change the other test thinks it has committed to the database. If one of the tests (the # one that runs after the other) finds the change the other has committed our fixtures don't work properly. # Using ResourceTypeTable as it's a simple model than doesn't require foreign keys. rt = ResourceTypeTable(resource_type="bbb", description="bbb") db.session.add(rt) db.session.commit() with pytest.raises(NoResultFound): ResourceTypeTable.query.filter( ResourceTypeTable.resource_type == "aaa").one()
def resource_type_list(): return ResourceTypeTable(resource_type="list_field", description="")
def resource_type_str(): return ResourceTypeTable(resource_type="str_field", description="")
def resource_type_int_2(): return ResourceTypeTable(resource_type="int_field_2", description="")
def seed(): ProductTable.query.delete() resources = [ ResourceTypeTable(resource_type=IMS_CIRCUIT_ID, description="IMS circuit Id"), ] product_blocks = [ ProductBlockTable(name="Ethernet", description="d", status="active", resource_types=resources) ] fixed_inputs = [ FixedInputTable(name=SERVICE_SPEED, value="1000"), FixedInputTable(name=CITY_TYPE, value="inner_city"), FixedInputTable(name="protection_type", value="Protected"), ] product = ProductTable( product_id=PRODUCT_ID, name="LightPath", description="descr", product_type="LightPath", tag="LightPath", status="active", product_blocks=product_blocks, fixed_inputs=fixed_inputs, ) msp_product = ProductTable( product_id=MSP_PRODUCT_ID, name="MSP", description="descr", product_type="Port", tag="Port", status="active", product_blocks=product_blocks, fixed_inputs=[ FixedInputTable(name=PORT_SPEED, value="1000"), FixedInputTable(name=DOMAIN, value="SURFNET7") ], ) msp_product_100G = ProductTable( name="MSP 1100G", description="descr", product_type="Port", tag="Port", status="active", product_blocks=product_blocks, fixed_inputs=[ FixedInputTable(name=PORT_SPEED, value="100000"), FixedInputTable(name="domain", value="SURFNET7"), ], ) product_no_workflow = ProductTable(product_id=uuid4(), name="P", description="P", product_type="Port", tag="P", status="active") port_subscription_id = ResourceTypeTable( resource_type=PORT_SUBSCRIPTION_ID, description="Port Subscription Id") values = [ SubscriptionInstanceValueTable(resource_type=port_subscription_id, value=str(depends_on_SUBSCRIPTION_ID)) ] subscription = SubscriptionTable( subscription_id=SUBSCRIPTION_ID, description="desc", status="active", insync=True, product=product, customer_id=uuid4(), instances=[ SubscriptionInstanceTable(product_block=product_blocks[0], values=values) ], ) depends_on_subscription = SubscriptionTable( subscription_id=depends_on_SUBSCRIPTION_ID, description="desc", status="active", insync=True, product=msp_product, customer_id=uuid4(), ) def lp_product(protection_type, product_id, speed="1000"): name = f"msp_ssp_{protection_type.lower()}" msp_ssp_fixed_inputs = [ FixedInputTable(name="protection_type", value=protection_type.capitalize()), FixedInputTable(name=SERVICE_SPEED, value=speed), FixedInputTable(name=CITY_TYPE, value="inner_city"), ] return ProductTable( product_id=product_id, name=f"name_{product_id}", description=name, product_type="LightPath", tag="LightPath", status="active", fixed_inputs=msp_ssp_fixed_inputs, ) db.session.add(product) db.session.add(msp_product) db.session.add(msp_product_100G) db.session.add(lp_product("protected", uuid4(), speed="10000")) db.session.add(lp_product("protected", uuid4(), speed="750")) db.session.add(lp_product("redundant", REDUNDANT_MSP_SSP_ID)) db.session.add(lp_product("protected", PROTECTED_MSP_SSP_ID, speed="250")) db.session.add(lp_product("unprotected", UNPROTECTED_MSP_SSP_ID)) db.session.add(subscription) db.session.add(depends_on_subscription) db.session.add(product_no_workflow) db.session.commit()
def seed(): # These resource types are special resources = [ ResourceTypeTable(resource_type=IMS_CIRCUIT_ID, description="Desc"), ResourceTypeTable(resource_type=PORT_SUBSCRIPTION_ID, description="Desc"), ] product_blocks = [ ProductBlockTable(name="ProductBlockA", description="description a", status="active", resource_types=resources) ] fixed_inputs = [FixedInputTable(name="product_type", value="MSP100G")] # Wf needs to exist in code and needs to be a legacy wf with mapping lp_product = ProductTable( name="LightpathProduct", description="Service product that lives on ports", product_type="LightPath", tag= "LightPath", # This is special since in_use_by/depends_on subscription code handles specific tags status="active", product_blocks=product_blocks, fixed_inputs=fixed_inputs, ) port_a_product = ProductTable( product_id=PRODUCT_ID, name="PortAProduct", description="Port A description", product_type="Port", tag= "SP", # This is special since in_use_by/depends_on subscription code handles specific tags status="active", product_blocks=product_blocks, fixed_inputs=fixed_inputs, ) port_b_product = ProductTable( name="PortBProduct", description="Port B description", product_type="Port", tag="PORTB", status="active", product_blocks=product_blocks, fixed_inputs=fixed_inputs, ) # Special resource type handled by get subscription by ipam prefix endpoint ip_prefix_resources = [ ResourceTypeTable(resource_type=IPAM_PREFIX_ID, description="Prefix id") ] ip_prefix_product_blocks = [ ProductBlockTable(name="ProductBlockB", description="description b", status="active", resource_types=ip_prefix_resources) ] ip_prefix_product = ProductTable( name="IPPrefixProduct", description="ProductTable that is used by service product", product_type="IP_PREFIX", tag="IP_PREFIX", status="active", product_blocks=ip_prefix_product_blocks, ) ip_prefix_subscription = SubscriptionTable( subscription_id=IP_PREFIX_SUBSCRIPTION_ID, description="desc", status="active", insync=True, product=ip_prefix_product, customer_id=CUSTOMER_ID, instances=[ SubscriptionInstanceTable( product_block=ip_prefix_product_blocks[0], values=[ SubscriptionInstanceValueTable( resource_type=ip_prefix_resources[0], value="26") ], ) ], ) port_a_subscription = SubscriptionTable( subscription_id=PORT_A_SUBSCRIPTION_ID, description="desc", status="initial", insync=True, product=port_a_product, customer_id=CUSTOMER_ID, instances=[ SubscriptionInstanceTable( product_block=product_blocks[0], values=[ SubscriptionInstanceValueTable(resource_type=resources[0], value="54321") ], ) ], ) provisioning_port_a_subscription = SubscriptionTable( subscription_id=PROVISIONING_PORT_A_SUBSCRIPTION_ID, description="desc", status="provisioning", insync=False, product=port_a_product, customer_id=CUSTOMER_ID, instances=[ SubscriptionInstanceTable( product_block=product_blocks[0], values=[ SubscriptionInstanceValueTable(resource_type=resources[0], value="12345") ], ) ], ) ssp_subscription = SubscriptionTable( subscription_id=SSP_SUBSCRIPTION_ID, description="desc", status="active", insync=True, product=port_b_product, customer_id=CUSTOMER_ID, instances=[ SubscriptionInstanceTable( product_block=product_blocks[0], values=[ SubscriptionInstanceValueTable(resource_type=resources[0], value="54321") ], ) ], ) lp_subscription_instance_values_ssp = [ SubscriptionInstanceValueTable(resource_type=resources[0], value="54321"), SubscriptionInstanceValueTable(resource_type=resources[1], value=str(PORT_A_SUBSCRIPTION_ID)), ] lp_subscription_instance_ssp = SubscriptionInstanceTable( product_block=product_blocks[0], values=lp_subscription_instance_values_ssp) lp_subscription_instance_values_msp = [ SubscriptionInstanceValueTable(resource_type=resources[0], value="54321"), SubscriptionInstanceValueTable(resource_type=resources[1], value=str(SSP_SUBSCRIPTION_ID)), ] lp_subscription_instance_msp = SubscriptionInstanceTable( product_block=product_blocks[0], values=lp_subscription_instance_values_msp) lp_subscription = SubscriptionTable( subscription_id=SERVICE_SUBSCRIPTION_ID, description="desc", status="active", insync=True, product=lp_product, customer_id=CUSTOMER_ID, instances=[lp_subscription_instance_ssp, lp_subscription_instance_msp], ) invalid_subscription = SubscriptionTable( subscription_id=INVALID_SUBSCRIPTION_ID, description="desc", status="active", insync=True, product=port_a_product, customer_id=CUSTOMER_ID, instances=[], ) invalid_tagged_product = ProductTable( product_id=str(uuid4()), name="INVALID_PRODUCT", description="invalid descr", product_type="Port", tag="NEWMSP", status="active", product_blocks=product_blocks, fixed_inputs=fixed_inputs, ) invalid_tagged_subscription = SubscriptionTable( subscription_id=INVALID_PORT_SUBSCRIPTION_ID, description="desc", status="active", insync=False, product=invalid_tagged_product, customer_id=CUSTOMER_ID, instances=[ SubscriptionInstanceTable( product_block=product_blocks[0], values=[ SubscriptionInstanceValueTable(resource_type=resources[0], value="54321") ], ) ], ) db.session.add(port_a_product) db.session.add(ip_prefix_product) db.session.add(ip_prefix_subscription) db.session.add(invalid_tagged_product) db.session.add(port_b_product) db.session.add(lp_product) db.session.add(port_a_subscription) db.session.add(provisioning_port_a_subscription) db.session.add(ssp_subscription) db.session.add(lp_subscription) db.session.add(invalid_subscription) db.session.add(invalid_tagged_subscription) db.session.commit() RELATION_RESOURCE_TYPES.extend([ PORT_SUBSCRIPTION_ID, IP_PREFIX_SUBSCRIPTION_ID, INTERNETPINNEN_PREFIX_SUBSCRIPTION_ID, PARENT_IP_PREFIX_SUBSCRIPTION_ID, PEER_GROUP_SUBSCRIPTION_ID, ]) return ip_prefix_product