diff --git a/api-tests/batch_policy_proposal_test.py b/api-tests/batch_policy_proposal_test.py index 7eceb3e..ceefb5f 100644 --- a/api-tests/batch_policy_proposal_test.py +++ b/api-tests/batch_policy_proposal_test.py @@ -21,11 +21,13 @@ def after_all(): utils.remove_everything_from_db() -def test_first_one_automatically_created(): +@pytest.mark.parametrize("customer_categories", [["gov", "public"], ["corporate", "sme"]]) +def test_first_one_automatically_created(customer_categories): """ Test whether the first, naive bapol proposal is created for a new proposal """ utils.post_processes_a_b("helicopter_license", "./resources/bpmn/helicopter/helicopter_vA.bpmn", "./resources/bpmn/helicopter/helicopter_vB.bpmn", - customer_categories=["public", "gov"], default_version='a', + customer_categories=customer_categories, + default_version='a', path_history="./resources/bpmn/helicopter/helicopter_vA_100.json") assert utils.get_process_count() == 1 params = { @@ -35,6 +37,14 @@ def test_first_one_automatically_created(): assert response.status_code == requests.codes.ok assert True is response.json().get('newProposalExists') + # make sure that customer categories are correct + response_cust_cats = [] + for exec_strat in response.json().get('proposal').get('executionStrategy'): + response_cust_cats.append(exec_strat.get('customerCategory')) + customer_categories.sort() + response_cust_cats.sort() + assert response_cust_cats == customer_categories + # make sure the id is of the process just posted bapol_prop_process_id = response.json().get('proposal').get('processId') response_process_meta = requests.get(BASE_URL + "/process/active/meta") @@ -45,27 +55,14 @@ def test_first_one_automatically_created(): assert None is response.json().get('proposal').get('baPolId') -def test_new_proposal_after_batch(): +@pytest.mark.parametrize("customer_categories", [["gov", "public"], ["corporate", "sme"]]) +def test_new_proposal_after_batch(customer_categories): utils.post_processes_a_b("helicopter_license", "./resources/bpmn/helicopter/helicopter_vA.bpmn", "./resources/bpmn/helicopter/helicopter_vB.bpmn", - customer_categories=["public", "gov"], default_version='a', + customer_categories=customer_categories, default_version='a', path_history="./resources/bpmn/helicopter/helicopter_vA_100.json") assert utils.get_bapol_proposal_count_active_process() == 1 - utils.post_bapol_currently_active_process({ - "batchSize": 5, - "executionStrategy": [ - { - "customerCategory": "public", - "explorationProbabilityA": 0.3, - "explorationProbabilityB": 0.7 - }, - { - "customerCategory": "gov", - "explorationProbabilityA": 0.7, - "explorationProbabilityB": 0.3 - } - ] - }) + utils.post_bapol_currently_active_process(utils.example_batch_policy_size(5, customer_categories)) assert utils.get_bapol_count() == 1 cs.start_client_simulation(5, 1) assert utils.get_bapol_proposal_count_active_process() == 2 @@ -74,6 +71,14 @@ def test_new_proposal_after_batch(): assert response.status_code == requests.codes.ok assert True is response.json().get('newProposalExists') + # make sure that customer categories are correct + response_cust_cats = [] + for exec_strat in response.json().get('proposal').get('executionStrategy'): + response_cust_cats.append(exec_strat.get('customerCategory')) + customer_categories.sort() + response_cust_cats.sort() + assert response_cust_cats == customer_categories + def test_requests_in_between_batches(): bapol_5_size = { @@ -122,7 +127,7 @@ def test_requests_in_between_batches(): def test_after_manual_decision_no_proposal(): - bapol_5_size = utils.example_batch_policy_size(5) + bapol_5_size = utils.example_batch_policy_size(5, ["gov", "public"]) utils.post_processes_a_b("fast", "./resources/bpmn/fast_a_better/fast_a_better_vA.bpmn", "./resources/bpmn/fast_a_better/fast_a_better_vB.bpmn", customer_categories=["public", "gov"], default_version='a', @@ -146,7 +151,7 @@ def test_bapol_prop_goes_away_cool_off(): customer_categories=["public", "gov"], default_version='a', path_history="./resources/bpmn/fast_a_better/fast_a_better_vA_100.json") # finish a batch - utils.post_bapol_currently_active_process(utils.example_batch_policy_size(5)) + utils.post_bapol_currently_active_process(utils.example_batch_policy_size(5, ["gov", "public"])) cs.start_client_simulation(5, 1) # one open proposal assert utils.new_open_proposal_exists_active_process() diff --git a/api-tests/batch_policy_test.py b/api-tests/batch_policy_test.py index 71c1c9f..d17ae20 100644 --- a/api-tests/batch_policy_test.py +++ b/api-tests/batch_policy_test.py @@ -1,6 +1,5 @@ import pytest import requests - import utils from config import BASE_URL @@ -83,12 +82,13 @@ def test_set_bapol_failing_json(): assert response.status_code == 400 -def test_set_bapol_failing_customer_category(): +@pytest.mark.parametrize("customer_categories", [["gov", "public"], ["corporate", "sme"]]) +def test_set_bapol_failing_customer_category(customer_categories): # given utils.post_processes_a_b("fast", "./resources/bpmn/fast_a_better/fast_a_better_vA.bpmn", "./resources/bpmn/fast_a_better/fast_a_better_vB.bpmn", - customer_categories=["public", "gov"], default_version='a', + customer_categories=customer_categories, default_version='a', path_history="./resources/bpmn/fast_a_better/fast_a_better_vA_100.json") bapol = { "batchSize": 200, @@ -99,7 +99,7 @@ def test_set_bapol_failing_customer_category(): "explorationProbabilityB": 0.7 }, { - "customer_Category": "enterprise", + "customer_Category": "corporate", "explorationProbabilityA": 0.7, "explorationProbabilityB": 0.3 } @@ -113,23 +113,25 @@ def test_set_bapol_failing_customer_category(): assert response.status_code == 400 -def test_get_latest(): +@pytest.mark.parametrize("customer_categories", [["gov", "public"], ["corporate", "sme"]]) +def test_get_latest(customer_categories): """ Test if retrieval of the latest batch policy works """ # given utils.post_processes_a_b("helicopter_license", "./resources/bpmn/helicopter/helicopter_vA.bpmn", "./resources/bpmn/helicopter/helicopter_vB.bpmn", - customer_categories=["public", "gov"], default_version='a', + customer_categories=customer_categories, default_version='a', path_history="./resources/bpmn/helicopter/helicopter_vA_100.json") - utils.post_bapol_currently_active_process({ + utils.post_bapol_currently_active_process( + { "batchSize": 200, "executionStrategy": [ { - "customerCategory": "public", + "customerCategory": customer_categories[0], "explorationProbabilityA": 0.3, "explorationProbabilityB": 0.7 }, { - "customerCategory": "gov", + "customerCategory": customer_categories[1], "explorationProbabilityA": 0.7, "explorationProbabilityB": 0.3 } @@ -145,9 +147,10 @@ def test_get_latest(): assert response_json.get("processId") == utils.get_currently_active_process_id() for i in range(2): exec_strat = response_json.get("executionStrategy")[i] - if exec_strat.get("customerCategory") == "public": + assert exec_strat.get("customerCategory") in customer_categories + if exec_strat.get("customerCategory") == customer_categories[0]: assert exec_strat.get("explorationProbabilityA") == 0.3 assert exec_strat.get("explorationProbabilityB") == 0.7 - if exec_strat.get("customerCategory") == "gov": + if exec_strat.get("customerCategory") == customer_categories[1]: assert exec_strat.get("explorationProbabilityA") == 0.7 assert exec_strat.get("explorationProbabilityB") == 0.3 diff --git a/api-tests/client_simulator_api_tests.py b/api-tests/client_simulator_api_tests.py index 69869a9..1de77ea 100644 --- a/api-tests/client_simulator_api_tests.py +++ b/api-tests/client_simulator_api_tests.py @@ -1,25 +1,18 @@ """ Use this to simulate client requests in the API tests""" import random from time import sleep - import requests from numpy.random import normal - from config import BASE_URL -from utils import get_currently_active_process_id +from utils import get_currently_active_process_id, get_currently_active_process_meta -CUSTOMER_CATEGORIES = ["public", "gov"] NORMAL_DIST_STD_DEV = 0.1 -def _get_random_customer_category(): - return CUSTOMER_CATEGORIES[random.randint(0, len(CUSTOMER_CATEGORIES) - 1)] - - -def send_request_for_new_processes_instance(process_id): +def send_request_for_new_processes_instance(process_id, customer_categories): params = { "process-id": process_id, - "customer-category": _get_random_customer_category() + "customer-category": customer_categories[random.randint(0, len(customer_categories) - 1)] } response = requests.get(BASE_URL + "/instance-router/start-instance", params=params) assert response.status_code == requests.codes.ok @@ -27,9 +20,10 @@ def send_request_for_new_processes_instance(process_id): def start_client_simulation(amount_of_requests_to_send: int, avg_break_sec: float): + customer_categories = get_currently_active_process_meta().get('customer_categories').split('-') currently_active_p_id = get_currently_active_process_id() for i in range(amount_of_requests_to_send): - send_request_for_new_processes_instance(currently_active_p_id) + send_request_for_new_processes_instance(currently_active_p_id, customer_categories) normal_sample = normal(avg_break_sec, NORMAL_DIST_STD_DEV) sleep_value = normal_sample if normal_sample >= 0 else 0 sleep(sleep_value) diff --git a/api-tests/instance_router_test.py b/api-tests/instance_router_test.py index 17571fe..8e645b9 100644 --- a/api-tests/instance_router_test.py +++ b/api-tests/instance_router_test.py @@ -6,8 +6,6 @@ from config import BASE_URL from utils import post_manual_decision -CUSTOMER_CATEGORIES = ["public", "gov"] - @pytest.fixture(autouse=True) def run_before_each_test(): @@ -25,14 +23,18 @@ def after_all(): utils.remove_everything_from_db() -def meta_run_manual_choice(version: str): - """ Helps check whether manual decision of version a or b work """ +def meta_run_manual_choice(version: str, customer_categories: list): + """ Helps check whether manual decision of version a or b work + :param version: + :param customer_categories: + """ assert version in ['a', 'b'] utils.post_processes_a_b("fast", "./resources/bpmn/fast_a_better/fast_a_better_vA.bpmn", "./resources/bpmn/fast_a_better/fast_a_better_vB.bpmn", - customer_categories=["public", "gov"], default_version='a', + customer_categories=customer_categories, + default_version='a', path_history="./resources/bpmn/fast_a_better/fast_a_better_vA_100.json") - utils.post_bapol_currently_active_process(utils.example_batch_policy) + utils.post_bapol_currently_active_process(utils.example_batch_policy_size(200, customer_categories)) currently_active_p_id = utils.get_currently_active_process_id() cs.start_client_simulation(5, 1) assert utils.get_sum_of_started_instances_in_batch(currently_active_p_id) == 5 @@ -73,17 +75,18 @@ def test_instantiation_failing_customer_category(): assert response.status_code == 400 -def test_aggregate_data(): +@pytest.mark.parametrize("customer_categories", [["gov", "public"], ["corporate", "sme"]]) +def test_aggregate_data(customer_categories): bapol_5_size = { - "batchSize": 10, + "batchSize": 15, "executionStrategy": [ { - "customerCategory": "public", + "customerCategory": customer_categories[0], "explorationProbabilityA": 0.3, "explorationProbabilityB": 0.7 }, { - "customerCategory": "gov", + "customerCategory": customer_categories[1], "explorationProbabilityA": 0.7, "explorationProbabilityB": 0.3 } @@ -91,12 +94,12 @@ def test_aggregate_data(): } utils.post_processes_a_b("fast", "./resources/bpmn/fast_a_better/fast_a_better_vA.bpmn", "./resources/bpmn/fast_a_better/fast_a_better_vB.bpmn", - customer_categories=["public", "gov"], default_version='a', + customer_categories=customer_categories, default_version='a', path_history="./resources/bpmn/fast_a_better/fast_a_better_vA_100.json") assert utils.get_bapol_proposal_count_active_process() == 1 utils.post_bapol_currently_active_process(bapol_5_size) assert utils.get_bapol_count() == 1 - cs.start_client_simulation(10, 1) + cs.start_client_simulation(15, 1) assert utils.get_bapol_proposal_count_active_process() == 2 assert utils.new_open_proposal_exists_active_process() is True currently_active_process_id = utils.get_currently_active_process_id() @@ -111,7 +114,7 @@ def test_aggregate_data(): for version in ['a', 'b']: for key in keys: assert key in response_json.get(version).keys() - assert response_json.get('a').get('numberStarted') + response_json.get('b').get('numberStarted') == 10 + assert response_json.get('a').get('numberStarted') + response_json.get('b').get('numberStarted') == 15 # check if the data has been populated successfully for key in keys: assert response_json.get('a').get(key) + response_json.get('b').get(key) != 0 @@ -138,23 +141,26 @@ def test_aggregate_data_before_instantiation(): assert response_json.get(version).get('averageReward') is None -def test_manual_choice_a(): +@pytest.mark.parametrize("customer_categories", [["gov", "public"], ["corporate", "sme"]]) +def test_manual_choice_a(customer_categories): """ Test if manual choice of a leads to only instantiating version a afterwards""" - meta_run_manual_choice('a') + meta_run_manual_choice('a', customer_categories) -def test_manual_choice_b(): +@pytest.mark.parametrize("customer_categories", [["gov", "public"], ["corporate", "sme"]]) +def test_manual_choice_b(customer_categories): """ Test if manual choice of b leads to only instantiating version b afterwards""" - meta_run_manual_choice('b') + meta_run_manual_choice('b', customer_categories) -def test_two_manual_choices_not_possible(): +@pytest.mark.parametrize("customer_categories", [["gov", "public"], ["corporate", "sme"]]) +def test_two_manual_choices_not_possible(customer_categories): """ We want to check that setting a second (manual) decision is not possible """ utils.post_processes_a_b("fast", "./resources/bpmn/fast_a_better/fast_a_better_vA.bpmn", "./resources/bpmn/fast_a_better/fast_a_better_vB.bpmn", - customer_categories=["public", "gov"], default_version='a', + customer_categories=customer_categories, default_version='a', path_history="./resources/bpmn/fast_a_better/fast_a_better_vA_100.json") - utils.post_bapol_currently_active_process(utils.example_batch_policy) + utils.post_bapol_currently_active_process(utils.example_batch_policy_size(10, customer_categories)) post_manual_decision('a') try: post_manual_decision('b') @@ -177,9 +183,10 @@ def test_client_requests_data_empty(): assert response.json().get("requestsB") == [] -def test_client_requests_data(): +@pytest.mark.parametrize("customer_categories", [["gov", "public"], ["corporate", "sme"]]) +def test_client_requests_data(customer_categories): """ Tests whether the client requests data is reasonable """ - meta_run_manual_choice('b') + meta_run_manual_choice('b', customer_categories) params = {"process-id": utils.get_currently_active_process_id()} response = requests.get(BASE_URL + "/instance-router/aggregate-data/client-requests", params=params) assert response.status_code == requests.codes.ok @@ -222,17 +229,18 @@ def test_finished_instances_are_collected(): assert response.json().get('finishedInstanceCount') > 0 -def test_detailed_batch_instance_info(): +@pytest.mark.parametrize("customer_categories", [["gov", "public"], ["corporate", "sme"]]) +def test_detailed_batch_instance_info(customer_categories): bapol_size_5 = { "batchSize": 5, "executionStrategy": [ { - "customerCategory": "public", + "customerCategory": customer_categories[0], "explorationProbabilityA": 0.3, "explorationProbabilityB": 0.7 }, { - "customerCategory": "gov", + "customerCategory": customer_categories[1], "explorationProbabilityA": 0.7, "explorationProbabilityB": 0.3 } @@ -240,7 +248,7 @@ def test_detailed_batch_instance_info(): } utils.post_processes_a_b("fast", "./resources/bpmn/fast_a_better/fast_a_better_vA.bpmn", "./resources/bpmn/fast_a_better/fast_a_better_vB.bpmn", - customer_categories=["public", "gov"], default_version='a', + customer_categories=customer_categories, default_version='a', path_history="./resources/bpmn/fast_a_better/fast_a_better_vA_100.json") active_process_id = utils.get_currently_active_process_id() # finish three batches @@ -275,7 +283,7 @@ def test_detailed_batch_instance_info(): assert "reward" in instance.keys() assert "rlProb" in instance.keys() assert instance.get("decision") is not None - assert instance.get("customerCategory") is not None + assert instance.get("customerCategory") in customer_categories assert instance.get("startTime") is not None if instance.get("endTime") is None or instance.get("reward") is None or instance.get("rlProb") is None: assert instance.get("reward") is None @@ -355,22 +363,23 @@ def test_routing_follows_bapol_a(): assert instance.get('decision') == 'a' -def test_routing_follows_bapol_both(): +@pytest.mark.parametrize("customer_categories", [["gov", "public"], ["corporate", "sme"]]) +def test_routing_follows_bapol_both(customer_categories): utils.post_processes_a_b("fast", "resources/bpmn/fast_a_better/fast_a_better_vA.bpmn", "resources/bpmn/fast_a_better/fast_a_better_vB.bpmn", - customer_categories=["public", "gov"], default_version='a', + customer_categories=customer_categories, default_version='a', path_history="./resources/bpmn/fast_a_better/fast_a_better_vA_100.json") utils.post_bapol_currently_active_process({ "batchSize": 10, "executionStrategy": [ { - "customerCategory": "public", + "customerCategory": customer_categories[0], "explorationProbabilityA": 0.5, "explorationProbabilityB": 0.5 }, { - "customerCategory": "gov", + "customerCategory": customer_categories[1], "explorationProbabilityA": 0.5, "explorationProbabilityB": 0.5 } @@ -431,7 +440,8 @@ def test_a_better_right_decision(): + execution_strategy.get('explorationProbabilityB') == 1 -def test_periodic_update_latest_bapol(): +@pytest.mark.parametrize("customer_categories", [["gov", "public"], ["corporate", "sme"]]) +def test_periodic_update_latest_bapol(customer_categories): """ Test, if the periodic updating of a batch policy is happening Will also focus on test of the endpoint instance-router/aggregate-data/evaluation-progress. @@ -445,10 +455,10 @@ def test_periodic_update_latest_bapol(): utils.post_processes_a_b("helicopter_license", "./resources/bpmn/helicopter/helicopter_vA.bpmn", "./resources/bpmn/helicopter/helicopter_vB.bpmn", - customer_categories=["public", "gov"], + customer_categories=customer_categories, default_version='a', path_history="./resources/bpmn/helicopter/helicopter_vA_100.json") - utils.post_bapol_currently_active_process(utils.example_batch_policy_size(10)) + utils.post_bapol_currently_active_process(utils.example_batch_policy_size(10, customer_categories)) process_id_active = utils.get_currently_active_process_id() # ----- @@ -511,6 +521,14 @@ def test_periodic_update_latest_bapol(): assert response_bapol_1.status_code == requests.codes.ok assert response_bapol_1.json().get('newProposalExists') is True + # make sure that customer categories are correct + response_cust_cats = [] + for exec_strat in response_bapol_1.json().get('proposal').get('executionStrategy'): + response_cust_cats.append(exec_strat.get('customerCategory')) + customer_categories.sort() + response_cust_cats.sort() + assert response_cust_cats == customer_categories + # test bapol proposal count response_bapol_count = requests.get(BASE_URL + "/batch-policy-proposal/count", params={'process-id': process_id_active}) @@ -554,6 +572,14 @@ def test_periodic_update_latest_bapol(): # proposal should have been updated and should (most likely) not be the same assert response_bapol_2.json().get('proposal') != response_bapol_1.json().get('proposal') + # make sure that customer categories are correct + response_cust_cats = [] + for exec_strat in response_bapol_2.json().get('proposal').get('executionStrategy'): + response_cust_cats.append(exec_strat.get('customerCategory')) + customer_categories.sort() + response_cust_cats.sort() + assert response_cust_cats == customer_categories + # test bapol proposal count response_bapol_count = requests.get(BASE_URL + "/batch-policy-proposal/count", params={'process-id': process_id_active}) @@ -562,7 +588,8 @@ def test_periodic_update_latest_bapol(): # ----- -def test_manual_trigger_fetch_learn_outside_batch(): +@pytest.mark.parametrize("customer_categories", [["gov", "public"], ["corporate", "sme"]]) +def test_manual_trigger_fetch_learn_outside_batch(customer_categories): """ Test, if the endpoint for manually triggering fetch and learn outside of batch works """ expected_keyset = ["totalToBeEvaluatedCount", "alreadyEvaluatedCount", @@ -572,10 +599,10 @@ def test_manual_trigger_fetch_learn_outside_batch(): utils.post_processes_a_b("helicopter_license", "./resources/bpmn/helicopter/helicopter_vA.bpmn", "./resources/bpmn/helicopter/helicopter_vB.bpmn", - customer_categories=["public", "gov"], + customer_categories=customer_categories, default_version='a', path_history="./resources/bpmn/helicopter/helicopter_vA_100.json") - utils.post_bapol_currently_active_process(utils.example_batch_policy_size(10)) + utils.post_bapol_currently_active_process(utils.example_batch_policy_size(10, customer_categories)) process_id_active = utils.get_currently_active_process_id() # ----- @@ -641,6 +668,14 @@ def test_manual_trigger_fetch_learn_outside_batch(): assert response_bapol_1.status_code == requests.codes.ok assert response_bapol_1.json().get('newProposalExists') is True + # make sure that customer categories are correct + response_cust_cats = [] + for exec_strat in response_bapol_1.json().get('proposal').get('executionStrategy'): + response_cust_cats.append(exec_strat.get('customerCategory')) + customer_categories.sort() + response_cust_cats.sort() + assert response_cust_cats == customer_categories + # test bapol proposal count response_bapol_count = requests.get(BASE_URL + "/batch-policy-proposal/count", params={'process-id': process_id_active}) @@ -684,6 +719,14 @@ def test_manual_trigger_fetch_learn_outside_batch(): # proposal should have been updated and should (most likely) not be the same assert response_bapol_2.json().get('proposal') != response_bapol_1.json().get('proposal') + # make sure that customer categories are correct + response_cust_cats = [] + for exec_strat in response_bapol_2.json().get('proposal').get('executionStrategy'): + response_cust_cats.append(exec_strat.get('customerCategory')) + customer_categories.sort() + response_cust_cats.sort() + assert response_cust_cats == customer_categories + # test bapol proposal count response_bapol_count = requests.get(BASE_URL + "/batch-policy-proposal/count", params={'process-id': process_id_active}) @@ -704,20 +747,22 @@ def test_manual_trigger_fetch_learn_before_first_batch_policy(): assert response_manual_trigger.status_code == requests.codes.conflict -def test_manual_trigger_fetch_learn_in_batch(): +@pytest.mark.parametrize("customer_categories", [["gov", "public"], ["corporate", "sme"]]) +def test_manual_trigger_fetch_learn_in_batch(customer_categories): """ When inside batch, manually triggering fetch and learn should fail """ utils.post_processes_a_b("helicopter_license", "./resources/bpmn/helicopter/helicopter_vA.bpmn", "./resources/bpmn/helicopter/helicopter_vB.bpmn", - customer_categories=["public", "gov"], + customer_categories=customer_categories, default_version='a', path_history="./resources/bpmn/helicopter/helicopter_vA_100.json") - utils.post_bapol_currently_active_process(utils.example_batch_policy_size(10)) + utils.post_bapol_currently_active_process(utils.example_batch_policy_size(10, customer_categories)) response_manual_trigger = requests.post(BASE_URL + "/process/active/trigger-fetch-learn") assert response_manual_trigger.status_code == requests.codes.conflict -def test_manual_trigger_cool_off_period(): +@pytest.mark.parametrize("customer_categories", [["gov", "public"], ["corporate", "sme"]]) +def test_manual_trigger_cool_off_period(customer_categories): """ Test whether triggering of manual fetch and learn acts as expected in cool off and afterwards In Cool-Off: --> should work @@ -726,9 +771,10 @@ def test_manual_trigger_cool_off_period(): """ utils.post_processes_a_b("fast", "./resources/bpmn/fast_a_better/fast_a_better_vA.bpmn", "./resources/bpmn/fast_a_better/fast_a_better_vB.bpmn", - customer_categories=["public", "gov"], default_version='a', + customer_categories=customer_categories, + default_version='a', path_history="./resources/bpmn/fast_a_better/fast_a_better_vA_100.json") - utils.post_bapol_currently_active_process(utils.example_batch_policy_size(5)) + utils.post_bapol_currently_active_process(utils.example_batch_policy_size(5, customer_categories)) cs.start_client_simulation(5, 1) response_post_cool_off = requests.post(BASE_URL + "/process/active/cool-off") assert response_post_cool_off.status_code == requests.codes.ok @@ -751,11 +797,11 @@ def test_manual_trigger_cool_off_period(): decision_json = { "decision": [ { - "customer_category": "public", + "customer_category": customer_categories[0], "winning_version": "a" }, { - "customer_category": "gov", + "customer_category": customer_categories[1], "winning_version": "b" } ] diff --git a/api-tests/process_test.py b/api-tests/process_test.py index f35bd1a..5a6f107 100644 --- a/api-tests/process_test.py +++ b/api-tests/process_test.py @@ -22,11 +22,12 @@ def after_all(): utils.remove_everything_from_db() -def test_set_process(): +@pytest.mark.parametrize("customer_categories", [["gov", "public"], ["corporate", "sme"]]) +def test_set_process(customer_categories): """ Test if setting of new process with variants works """ utils.post_processes_a_b("helicopter_license", "./resources/bpmn/helicopter/helicopter_vA.bpmn", "./resources/bpmn/helicopter/helicopter_vB.bpmn", - customer_categories=["public", "gov"], default_version='a', + customer_categories=customer_categories, default_version='a', path_history="./resources/bpmn/helicopter/helicopter_vA_100.json") assert utils.get_process_count() == 1 @@ -47,28 +48,31 @@ def test_set_2_processes(): def test_get_active_process_metadata(): """ Test if receiving of metadata about currently active process works """ - # given - utils.post_processes_a_b("helicopter_license", "./resources/bpmn/helicopter/helicopter_vA.bpmn", - "./resources/bpmn/helicopter/helicopter_vB.bpmn", - customer_categories=["public", "gov"], default_version='a', - path_history="./resources/bpmn/helicopter/helicopter_vA_100.json") - # when - response = requests.get(BASE_URL + "/process/active/meta") - # then - response_json = response.json() - assert response.status_code == requests.codes.ok - assert response_json.get("name") == "helicopter_license" - assert response_json.get('default_version') == 'a' - assert response_json.get('id') is not None - assert response_json.get('customer_categories') == "gov-public" # should be alphabetical - assert response_json.get('default_interarrival_time_history') == 64.18521 - assert response_json.get('experiment_state') == "Running, before first batch policy has been set" - assert response_json.get('datetime_added') is not None - assert response_json.get('datetime_decided') is None - assert response_json.get('number_batch_policies') == 0 - assert response_json.get('number_instances') == 0 - assert response_json.get("winning_versions") is None - assert response_json.get("winning_reason") is None + customer_category_groups = ["gov-public", "corporate-sme"] + for customer_categories in customer_category_groups: + # given + utils.post_processes_a_b("helicopter_license", "./resources/bpmn/helicopter/helicopter_vA.bpmn", + "./resources/bpmn/helicopter/helicopter_vB.bpmn", + customer_categories=customer_categories.split('-'), + default_version='a', + path_history="./resources/bpmn/helicopter/helicopter_vA_100.json") + # when + response = requests.get(BASE_URL + "/process/active/meta") + # then + response_json = response.json() + assert response.status_code == requests.codes.ok + assert response_json.get("name") == "helicopter_license" + assert response_json.get('default_version') == 'a' + assert response_json.get('id') is not None + assert response_json.get('customer_categories') == customer_categories # should be alphabetical + assert response_json.get('default_interarrival_time_history') == 64.18521 + assert response_json.get('experiment_state') == "Running, before first batch policy has been set" + assert response_json.get('datetime_added') is not None + assert response_json.get('datetime_decided') is None + assert response_json.get('number_batch_policies') == 0 + assert response_json.get('number_instances') == 0 + assert response_json.get("winning_versions") is None + assert response_json.get("winning_reason") is None def test_get_active_process_variants_files(): @@ -128,12 +132,13 @@ def test_experiment_state_manual_decision(): assert 'Manual' in exp_state and 'Done' in exp_state -def test_experiment_state_cool_off(): +@pytest.mark.parametrize("customer_categories", [["gov", "public"], ["corporate", "sme"]]) +def test_experiment_state_cool_off(customer_categories): utils.post_processes_a_b("fast", "./resources/bpmn/fast_a_better/fast_a_better_vA.bpmn", "./resources/bpmn/fast_a_better/fast_a_better_vB.bpmn", - customer_categories=["public", "gov"], default_version='a', + customer_categories=customer_categories, default_version='a', path_history="./resources/bpmn/fast_a_better/fast_a_better_vA_100.json") - utils.post_bapol_currently_active_process(utils.example_batch_policy_size(5)) + utils.post_bapol_currently_active_process(utils.example_batch_policy_size(5, customer_categories)) cs.start_client_simulation(5, 1) response_post_cool_off = requests.post(BASE_URL + "/process/active/cool-off") assert response_post_cool_off.status_code == requests.codes.ok @@ -151,7 +156,7 @@ def test_cool_off_only_after_batch_finished(): response_post_cool_off = requests.post(BASE_URL + "/process/active/cool-off") assert response_post_cool_off.status_code == requests.codes.not_found # not yet finish a batch - utils.post_bapol_currently_active_process(utils.example_batch_policy_size(5)) + utils.post_bapol_currently_active_process(utils.example_batch_policy_size(5, ["gov", "public"])) cs.start_client_simulation(3, 1) response_post_cool_off = requests.post(BASE_URL + "/process/active/cool-off") assert response_post_cool_off.status_code == requests.codes.not_found @@ -161,12 +166,13 @@ def test_cool_off_only_after_batch_finished(): assert response_post_cool_off.status_code == requests.codes.ok -def test_cool_off_period(): +@pytest.mark.parametrize("customer_categories", [["gov", "public"], ["corporate", "sme"]]) +def test_cool_off_period(customer_categories): utils.post_processes_a_b("fast", "./resources/bpmn/fast_a_better/fast_a_better_vA.bpmn", "./resources/bpmn/fast_a_better/fast_a_better_vB.bpmn", - customer_categories=["public", "gov"], default_version='a', + customer_categories=customer_categories, default_version='a', path_history="./resources/bpmn/fast_a_better/fast_a_better_vA_100.json") - utils.post_bapol_currently_active_process(utils.example_batch_policy_size(5)) + utils.post_bapol_currently_active_process(utils.example_batch_policy_size(5, customer_categories)) cs.start_client_simulation(5, 1) response_post_cool_off = requests.post(BASE_URL + "/process/active/cool-off") assert response_post_cool_off.status_code == requests.codes.ok @@ -178,12 +184,12 @@ def test_cool_off_period(): decision_json = { "decision": [ { - "customer_category": "public", - "winning_version": "a" + "customer_category": customer_categories[0], + "winning_version": "b" }, { - "customer_category": "gov", - "winning_version": "b" + "customer_category": customer_categories[1], + "winning_version": "a" } ] } @@ -210,12 +216,12 @@ def test_cool_off_period(): assert "Done" in meta.get('experiment_state') and "ended normally" in meta.get('experiment_state') assert meta.get('winning_versions') == [ { - "customer_category": "public", - "winning_version": "a" + "customer_category": customer_categories[0], + "winning_version": "b" }, { - "customer_category": "gov", - "winning_version": "b" + "customer_category": customer_categories[1], + "winning_version": "a" } ] @@ -226,7 +232,7 @@ def test_cool_off_period_already_all_evaluated(): "./resources/bpmn/fast_a_better/fast_a_better_vB.bpmn", customer_categories=["public", "gov"], default_version='a', path_history="./resources/bpmn/fast_a_better/fast_a_better_vA_100.json") - utils.post_bapol_currently_active_process(utils.example_batch_policy_size(5)) + utils.post_bapol_currently_active_process(utils.example_batch_policy_size(5, ["gov", "public"])) process_id_active = utils.get_currently_active_process_id() cs.start_client_simulation(5, 1) sleep(20) diff --git a/api-tests/utils.py b/api-tests/utils.py index 5324a20..570194a 100644 --- a/api-tests/utils.py +++ b/api-tests/utils.py @@ -67,19 +67,19 @@ def get_currently_active_process_meta(): } -def example_batch_policy_size(size: int) -> dict: +def example_batch_policy_size(size: int, customer_categories: list) -> dict: return { "batchSize": size, "executionStrategy": [ { - "customerCategory": "public", - "explorationProbabilityA": 0.3, - "explorationProbabilityB": 0.7 - }, - { - "customerCategory": "gov", + "customerCategory": customer_categories[0], "explorationProbabilityA": 0.7, "explorationProbabilityB": 0.3 + }, + { + "customerCategory": customer_categories[1], + "explorationProbabilityA": 0.3, + "explorationProbabilityB": 0.7 } ] } diff --git a/client_simulator/client_simulator.py b/client_simulator/client_simulator.py index a603716..4bcc65b 100644 --- a/client_simulator/client_simulator.py +++ b/client_simulator/client_simulator.py @@ -1,11 +1,10 @@ import random from time import sleep - import requests from numpy.random import normal BASE_URL = "http://localhost:5001" -CUSTOMER_CATEGORIES = ["public", "gov"] +CUSTOMER_CATEGORIES = None # TODO: set these before starting AMOUNT_OF_REQUESTS_TO_SEND = 10 NORMAL_DIST_MEAN = 1 NORMAL_DIST_STD_DEV = 0.5 diff --git a/source/frontend/client_simulator.py b/source/frontend/client_simulator.py index 29fb803..331501b 100644 --- a/source/frontend/client_simulator.py +++ b/source/frontend/client_simulator.py @@ -4,21 +4,12 @@ import requests from numpy.random import normal from config import BACKEND_URI -from utils import get_currently_active_process_id +from utils import get_currently_active_process_id, get_currently_active_process_meta -CUSTOMER_CATEGORIES = ["public", "gov"] NORMAL_DIST_STD_DEV = 0.5 -def _get_random_customer_category() -> str: - """Get random customer category - - :return: "public" or "gov" - """ - return CUSTOMER_CATEGORIES[random.randint(0, len(CUSTOMER_CATEGORIES) - 1)] - - -def _send_request_for_new_processes_instance(process_id) -> str: +def _send_request_for_new_processes_instance(process_id:int, customer_categories: list) -> str: """Send a request for a new process instance :param process_id: specify process @@ -26,7 +17,7 @@ def _send_request_for_new_processes_instance(process_id) -> str: """ params = { "process-id": process_id, - "customer-category": _get_random_customer_category() + "customer-category": customer_categories[random.randint(0, len(customer_categories) - 1)] } response = requests.get(BACKEND_URI + "/instance-router/start-instance", params=params) assert response.status_code == requests.codes.ok # pylint: disable=no-member @@ -39,9 +30,10 @@ def run_simulation(amount_of_requests: int, avg_interarrival_time: float) -> Non :param amount_of_requests: How many requests should be sent out :param avg_interarrival_time: Average time between instantiation requests """ + customer_categories = get_currently_active_process_meta().get('customer_categories').split('-') currently_active_p_id = get_currently_active_process_id() for _ in range(amount_of_requests): - print(_send_request_for_new_processes_instance(currently_active_p_id)) + print(_send_request_for_new_processes_instance(currently_active_p_id, customer_categories)) normal_sample = normal(avg_interarrival_time, NORMAL_DIST_STD_DEV) sleep_value = normal_sample if normal_sample >= 0 else 0 sleep(sleep_value) diff --git a/source/frontend/sidebar/__init__.py b/source/frontend/sidebar/__init__.py index b16c3c5..1f4b23d 100644 --- a/source/frontend/sidebar/__init__.py +++ b/source/frontend/sidebar/__init__.py @@ -12,5 +12,5 @@ def build_bar(): - Controllable: Expert oversight (Human-in-the-Loop) For reporting bugs, feedback and more info, please refer - to the [Github repository](https://github.com/Ultimate-Storm/sbe_prototyping). + to the [Github repository](https://github.com/aaronkurz/hitl-ab-bpm). """)