Skip to content

Commit c9978c3

Browse files
Refactor- added teardown decorator
1 parent 0db0f3c commit c9978c3

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

integration/test_alerts.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import json
22

33
from integration import run_command
4-
from integration.util import cleanup
4+
from integration.util import cleanup_after_validation
55

66

77
def _parse_response(response):
@@ -18,13 +18,16 @@ def test_alert_prints_to_stdout_and_filters_result_between_given_date():
1818
assert record["createdAt"].startswith("2020-05-18")
1919

2020

21+
def _validate_severity(response):
22+
parsed_response = _parse_response(response)
23+
for record in parsed_response:
24+
assert record["severity"] == "MEDIUM"
25+
26+
27+
@cleanup_after_validation("./integration/alerts")
2128
def test_alert_writes_to_file_and_filters_result_by_severity():
22-
command = "code42 alerts write-to ./integration/alerts -b 2020-05-18 -e " \
23-
"2020-05-20 --severity MEDIUM"
29+
command = "code42 alerts write-to ./integration/alerts -b 2020-05-18 -e 2020-05-20 " \
30+
"--severity MEDIUM"
2431
return_code, response = run_command(command)
2532
assert return_code is 0
26-
with cleanup("./integration/alerts") as f:
27-
response = f.read()
28-
parsed_response = _parse_response(response)
29-
for record in parsed_response:
30-
assert record["severity"] == "MEDIUM"
33+
return _validate_severity

integration/util.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,14 @@ def __enter__(self):
1010

1111
def __exit__(self, exc_type, exc_val, exc_tb):
1212
run_command("rm -f {}".format(self.filename))
13+
14+
15+
def cleanup_after_validation(filename):
16+
def wrap(test_function):
17+
def wrapper():
18+
validate = test_function()
19+
with cleanup(filename) as f:
20+
response = f.read()
21+
validate(response)
22+
return wrapper
23+
return wrap

0 commit comments

Comments
 (0)