def test_create_execution(organizations, default_org_id, default_team_id): experiment_id = str(uuid.uuid4()) x_id = str(uuid.uuid4()) experiment = { "title": "Hello there", "extensions": [ { "name": "chaosiq", "experiment_id": experiment_id } ] } with requests_mock.mock() as m: url = urls.full( urls.base(ENDPOINT), default_org_id, default_team_id, experiment_id, with_executions=True) m.post( url, status_code=201, json={ "id": x_id, }, headers={ "content-type": "application/json", "content-location": "{}/{}".format(url, x_id) } ) with client_session(ENDPOINT, organizations) as s: r = initialize_execution(s, experiment, {}) assert r.status_code == 201 # we injected the execution_id assert experiment["extensions"][0]["execution_id"] == x_id
def test_execution_not_created_when_experiment_is_invalid_type( organizations, default_org_id, default_team_id): experiment_id = str(uuid.uuid4()) # the remote endpoint cannot deal with anything but a experiment experiment = { "extensions": [ { "name": "chaosiq", "experiment_id": experiment_id } ] } with requests_mock.mock() as m: url = urls.full( urls.base(ENDPOINT), default_org_id, default_team_id, experiment_id, with_executions=True) m.post( url, status_code=422, json=[ { "loc": ["a_dict"], "msg": "value is not a valid dict", "type": "type_error.dict" } ], headers={ "content-type": "application/json" } ) with client_session(ENDPOINT, organizations) as s: r = initialize_execution(s, experiment, {}) assert r.status_code == 422
def test_cannot_create_execution_from_unknown_experiment_id( organizations, default_org_id, default_team_id): experiment_id = str(uuid.uuid4()) experiment = { "title": "Hello there", "extensions": [ { "name": "chaosiq", "experiment_id": experiment_id } ] } with requests_mock.mock() as m: url = urls.full( urls.base(ENDPOINT), default_org_id, default_team_id, experiment_id, with_executions=True) m.post( url, status_code=422, json=[], headers={ "content-type": "application/json" } ) with client_session(ENDPOINT, organizations) as s: r = initialize_execution(s, experiment, {}) assert r.status_code == 422 assert "execution_id" not in experiment["extensions"][0]
def test_cannot_create_execution_on_requests_connection_timeout( organizations, default_org_id, default_team_id): experiment_id = str(uuid.uuid4()) experiment = { "title": "Hello there", "extensions": [ { "name": "chaosiq", "experiment_id": experiment_id } ] } with requests_mock.mock() as m: url = urls.full( urls.base(ENDPOINT), default_org_id, default_team_id, experiment_id, with_executions=True) m.post( url, exc=requests.exceptions.ConnectTimeout ) with client_session(ENDPOINT, organizations) as s: r = initialize_execution(s, experiment, {}) assert r is None
def test_initialize_execution_requires_experiment_id(): assert initialize_execution(None, {}, {}) is None