Skip to content

Commit 1fa86be

Browse files
jstuckerhelmke
authored andcommitted
refactor: remove useless class from test
1 parent f34190a commit 1fa86be

File tree

1 file changed

+65
-63
lines changed

1 file changed

+65
-63
lines changed

src/test/acceptance/rest/test_rest_analyze_firmware.py

Lines changed: 65 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -8,66 +8,68 @@
88
test_container_uid = '418a54d78550e8584291c96e5d6168133621f352bfc1d43cf84e81187fef4962_787'
99

1010

11-
class TestRestFirmware:
12-
def _rest_upload_firmware(self, test_client):
13-
data = get_firmware_for_rest_upload_test()
14-
rv = test_client.put('/rest/firmware', json=data, follow_redirects=True)
15-
assert b'"status": 0' in rv.data, 'rest upload not successful'
16-
assert test_container_uid.encode() in rv.data, 'uid not found in rest upload reply'
17-
18-
def _rest_get_analysis_result(self, test_client):
19-
rv = test_client.get(f'/rest/firmware/{test_container_uid}', follow_redirects=True)
20-
assert b'analysis_date' in rv.data, 'rest analysis download not successful'
21-
assert b'software_components' in rv.data, 'rest analysis not successful'
22-
assert b'"device_part": "test_part' in rv.data, 'device part not present'
23-
24-
def _rest_search(self, test_client):
25-
query = urllib.parse.quote('{"device_class": "test_class"}')
26-
rv = test_client.get(f'/rest/firmware?query={query}', follow_redirects=True)
27-
assert test_container_uid.encode() in rv.data, 'test firmware not found in rest search'
28-
29-
def _rest_search_fw_only(self, test_client):
30-
query = json.dumps({'sha256': test_container_uid.split('_')[0]})
31-
rv = test_client.get(f'/rest/firmware?query={urllib.parse.quote(query)}', follow_redirects=True)
32-
assert test_container_uid.encode() in rv.data, 'test firmware not found in rest search'
33-
34-
def _rest_update_analysis_bad_analysis(self, test_client):
35-
query = urllib.parse.quote('["unknown_system"]')
36-
rv = test_client.put(f'/rest/firmware/{test_container_uid}?update={query}', follow_redirects=True)
37-
assert (
38-
b'Unknown analysis system' in rv.data
39-
), 'rest analysis update should break on request of non existing system'
40-
41-
def _rest_update_analysis_success(self, test_client):
42-
update = urllib.parse.quote(json.dumps(['crypto_material']))
43-
rv = test_client.put(f'/rest/firmware/{test_container_uid}?update={update}', follow_redirects=True)
44-
assert b'error_message' not in rv.data, 'Error on update request'
45-
46-
def _rest_check_new_analysis_exists(self, test_client):
47-
rv = test_client.get(f'/rest/firmware/{test_container_uid}', follow_redirects=True)
48-
response_data = json.loads(rv.data.decode())
49-
assert response_data['firmware']['analysis']['crypto_material']
50-
assert (
51-
response_data['firmware']['analysis']['crypto_material']['analysis_date']
52-
> response_data['firmware']['analysis']['software_components']['analysis_date']
53-
)
54-
55-
@pytest.mark.usefixtures('intercom_backend_binding')
56-
# container including 3 files times 3 plugins
57-
@pytest.mark.SchedulerTestConfig(items_to_analyze=4 * 3)
58-
def test_run_from_upload_to_show_analysis_and_search(
59-
self, test_client, analysis_finished_event, analysis_finished_counter
60-
):
61-
self._rest_upload_firmware(test_client)
62-
assert analysis_finished_event.wait(timeout=30)
63-
analysis_finished_counter.value -= 4 # only one plugin to update
64-
analysis_finished_event.clear()
65-
self._rest_get_analysis_result(test_client)
66-
self._rest_search(test_client)
67-
self._rest_search_fw_only(test_client)
68-
self._rest_update_analysis_bad_analysis(test_client)
69-
self._rest_update_analysis_success(test_client)
70-
71-
assert analysis_finished_event.wait(timeout=30)
72-
73-
self._rest_check_new_analysis_exists(test_client)
11+
def _rest_upload_firmware(test_client):
12+
data = get_firmware_for_rest_upload_test()
13+
rv = test_client.put('/rest/firmware', json=data, follow_redirects=True)
14+
assert b'"status": 0' in rv.data, 'rest upload not successful'
15+
assert test_container_uid.encode() in rv.data, 'uid not found in rest upload reply'
16+
17+
18+
def _rest_get_analysis_result(test_client):
19+
rv = test_client.get(f'/rest/firmware/{test_container_uid}', follow_redirects=True)
20+
assert b'analysis_date' in rv.data, 'rest analysis download not successful'
21+
assert b'software_components' in rv.data, 'rest analysis not successful'
22+
assert b'"device_part": "test_part' in rv.data, 'device part not present'
23+
24+
25+
def _rest_search(test_client):
26+
query = urllib.parse.quote('{"device_class": "test_class"}')
27+
rv = test_client.get(f'/rest/firmware?query={query}', follow_redirects=True)
28+
assert test_container_uid.encode() in rv.data, 'test firmware not found in rest search'
29+
30+
31+
def _rest_search_fw_only(test_client):
32+
query = json.dumps({'sha256': test_container_uid.split('_')[0]})
33+
rv = test_client.get(f'/rest/firmware?query={urllib.parse.quote(query)}', follow_redirects=True)
34+
assert test_container_uid.encode() in rv.data, 'test firmware not found in rest search'
35+
36+
37+
def _rest_update_analysis_bad_analysis(test_client):
38+
query = urllib.parse.quote('["unknown_system"]')
39+
rv = test_client.put(f'/rest/firmware/{test_container_uid}?update={query}', follow_redirects=True)
40+
assert b'Unknown analysis system' in rv.data, 'rest analysis update should break on request of non existing system'
41+
42+
43+
def _rest_update_analysis_success(test_client):
44+
update = urllib.parse.quote(json.dumps(['crypto_material']))
45+
rv = test_client.put(f'/rest/firmware/{test_container_uid}?update={update}', follow_redirects=True)
46+
assert b'error_message' not in rv.data, 'Error on update request'
47+
48+
49+
def _rest_check_new_analysis_exists(test_client):
50+
rv = test_client.get(f'/rest/firmware/{test_container_uid}', follow_redirects=True)
51+
response_data = json.loads(rv.data.decode())
52+
assert response_data['firmware']['analysis']['crypto_material']
53+
assert (
54+
response_data['firmware']['analysis']['crypto_material']['analysis_date']
55+
> response_data['firmware']['analysis']['software_components']['analysis_date']
56+
)
57+
58+
59+
@pytest.mark.usefixtures('intercom_backend_binding')
60+
# container including 3 files times 3 plugins
61+
@pytest.mark.SchedulerTestConfig(items_to_analyze=4 * 3)
62+
def test_run_from_upload_to_show_analysis_and_search(test_client, analysis_finished_event, analysis_finished_counter):
63+
_rest_upload_firmware(test_client)
64+
assert analysis_finished_event.wait(timeout=30)
65+
analysis_finished_counter.value -= 4 # only one plugin to update
66+
analysis_finished_event.clear()
67+
_rest_get_analysis_result(test_client)
68+
_rest_search(test_client)
69+
_rest_search_fw_only(test_client)
70+
_rest_update_analysis_bad_analysis(test_client)
71+
_rest_update_analysis_success(test_client)
72+
73+
assert analysis_finished_event.wait(timeout=30)
74+
75+
_rest_check_new_analysis_exists(test_client)

0 commit comments

Comments
 (0)