#506 Tests for subject_type=group
Merged 4 years ago by vmaljulin. Opened 4 years ago by vmaljulin.
vmaljulin/greenwave FACTORY-5349  into  master

@@ -132,3 +132,12 @@ 

  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}

file modified
+4 -4
@@ -257,9 +257,9 @@ 

      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 @@ 

          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()

  

@@ -229,9 +229,7 @@ 

          '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 @@ 

          '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 @@ 

          '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 @@ 

          '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()

  

file modified
+79 -152
@@ -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 @@ 

      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)
@@ -89,9 +91,7 @@ 

          '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']

  
@@ -104,9 +104,7 @@ 

          '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']

  
@@ -118,9 +116,7 @@ 

          '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']

  
@@ -132,9 +128,7 @@ 

          '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']

  
@@ -146,9 +140,7 @@ 

          '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']

  
@@ -157,9 +149,7 @@ 

          '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']

  
@@ -173,9 +163,7 @@ 

          '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')
@@ -191,9 +179,7 @@ 

          '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')
@@ -202,8 +188,7 @@ 

  

  @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']
@@ -233,9 +218,7 @@ 

          '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
@@ -262,9 +245,7 @@ 

          '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()

  
@@ -303,9 +284,7 @@ 

          '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()

  
@@ -337,9 +316,7 @@ 

          '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()

  
@@ -369,9 +346,7 @@ 

          '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
@@ -392,9 +367,7 @@ 

          '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
@@ -434,9 +407,7 @@ 

          '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
@@ -477,9 +448,7 @@ 

          '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
@@ -517,9 +486,7 @@ 

          '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
@@ -540,6 +507,31 @@ 

      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', json=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 = {
@@ -548,9 +540,7 @@ 

          '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
@@ -573,9 +563,7 @@ 

          '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
@@ -599,10 +587,7 @@ 

          '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
@@ -636,9 +621,7 @@ 

          '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.
@@ -677,9 +660,7 @@ 

          '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
@@ -687,9 +668,7 @@ 

      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'},
@@ -709,9 +688,7 @@ 

      # ...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
@@ -737,9 +714,7 @@ 

          '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
@@ -774,9 +749,7 @@ 

          '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
@@ -816,9 +789,7 @@ 

          '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
@@ -826,9 +797,7 @@ 

      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 = [
@@ -847,9 +816,7 @@ 

      # ...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
@@ -886,9 +853,7 @@ 

          '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
@@ -898,9 +863,7 @@ 

      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
@@ -924,9 +887,7 @@ 

          '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
@@ -947,9 +908,7 @@ 

          '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
@@ -970,9 +929,7 @@ 

          '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
@@ -1109,9 +1066,7 @@ 

          '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']
@@ -1141,9 +1096,7 @@ 

          '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']
@@ -1202,15 +1155,13 @@ 

          '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):
@@ -1228,9 +1179,7 @@ 

          '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
@@ -1268,9 +1217,7 @@ 

          '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
@@ -1308,9 +1255,7 @@ 

          '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()

  
@@ -1335,9 +1280,7 @@ 

          '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
@@ -1367,9 +1310,7 @@ 

          ],

          '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
@@ -1392,9 +1333,7 @@ 

          '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()

  
@@ -1402,9 +1341,7 @@ 

      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()

  
@@ -1426,9 +1363,7 @@ 

              },

          ],

      }

-     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']

  
@@ -1451,9 +1386,7 @@ 

              },

          ],

      }

-     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']

  
@@ -1475,9 +1408,7 @@ 

              },

          ],

      }

-     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']

  
@@ -1521,9 +1452,7 @@ 

              },

          ],

      }

-     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()

  
@@ -1574,9 +1503,7 @@ 

              },

          ],

      }

-     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()

  

This comment doesn't really seem related to the code. You mention a failed result waived, but then you create a PASSED result and no waiver. Maybe copy/paste?

