Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@stub_action('employee_service', 'get_employees_reports_by_manager_ids')
@stub_action('employee_service', 'get_employees_by_ids')
@stub_action('company_service', 'get_all_companies')
def test_expand_company_ceo_and_reports(
self,
mock_get_companies,
mock_get_employees,
mock_get_reports,
mock_get_images,
):
mock_get_companies.return_value = {
'companies': [
{'_type': 'company_type', 'company_id': '9183', 'name': 'Acme', 'ceo_id': '5791'},
{'_type': 'company_type', 'company_id': '7261', 'name': 'Logo Makers', 'ceo_id': '51', 'logo_id': '65'},
],
}
@stub_action('future_service', 'present_sounds', body={'when': 'present'})
def test_call_jobs_parallel_future_success(self, mock_present_sounds, mock_past_sounds):
client = Client({})
future = client.call_jobs_parallel_future(
[
{'service_name': 'future_service', 'actions': [
{'action': 'present_sounds', 'body': {'where': 'here'}},
]},
{'service_name': 'future_service', 'actions': [
{'action': 'past_sounds', 'body': {'where': 'there'}},
]},
],
)
mock_present_sounds.assert_called_once_with({'where': 'here'})
mock_past_sounds.assert_called_once_with({'where': 'there'})
@stub_action('future_service', 'present_sounds', errors=[{'code': 'BROKEN', 'message': 'Broken, dude'}])
def test_call_action_future_error(self, mock_present_sounds):
client = Client({})
future = client.call_action_future('future_service', 'present_sounds', body={'hello': 'world'})
mock_present_sounds.assert_called_once_with({'hello': 'world'})
with self.assertRaises(client.CallActionError) as error_context:
assert future.result()
first_exception = error_context.exception
assert len(error_context.exception.actions[0].errors) == 1
error = error_context.exception.actions[0].errors[0]
assert error.code == 'BROKEN'
@stub_action('employee_service', 'get_employees_by_ids')
@stub_action('company_service', 'get_all_companies')
def test_expand_company_ceo_and_logo(self, mock_get_companies, mock_get_employees, mock_get_images):
mock_get_companies.return_value = {
'companies': [
{'_type': 'company_type', 'company_id': '9183', 'name': 'Acme', 'ceo_id': '5791'},
{'_type': 'company_type', 'company_id': '7261', 'name': 'Logo Makers', 'ceo_id': '51', 'logo_id': '65'},
],
}
mock_get_employees.return_value = {
'employees': {
'5791': {'_type': 'employee_type', 'employee_id': '5791', 'name': 'Julia', 'photo_id': '37'},
'51': {'_type': 'employee_type', 'employee_id': '51', 'name': 'Nathan', 'photo_id': '79'},
},
}
'foo': {'transport': {'path': 'pysoa.test.stub_service:StubClientTransport'}},
'bar': {'transport': {'path': 'pysoa.test.stub_service:StubClientTransport'}},
'baz': {'transport': {'path': 'pysoa.test.stub_service:StubClientTransport'}},
'qux': {'transport': {'path': 'pysoa.test.stub_service:StubClientTransport'}},
})
action_request = EnrichedActionRequest(action='status', body={}, client=client)
baz_body = {
'conformity': '1.2.3',
'pysoa': '1.0.2',
'python': '3.7.4',
'version': '9.7.8',
}
with stub_action('foo', 'status') as foo_stub,\
stub_action('bar', 'status', errors=[Error('BAR_ERROR', 'Bar error')]),\
stub_action('baz', 'status', body=baz_body),\
stub_action('qux', 'status') as qux_stub:
foo_stub.return_value = JobResponse(errors=[Error('FOO_ERROR', 'Foo error')])
qux_stub.side_effect = MessageReceiveTimeout('Timeout calling qux')
response = _CheckOtherServicesAction()(action_request)
self.assertIsInstance(response, ActionResponse)
self.assertEqual(six.text_type(conformity.__version__), response.body['conformity'])
self.assertEqual(six.text_type(pysoa.__version__), response.body['pysoa'])
self.assertEqual(six.text_type(platform.python_version()), response.body['python'])
self.assertEqual('8.71.2', response.body['version'])
self.assertIn('healthcheck', response.body)
self.assertEqual([], response.body['healthcheck']['warnings'])
self.assertIn(
@stub_action('future_service', 'present_sounds', errors=[{'code': 'BROKEN', 'message': 'Broken, dude'}])
def test_call_actions_future_error(self, mock_present_sounds):
client = Client({})
future = client.call_actions_future(
'future_service',
[{'action': 'present_sounds', 'body': {'foo': 'bar'}}],
)
mock_present_sounds.assert_called_once_with({'foo': 'bar'})
with self.assertRaises(client.CallActionError) as error_context:
raise future.exception() # type: ignore
first_exception = error_context.exception
assert len(error_context.exception.actions[0].errors) == 1
@stub_action('employee_service', 'get_employees_by_ids')
@stub_action('company_service', 'get_all_companies')
def test_expand_company_ceo_and_reports(
self,
mock_get_companies,
mock_get_employees,
mock_get_reports,
mock_get_images,
):
mock_get_companies.return_value = {
'companies': [
{'_type': 'company_type', 'company_id': '9183', 'name': 'Acme', 'ceo_id': '5791'},
{'_type': 'company_type', 'company_id': '7261', 'name': 'Logo Makers', 'ceo_id': '51', 'logo_id': '65'},
],
}
mock_get_employees.return_value = {
@stub_action('image_service', 'get_images_by_ids')
@stub_action('employee_service', 'get_employees_by_ids')
@stub_action('company_service', 'get_all_companies')
def test_expand_company_ceo_and_logo(self, mock_get_companies, mock_get_employees, mock_get_images):
mock_get_companies.return_value = {
'companies': [
{'_type': 'company_type', 'company_id': '9183', 'name': 'Acme', 'ceo_id': '5791'},
{'_type': 'company_type', 'company_id': '7261', 'name': 'Logo Makers', 'ceo_id': '51', 'logo_id': '65'},
],
}
mock_get_employees.return_value = {
'employees': {
'5791': {'_type': 'employee_type', 'employee_id': '5791', 'name': 'Julia', 'photo_id': '37'},
'51': {'_type': 'employee_type', 'employee_id': '51', 'name': 'Nathan', 'photo_id': '79'},
},
}
@stub_action('future_service', 'present_sounds', body={'baz': 'qux'})
def test_call_actions_future_success(self, mock_present_sounds):
client = Client({})
future = client.call_actions_future(
'future_service',
[{'action': 'present_sounds', 'body': {'foo': 'bar'}}],
)
mock_present_sounds.assert_called_once_with({'foo': 'bar'})
assert future.exception() is None
response = future.result()
assert response.errors == []
assert response.actions[0].errors == []
},
},
}
expected_car_response = {
'car_obj': {
'_type': 'car_type',
'id': 5,
'automaker_id': 6,
'automaker_profile': {
'_type': 'auto_type',
'id': 6,
},
},
}
with stub_action('author_info_service', 'get_authors_by_ids', body={'authors_detail': {
2: {
'_type': 'author_type',
'id': 201838,
'things': 'stuff',
},
}}), \
stub_action('book_info_service', 'get_book', body={'book_obj': {
'_type': 'book_type',
'id': 10573,
'author_id': 2,
'publish_id': 3,
}}):
response = self.client.call_actions(
service_name='book_info_service',
actions=[
{