From dd5f28ac654f9617704a95827ec157e805493fca Mon Sep 17 00:00:00 2001 From: Valerij Maljulin Date: Oct 25 2019 11:28:52 +0000 Subject: [PATCH 1/2] Tests for subject_type=group Signed-off-by: Valerij Maljulin --- diff --git a/conf/policies/fedora.yaml b/conf/policies/fedora.yaml index 0a6a7bf..f855960 100644 --- a/conf/policies/fedora.yaml +++ b/conf/policies/fedora.yaml @@ -132,3 +132,12 @@ decision_context: compose_test_scenario subject_type: compose rules: - !PassingTestCaseRule {test_case_name: testcase_name} + +--- !Policy +id: "compose-test-scenario-group" +product_versions: + - fedora-30 +decision_context: compose_test_scenario_group +subject_type: group +rules: + - !PassingTestCaseRule {test_case_name: testcase_name} diff --git a/functional-tests/test_api_v1.py b/functional-tests/test_api_v1.py index 9c5bda7..90da310 100644 --- a/functional-tests/test_api_v1.py +++ b/functional-tests/test_api_v1.py @@ -3,7 +3,9 @@ import json import pytest import re +import os +from hashlib import sha256 from textwrap import dedent from greenwave import __version__ @@ -38,7 +40,7 @@ def test_inspect_policies(requests_session, greenwave_server): assert r.status_code == 200 body = r.json() policies = body['policies'] - assert len(policies) == 15 + assert len(policies) == 16 assert any(p['id'] == 'taskotron_release_critical_tasks' for p in policies) assert any(p['decision_context'] == 'bodhi_update_push_stable' for p in policies) assert any(p['product_versions'] == ['fedora-26'] for p in policies) @@ -540,6 +542,33 @@ def test_make_a_decision_on_no_results(requests_session, greenwave_server, testd assert res_data['unsatisfied_requirements'] == expected_unsatisfied_requirements +def test_subject_type_group(requests_session, greenwave_server, testdatabuilder): + results_item = 'sha256:' + sha256(os.urandom(50)).hexdigest() + + testdatabuilder.create_result( + item=results_item, testcase_name='testcase_name', outcome='PASSED', _type='group' + ) + data = { + 'decision_context': 'compose_test_scenario_group', + 'product_version': 'fedora-30', + 'subject_type': 'group', + 'subject_identifier': results_item, + } + r = requests_session.post(greenwave_server + 'api/v1.0/decision', + headers={'Content-Type': 'application/json'}, + data=json.dumps(data)) + + assert r.status_code == 200 + + res_data = r.json() + assert res_data['satisfied_requirements'][0]['testcase'] == 'testcase_name' + assert res_data['satisfied_requirements'][0]['type'] == 'test-result-passed' + assert res_data['policies_satisfied'] is True + + expected_summary = 'All required tests passed' + assert res_data['summary'] == expected_summary + + def test_empty_policy_is_always_satisfied( requests_session, greenwave_server, testdatabuilder): data = { From fda203ad0e1b21033a91289416b386cbf11d7b40 Mon Sep 17 00:00:00 2001 From: Valerij Maljulin Date: Oct 25 2019 11:28:52 +0000 Subject: [PATCH 2/2] Functional tests refactoring Signed-off-by: Valerij Maljulin --- diff --git a/functional-tests/conftest.py b/functional-tests/conftest.py index 59db49d..d030b0b 100644 --- a/functional-tests/conftest.py +++ b/functional-tests/conftest.py @@ -257,9 +257,9 @@ class TestDataBuilder(object): def _create_result(self, data): response = self.requests_session.post( self.resultsdb_url + 'api/v2.0/results', - headers={'Content-Type': 'application/json'}, timeout=TEST_HTTP_TIMEOUT, - data=json.dumps(data)) + json=data + ) response.raise_for_status() return response.json() @@ -322,9 +322,9 @@ class TestDataBuilder(object): response = self.requests_session.post( self.waiverdb_url + 'api/v1.0/waivers/', auth=('dummy', 'dummy'), - headers={'Content-Type': 'application/json'}, timeout=TEST_HTTP_TIMEOUT, - data=json.dumps(data)) + json=data + ) response.raise_for_status() return response.json() diff --git a/functional-tests/consumers/test_resultsdb.py b/functional-tests/consumers/test_resultsdb.py index 17724af..8b3e809 100644 --- a/functional-tests/consumers/test_resultsdb.py +++ b/functional-tests/consumers/test_resultsdb.py @@ -229,9 +229,7 @@ def test_consume_compose_id_result( 'subject': [{'productmd.compose.id': compose_id}], 'when': right_before_this_time(result['submit_time']) } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 old_decision = r.json() msg = { @@ -303,9 +301,7 @@ def test_consume_legacy_result( 'subject': [{'item': nvr, 'type': 'koji_build'}], 'when': right_before_this_time(result['submit_time']), } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 old_decision = r.json() # should have two messages published as we have two decision contexts applicable to @@ -364,9 +360,7 @@ def test_consume_legacy_result( 'subject': [{'item': nvr, 'type': 'koji_build'}], 'when': right_before_this_time(result['submit_time']), } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 old_decision = r.json() second_msg = { @@ -561,9 +555,7 @@ def test_consume_new_result_container_image( 'subject': [{'item': nvr, 'type': 'container-image'}], 'when': right_before_this_time(result['submit_time']), } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 old_decision = r.json() diff --git a/functional-tests/test_api_v1.py b/functional-tests/test_api_v1.py index 90da310..72458d1 100644 --- a/functional-tests/test_api_v1.py +++ b/functional-tests/test_api_v1.py @@ -91,9 +91,7 @@ def test_cannot_make_decision_without_product_version(requests_session, greenwav 'subject_type': 'bodhi_update', 'subject_identifier': 'FEDORA-2018-ec7cb4d5eb', } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 400 assert 'Missing required product version' == r.json()['message'] @@ -106,9 +104,7 @@ def test_cannot_make_decision_without_decision_context_and_user_policies( 'subject_type': 'bodhi_update', 'subject_identifier': 'FEDORA-2018-ec7cb4d5eb', } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 400 assert 'Either decision_context or rules is required.' == r.json()['message'] @@ -120,9 +116,7 @@ def test_cannot_make_decision_without_subject_type(requests_session, greenwave_s 'product_version': 'fedora-26', 'subject_identifier': 'FEDORA-2018-ec7cb4d5eb', } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 400 assert 'Missing required "subject_type" parameter' == r.json()['message'] @@ -134,9 +128,7 @@ def test_cannot_make_decision_without_subject_identifier(requests_session, green 'product_version': 'fedora-26', 'subject_type': 'bodhi_update', } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 400 assert 'Missing required "subject_identifier" parameter' == r.json()['message'] @@ -148,9 +140,7 @@ def test_cannot_make_decision_with_invalid_subject(requests_session, greenwave_s 'product_version': 'fedora-26', 'subject': 'foo-1.0.0-1.el7', } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 400 assert 'Invalid subject, must be a list of dicts' == r.json()['message'] @@ -159,9 +149,7 @@ def test_cannot_make_decision_with_invalid_subject(requests_session, greenwave_s 'product_version': 'fedora-26', 'subject': ['foo-1.0.0-1.el7'], } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 400 assert 'Invalid subject, must be a list of dicts' == r.json()['message'] @@ -175,9 +163,7 @@ def test_404_for_invalid_product_version(requests_session, greenwave_server, tes 'subject_type': 'koji_build', 'subject_identifier': nvr, } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 404 expected = ('Cannot find any applicable policies for koji_build subjects ' 'at gating point bodhi_push_update_stable in f26') @@ -193,9 +179,7 @@ def test_404_for_invalid_decision_context(requests_session, greenwave_server, te 'subject_type': 'koji_build', 'subject_identifier': nvr, } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 404 expected = ('Cannot find any applicable policies for koji_build subjects ' 'at gating point bodhi_push_update in fedora-26') @@ -204,8 +188,7 @@ def test_404_for_invalid_decision_context(requests_session, greenwave_server, te @pytest.mark.smoke def test_415_for_missing_request_content_type(requests_session, greenwave_server): - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - data=json.dumps({})) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json={}) assert r.status_code == 415 expected = "No JSON payload in request" assert expected == r.json()['message'] @@ -235,9 +218,7 @@ def test_make_a_decision_on_passed_result(requests_session, greenwave_server, te 'subject_identifier': nvr, } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() assert res_data['policies_satisfied'] is True @@ -264,9 +245,7 @@ def test_make_a_decision_with_verbose_flag(requests_session, greenwave_server, t 'verbose': True, } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() @@ -305,9 +284,7 @@ def test_make_a_decision_with_verbose_flag_and_multiple_nvrs_with_results( 'verbose': True, } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() @@ -339,9 +316,7 @@ def test_make_a_decision_with_verbose_flag_and_multiple_nvrs_with_waivers( 'verbose': True, } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() @@ -371,9 +346,7 @@ def test_make_a_decision_on_failed_result_with_waiver( 'subject_type': 'koji_build', 'subject_identifier': nvr, } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() assert res_data['policies_satisfied'] is True @@ -394,9 +367,7 @@ def test_make_a_decision_on_failed_result(requests_session, greenwave_server, te 'subject_type': 'koji_build', 'subject_identifier': nvr, } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() assert res_data['policies_satisfied'] is False @@ -436,9 +407,7 @@ def test_make_a_decision_on_queued_result(requests_session, greenwave_server, te 'subject_type': 'koji_build', 'subject_identifier': nvr, } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() assert res_data['policies_satisfied'] is False @@ -479,9 +448,7 @@ def test_make_a_decision_on_running_result(requests_session, greenwave_server, t 'subject_type': 'koji_build', 'subject_identifier': nvr, } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() assert res_data['policies_satisfied'] is False @@ -519,9 +486,7 @@ def test_make_a_decision_on_no_results(requests_session, greenwave_server, testd 'subject_type': 'koji_build', 'subject_identifier': nvr, } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() assert res_data['policies_satisfied'] is False @@ -554,9 +519,7 @@ def test_subject_type_group(requests_session, greenwave_server, testdatabuilder) 'subject_type': 'group', 'subject_identifier': results_item, } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 @@ -577,9 +540,7 @@ def test_empty_policy_is_always_satisfied( 'subject_type': 'bodhi_update', 'subject_identifier': 'FEDORA-2000-abcdef01', } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() assert res_data['policies_satisfied'] is True @@ -602,9 +563,7 @@ def test_bodhi_push_update_stable_policy( 'subject_type': 'koji_build', 'subject_identifier': nvr, } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() assert res_data['policies_satisfied'] is True @@ -628,10 +587,7 @@ def test_bodhi_nonexistent_bodhi_update_policy( 'subject_type': 'bodhi_update', 'subject_identifier': 'FEDORA-2000-deadbeaf', } - r = requests_session.post( - greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() assert res_data['policies_satisfied'] is True @@ -665,9 +621,7 @@ def test_multiple_results_in_a_subject( 'subject_type': 'koji_build', 'subject_identifier': nvr, } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() # The failed result should be taken into account. @@ -706,9 +660,7 @@ def test_ignore_result(requests_session, greenwave_server, testdatabuilder): 'subject_type': 'koji_build', 'subject_identifier': nvr, } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() assert res_data['policies_satisfied'] is True @@ -716,9 +668,7 @@ def test_ignore_result(requests_session, greenwave_server, testdatabuilder): data.update({ 'ignore_result': [result['id']] }) - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) expected_unsatisfied_requirements = [ { 'item': {'item': nvr, 'type': 'koji_build'}, @@ -738,9 +688,7 @@ def test_ignore_result(requests_session, greenwave_server, testdatabuilder): # ...we should get the same behaviour. del(data['ignore_result']) data['when'] = right_before_this_time(result['submit_time']) - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() assert res_data['policies_satisfied'] is False @@ -766,9 +714,7 @@ def test_make_a_decision_on_passed_result_with_scenario( 'subject_type': 'compose', 'subject_identifier': compose_id, } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() assert res_data['policies_satisfied'] is True @@ -803,9 +749,7 @@ def test_make_a_decision_on_failing_result_with_scenario( 'subject_type': 'compose', 'subject_identifier': compose_id, } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() assert res_data['policies_satisfied'] is False @@ -845,9 +789,7 @@ def test_ignore_waiver(requests_session, greenwave_server, testdatabuilder): 'subject_type': 'koji_build', 'subject_identifier': nvr, } - r_ = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r_ = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r_.status_code == 200 res_data = r_.json() assert res_data['policies_satisfied'] is True @@ -855,9 +797,7 @@ def test_ignore_waiver(requests_session, greenwave_server, testdatabuilder): data.update({ 'ignore_waiver': [waiver['id']] }) - r_ = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r_ = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r_.status_code == 200 res_data = r_.json() expected_unsatisfied_requirements = [ @@ -876,9 +816,7 @@ def test_ignore_waiver(requests_session, greenwave_server, testdatabuilder): # ...we should get the same behaviour. del(data['ignore_waiver']) data['when'] = right_before_this_time(waiver['timestamp']) - r_ = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r_ = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r_.status_code == 200 res_data = r_.json() assert res_data['policies_satisfied'] is False @@ -915,9 +853,7 @@ def test_cached_false_positive(requests_session, greenwave_server, testdatabuild 'subject_type': 'bodhi_update', 'subject_identifier': 'FEDORA-2000-abcdef01', } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() assert res_data['policies_satisfied'] is True @@ -927,9 +863,7 @@ def test_cached_false_positive(requests_session, greenwave_server, testdatabuild testdatabuilder.create_result(item=nvr, testcase_name=TASKTRON_RELEASE_CRITICAL_TASKS[-1], outcome='FAILED') - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() assert res_data['policies_satisfied'] is True @@ -953,9 +887,7 @@ def test_blacklist(requests_session, greenwave_server, testdatabuilder): 'subject_type': 'bodhi_update', 'subject_identifier': 'FEDORA-2000-abcdef01', } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() # the failed test result of dist.abicheck should be ignored and thus the policy @@ -976,9 +908,7 @@ def test_excluded_packages(requests_session, greenwave_server, testdatabuilder): 'product_version': 'rhel-something', 'subject': [{'type': 'brew-build', 'item': nvr}], } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() # the failed test result of sci.brew-build.tier0.functiona should be ignored and thus the @@ -999,9 +929,7 @@ def test_make_a_decision_about_brew_build(requests_session, greenwave_server, te 'subject': [{'type': 'brew-build', 'item': nvr}], } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() assert res_data['policies_satisfied'] is True @@ -1138,9 +1066,7 @@ def test_make_a_decision_about_compose_all_variants_architectures( 'subject_type': 'compose', 'subject_identifier': compose_id, } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() assert not res_data['policies_satisfied'] @@ -1170,9 +1096,7 @@ def test_make_a_decision_about_compose_new_variants_architectures( 'subject_type': 'compose', 'subject_identifier': compose_id, } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() assert res_data['policies_satisfied'] @@ -1231,15 +1155,13 @@ def test_decision_on_redhat_module(requests_session, greenwave_server, testdatab 'subject_identifier': nvr, 'verbose': True } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() assert res_data['policies_satisfied'] is True expected_summary = 'All required tests passed' assert res_data['summary'] == expected_summary - res_data['results'][0]['data']['type'][0] == 'redhat-module' + assert res_data['results'][0]['data']['type'][0] == 'redhat-module' def test_verbose_retrieve_latest_results(requests_session, greenwave_server, testdatabuilder): @@ -1257,9 +1179,7 @@ def test_verbose_retrieve_latest_results(requests_session, greenwave_server, tes 'verbose': True } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() assert res_data['policies_satisfied'] is True @@ -1297,9 +1217,7 @@ def test_make_decision_passed_on_subject_type_bodhi_with_waiver( 'subject_identifier': nvr, } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() assert res_data['policies_satisfied'] is True @@ -1337,9 +1255,7 @@ def test_make_a_decision_with_verbose_flag_all_results_returned( 'subject_identifier': nvr, 'verbose': True, } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() @@ -1364,9 +1280,7 @@ def test_verbose_retrieve_latest_results_scenario(requests_session, greenwave_se 'verbose': True } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() assert res_data['policies_satisfied'] is True @@ -1396,9 +1310,7 @@ def test_api_returns_not_repeated_waiver_in_verbose_info( ], 'verbose': True } - r_ = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r_ = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r_.status_code == 200 res_data = r_.json() assert len(res_data['waivers']) == 1 @@ -1421,9 +1333,7 @@ def test_api_with_when(requests_session, greenwave_server, testdatabuilder): 'when': right_before_this_time(results[1]['submit_time']), 'verbose': True, } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() @@ -1431,9 +1341,7 @@ def test_api_with_when(requests_session, greenwave_server, testdatabuilder): assert res_data['results'] == [results[0]] del data['when'] - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() @@ -1455,9 +1363,7 @@ def test_cannot_make_decision_with_both_decision_context_and_user_policies( }, ], } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 400 assert ('Cannot have both decision_context and rules') == r.json()['message'] @@ -1480,9 +1386,7 @@ def test_cannot_make_decision_without_required_rule_type( }, ], } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 400 assert ('Key \'type\' is required for every rule') == r.json()['message'] @@ -1504,9 +1408,7 @@ def test_cannot_make_decision_without_required_rule_testcase_name( }, ], } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 400 assert ('Key \'test_case_name\' is required if not a RemoteRule') == r.json()['message'] @@ -1550,9 +1452,7 @@ def test_make_a_decision_with_verbose_flag_on_demand_policy( }, ], } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json() @@ -1603,9 +1503,7 @@ def test_make_a_decision_on_demand_policy( }, ], } - r = requests_session.post(greenwave_server + 'api/v1.0/decision', - headers={'Content-Type': 'application/json'}, - data=json.dumps(data)) + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 res_data = r.json()