Skip to content

Commit

Permalink
Fix waiving all scenarios (#73)
Browse files Browse the repository at this point in the history
If a matching waiver has scenario=null, it should apply to all test
results disregarding their scenario values.

JIRA: RHELWF-7314
  • Loading branch information
hluk committed Aug 18, 2022
1 parent 414dd34 commit 01b14ed
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 7 deletions.
53 changes: 53 additions & 0 deletions functional-tests/test_api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -1733,3 +1733,56 @@ def test_make_a_decision_on_passed_result_with_custom_scenario(
'type': 'test-result-passed'
}
]


def test_make_a_decision_all_scenarios_waived(
requests_session, greenwave_server, testdatabuilder):
nvr = testdatabuilder.unique_nvr()
scenarios = ('scenario1', 'scenario2')

results = [
testdatabuilder.create_result(
item=nvr,
testcase_name='test1',
outcome='FAILED',
scenario=scenario,
)
for scenario in scenarios
]

testdatabuilder.create_waiver(
nvr=nvr,
product_version='fedora-26',
testcase_name='test1',
comment='This is fine',
)

data = {
'rules': [
{"type": "PassingTestCaseRule", "test_case_name": "test1", "scenario": scenario}
for scenario in scenarios
],
'product_version': 'fedora-26',
'subject_type': 'koji_build',
'subject_identifier': nvr,
}
r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data)
assert r.status_code == 200
res_data = r.json()
assert res_data['unsatisfied_requirements'] == []
assert res_data['satisfied_requirements'] == [
{
'subject_identifier': nvr,
'subject_type': 'koji_build',
'result_id': result['id'],
'testcase': 'test1',
'scenario': result['data']['scenario'][0],
'system_architecture': None,
'system_variant': None,
'source': None,
'type': 'test-result-failed-waived'
}
for result in results
]
assert res_data['policies_satisfied'] is True
assert res_data['summary'] == 'All required tests passed'
15 changes: 8 additions & 7 deletions greenwave/decision.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,14 @@ def waive_answers(self, waivers_retriever):
if not self.verbose:
for answer in self.answers:
if not answer.is_satisfied:
self.waiver_filters.append(dict(
subject_type=answer.subject.type,
subject_identifier=answer.subject.identifier,
product_version=self.product_version,
testcase=answer.test_case_name,
scenario=answer.scenario
))
waiver = {
"subject_type": answer.subject.type,
"subject_identifier": answer.subject.identifier,
"product_version": self.product_version,
"testcase": answer.test_case_name,
}
if waiver not in self.waiver_filters:
self.waiver_filters.append(waiver)

if self.waiver_filters:
self.waivers = waivers_retriever.retrieve(self.waiver_filters)
Expand Down
51 changes: 51 additions & 0 deletions greenwave/tests/test_waive.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,54 @@ def test_waive_scenario():
)
assert 1 == len(waived)
assert expected_json == waived[0].to_json()


def test_waive_scenarios_all():
answers = [
TestResultFailed(
subject=test_subject(),
test_case_name='test1',
source='https://greenwave_tests.example.com',
result_id=98,
data={'scenario': 'scenario1'},
),
TestResultFailed(
subject=test_subject(),
test_case_name='test1',
source='https://greenwave_tests.example.com',
result_id=99,
data={'scenario': 'scenario2'},
)
]

waivers = [
dict(
subject_type='koji_build',
subject_identifier='nethack-1.2.3-1.rawhide',
product_version='rawhide',
testcase='test1',
scenario=None
)
]
waived = waive_answers(answers, waivers)
expected_json = [
dict(
type='test-result-failed-waived',
testcase='test1',
subject_type='koji_build',
subject_identifier='nethack-1.2.3-1.rawhide',
result_id=98,
scenario='scenario1',
source='https://greenwave_tests.example.com',
),
dict(
type='test-result-failed-waived',
testcase='test1',
subject_type='koji_build',
subject_identifier='nethack-1.2.3-1.rawhide',
result_id=99,
scenario='scenario2',
source='https://greenwave_tests.example.com',
),
]
assert expected_json == [w.to_json() for w in waived]

0 comments on commit 01b14ed

Please sign in to comment.