Skip to content

Commit 8922cb0

Browse files
committed
Factored test driver
1 parent 9d5c69d commit 8922cb0

File tree

3 files changed

+11
-26
lines changed

3 files changed

+11
-26
lines changed

tests/iris.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,12 @@ def update(self, path, body):
6969
def delete(self, path):
7070
return self._api.delete(path)
7171

72-
def post_multipart_encoded_file(self, path, data, file_path):
73-
return self._api.post_multipart_encoded_file(path, data, file_path)
72+
def create_report(self, data, template_name):
73+
file_path = f'data/report_templates/{template_name}'
74+
with open(file_path, 'rb') as file:
75+
files = {'file': file}
76+
response = self._api.post_multipart_encoded_files('/manage/templates/add', data, files).json()
77+
return response['data']['report_id']
7478

7579
def post_multipart_encoded_files(self, path, data, files):
7680
return self._api.post_multipart_encoded_files(path, data, files)

tests/rest_api.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,6 @@ def is_ready(self):
7474
except ConnectionError:
7575
return False
7676

77-
def post_multipart_encoded_file(self, path, data, file_path):
78-
headers = {'Authorization': f'Bearer {self._api_key}'}
79-
with open(file_path, 'rb') as file:
80-
url = self._build_url(path)
81-
response = requests.post(url, headers=headers, data=data, files={'file': file})
82-
response_as_string = self._convert_response_to_string(response)
83-
print(f'POST {url} {data} {file_path} => {response_as_string}')
84-
return response
85-
8677
def post_multipart_encoded_files(self, path, data, files):
8778
headers = {'Authorization': f'Bearer {self._api_key}'}
8879
url = self._build_url(path)

tests/tests_rest_reports.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ def tearDown(self):
3838
def test_generate_docx_report__in_safe_mode_should_return_200(self):
3939
data = {'report_name': 'name', 'report_type': 1, 'report_language': 1, 'report_description': 'description',
4040
'report_name_format': 'report_name_format'}
41-
response = self._subject.post_multipart_encoded_file('/manage/templates/add', data,
42-
'data/report_templates/empty.docx').json()
43-
report_identifier = response['data']['report_id']
41+
report_identifier = self._subject.create_report(data, 'empty.docx')
4442
case_identifier = self._subject.create_dummy_case()
4543
response = self._subject.get(f'/case/report/generate-investigation/{report_identifier}',
4644
{'cid': case_identifier, 'safe': True})
@@ -49,9 +47,7 @@ def test_generate_docx_report__in_safe_mode_should_return_200(self):
4947
def test_generate_docx_report_should_render_variable_case_for_customer(self):
5048
data = {'report_name': 'name', 'report_type': 1, 'report_language': 1, 'report_description': 'description',
5149
'report_name_format': 'report_name_format'}
52-
response = self._subject.post_multipart_encoded_file('/manage/templates/add', data,
53-
'data/report_templates/variable_case_for_customer.docx').json()
54-
report_identifier = response['data']['report_id']
50+
report_identifier = self._subject.create_report(data,'variable_case_for_customer.docx')
5551
case_identifier = self._subject.create_dummy_case()
5652
response = self._subject.get(f'/case/report/generate-investigation/{report_identifier}',
5753
{'cid': case_identifier, 'safe': True})
@@ -62,9 +58,7 @@ def test_generate_docx_report_should_render_variable_case_for_customer(self):
6258
def test_generate_md_report_should_render_variable_case_name(self):
6359
data = {'report_name': 'name', 'report_type': 1, 'report_language': 1, 'report_description': 'description',
6460
'report_name_format': 'report_name_format'}
65-
response = self._subject.post_multipart_encoded_file('/manage/templates/add', data,
66-
'data/report_templates/variable_case_name.md').json()
67-
report_identifier = response['data']['report_id']
61+
report_identifier = self._subject.create_report(data,'variable_case_name.md')
6862
case_identifier = self._subject.create_dummy_case()
6963
response = self._subject.get(f'/case/report/generate-investigation/{report_identifier}',
7064
{'cid': case_identifier, 'safe': True})
@@ -73,9 +67,7 @@ def test_generate_md_report_should_render_variable_case_name(self):
7367
def test_generate_md_report_should_render_variable_case_for_customer(self):
7468
data = {'report_name': 'name', 'report_type': 1, 'report_language': 1, 'report_description': 'description',
7569
'report_name_format': 'report_name_format'}
76-
response = self._subject.post_multipart_encoded_file('/manage/templates/add', data,
77-
'data/report_templates/variable_case_for_customer.md').json()
78-
report_identifier = response['data']['report_id']
70+
report_identifier = self._subject.create_report(data,'variable_case_for_customer.md')
7971
case_identifier = self._subject.create_dummy_case()
8072
response = self._subject.get(f'/case/report/generate-investigation/{report_identifier}',
8173
{'cid': case_identifier, 'safe': True})
@@ -84,9 +76,7 @@ def test_generate_md_report_should_render_variable_case_for_customer(self):
8476
def test_generate_md_activities_report_should_render_variable_case_for_customer_when(self):
8577
data = {'report_name': 'name', 'report_type': 2, 'report_language': 1, 'report_description': 'description',
8678
'report_name_format': 'report_name_format'}
87-
response = self._subject.post_multipart_encoded_file('/manage/templates/add', data,
88-
'data/report_templates/variable_case_for_customer.md').json()
89-
report_identifier = response['data']['report_id']
79+
report_identifier = self._subject.create_report(data,'variable_case_for_customer.md')
9080
case_identifier = self._subject.create_dummy_case()
9181
response = self._subject.get(f'/case/report/generate-activities/{report_identifier}',
9282
{'cid': case_identifier, 'safe': True})

0 commit comments

Comments
 (0)