The issue is here: this function (functional-tests/conftest.py) creates by default a result with subject type "koji_build", but you want to create a result with subject type "group". So when you check for the decision, greenwave doesn't find any result with subject type "group", because the one you created has type "koji_build".
This function also takes an additional parameter "_type" that you can use to specify the subject type ("group" in this case).

You need to add here also "verbose": True as parameter. Otherwise you're not going to get the info about the result that you are checking later in the "assert" part.

If you add "verbose" True as parameter that's what you're going to get as res_data:


{'applicable_policies': ['compose-test-scenario-group'],
'policies_satisfied': True,
'results': [{'data': {'item': ['sha256:fe6e893b8b1b9a56df1d1f4909e4a1c2e31963d06afc1de477c34841e523f8fe'],
'type': ['group']},
'groups': [],
'href': 'http://resultsdb:5001/api/v2.0/results/326',
'id': 326,
'note': None,
'outcome': 'PASSED',
'ref_url': None,
'submit_time': '2019-10-24T09:43:38.873338',
'testcase': {'href': 'http://resultsdb:5001/api/v2.0/testcases/testcase_name',
'name': 'testcase_name',
'ref_url': None}}],
'satisfied_requirements': [{'result_id': 326,
'testcase': 'testcase_name',
'type': 'test-result-passed'}],
'summary': 'All required tests passed',
'unsatisfied_requirements': [],
'waivers': []}

You need then to change later to get the right info from there.

This comment doesn't really seem related to the code. You mention a failed result waived, but then you create a PASSED result and no waiver. Maybe copy/paste?

oh, my bad. that was just copy-pasted :)

The issue is here: this function (functional-tests/conftest.py) creates by default a result with subject type "koji_build", but you want to create a result with subject type "group". So when you check for the decision, greenwave doesn't find any result with subject type "group", because the one you created has type "koji_build".
This function also takes an additional parameter "_type" that you can use to specify the subject type ("group" in this case).

See it. Thank you!

rebased onto da6fe520c90d79cc3613ea7b4777a518942c6d2e

4 years ago

Comments were addressed

optional: can you put this all in one line? To make it look like the other ones.
It shouldn't be too long, so flake8 shouldn't complain about it.

The bad comment is still here :D

Flake8 complains about this line... could you check it?

As a side note: when you think you're done with the PR, remove the WIP so we are sure it can be merged :)

rebased onto 8ce3ded749860b573c571a7a14d912aae7a483da

4 years ago

rebased onto 1311962ddb33c11007c995206c0731683e65b4fe

4 years ago

I think there should be a list of artifacts/items in the group result data and it should be listed in the decision.

@gnaponie Is that correct? I'm still working on the details: https://pagure.io/fedora-ci/messages/pull-request/87

@lholecek I think there shouldn't be the details about the single results in the decision. Only about the "group" result (item == the hash of ids).
@lucarval what do you think?

I'm not sure... there is FACTORY-5347 that might be connected. But it regards results, I'm not sure this should be included in the decision itself. (Anyhow it would automatically get added if verbose=True, it would need changes on the greenwave side).

Consider using the json= parameter instead of data=. This has two benefits:

  1. No need to call json.dumps
  2. Content-Type header is automatically set.

https://requests.kennethreitz.org/en/master/user/quickstart/#more-complicated-post-requests

@lholecek I think there shouldn't be the details about the single results in the decision. Only about the "group" result (item == the hash of ids).
@lucarval what do you think?

I agree. At least for now, Greenwave is agnostic to what's actually in the group.

rebased onto dd5f28a

4 years ago

Consider using the json= parameter instead of data=. This has two benefits:

No need to call json.dumps
Content-Type header is automatically set.

https://requests.kennethreitz.org/en/master/user/quickstart/#more-complicated-post-requests

Refactored all functional tests for it

Pull-Request has been merged by vmaljulin

4 years ago