Skip to content

Commit

Permalink
Update tests for PayloadResults.workers being Dict
Browse files Browse the repository at this point in the history
  • Loading branch information
mlaferrera committed Jul 17, 2019
1 parent b7034db commit a8623a2
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions stoq/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ def test_split_results(self):
split_response = response.split()
self.assertEqual(len(split_response), 2)
for r in split_response:
if 'simple_worker' in r['results'][0]['workers'][0]:
self.assertNotIn('multiclass_plugin', r['results'][0]['workers'][0])
elif 'multiclass_plugin' in r['results'][0]['workers'][0]:
self.assertNotIn('simple_worker', r['results'][0]['workers'][0])
if 'simple_worker' in r['results'][0]['workers']:
self.assertNotIn('multiclass_plugin', r['results'][0]['workers'])
elif 'multiclass_plugin' in r['results'][0]['workers']:
self.assertNotIn('simple_worker', r['results'][0]['workers'])
else:
raise Exception('required plugin not found in results')

Expand All @@ -118,9 +118,9 @@ def test_always_dispatch(self):
def test_start_dispatch(self):
s = Stoq(base_dir=utils.get_data_dir())
response = s.scan(self.generic_content, add_start_dispatch=['extract_random'])
self.assertIn('extract_random', response.results[0].plugins_run['workers'][0])
self.assertIn('extract_random', response.results[0].plugins_run['workers'])
self.assertNotIn(
'extract_random', response.results[1].plugins_run['workers'][0]
'extract_random', response.results[1].plugins_run['workers']
)

def test_dispatch(self):
Expand Down Expand Up @@ -204,7 +204,7 @@ def test_dispatch_nonexistent_plugin(self):
self.generic_content, add_start_dispatch=['this_plugin_doesnt_exist']
)
self.assertNotIn(
'this_plugin_doesnt_exist', response.results[0].plugins_run['workers'][0]
'this_plugin_doesnt_exist', response.results[0].plugins_run['workers']
)
self.assertEqual(len(response.errors), 1)

Expand Down Expand Up @@ -269,9 +269,9 @@ def test_dont_dest_archive_yara(self):
def test_worker_in_results(self):
s = Stoq(base_dir=utils.get_data_dir())
response = s.scan(self.generic_content, add_start_dispatch=['simple_worker'])
self.assertIn('simple_worker', response.results[0].workers[0])
self.assertIn('simple_worker', response.results[0].workers)
self.assertIn(
'valuable_insight', response.results[0].workers[0]['simple_worker']
'valuable_insight', response.results[0].workers['simple_worker']
)
self.assertEqual(len(response.errors), 0)

Expand Down Expand Up @@ -311,7 +311,7 @@ def test_worker_errors(self):
simple_worker.RETURN_ERRORS = True
response = s.scan(self.generic_content, add_start_dispatch=['simple_worker'])
self.assertIn('simple_worker', response.results[0].plugins_run['workers'][0])
self.assertIn('simple_worker', response.results[0].workers[0])
self.assertIn('simple_worker', response.results[0].workers)
self.assertEqual(len(response.errors), 1)
self.assertIn('Test error', response.errors['simple_worker'][0])

Expand Down Expand Up @@ -560,33 +560,33 @@ def test_reconstruct_all_subresponses(self):
payload_id="A.zip",
size=0,
payload_meta=PayloadMeta(),
workers=[{"fake": "result1"}],
plugins_run={"workers": [["fake"]]},
workers={"fake": "result1"},
plugins_run={"workers": ["fake"]},
),
PayloadResults(
payload_id="B.txt",
size=0,
payload_meta=PayloadMeta(),
workers=[{"fake": "result2"}],
plugins_run={"workers": [["fake"]]},
workers={"fake": "result2"},
plugins_run={"workers": ["fake"]},
extracted_from="A.zip",
extracted_by="fake",
),
PayloadResults(
payload_id="C.zip",
size=0,
payload_meta=PayloadMeta(),
workers=[{"fake": "result3"}],
plugins_run={"workers": [["fake"]]},
workers={"fake": "result3"},
plugins_run={"workers": ["fake"]},
extracted_from="A.zip",
extracted_by="fake",
),
PayloadResults(
payload_id="D.txt",
size=0,
payload_meta=PayloadMeta(),
workers=[{"fake": "result4"}],
plugins_run={"workers": [["fake"]]},
workers={"fake": "result4"},
plugins_run={"workers": ["fake"]},
extracted_from="C.zip",
extracted_by="fake",
),
Expand All @@ -607,7 +607,7 @@ def test_reconstruct_all_subresponses(self):
)
self.assertEqual(
[
stoq_response.results[0].workers[0]["fake"]
stoq_response.results[0].workers["fake"]
for stoq_response in all_subresponses
],
["result1", "result2", "result3", "result4"],
Expand Down

0 comments on commit a8623a2

Please sign in to comment.