Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_register_device_api_endpoints(self):
app = klein.Klein()
auth = DummyAuthProvider()
result = ['foobar']
with mock.patch('stethoscope.plugins.utils.instantiate_plugins') as \
mock_instantiate_plugins:
mock_instantiate_plugins.return_value = stevedore.ExtensionManager.make_test_instance(
[get_mock_ext(result)])
stethoscope.api.endpoints.devices.register_device_api_endpoints(app, config, auth)
# see klein's test_app.py
self.assertEqual(
app.url_map.bind('devices-foo-email').match("/devices/foo/email/user@example.com"),
('devices-foo-email', {'email': "user@example.com"})
)
self.assertEqual(
app.url_map.bind('devices-foo-macaddr').match("/devices/foo/macaddr/de:ca:fb:ad:00:00"),
('devices-foo-macaddr', {'macaddr': "de:ca:fb:ad:00:00"}))
self.assertEqual(app.url_map.bind('devices-foo-serial').match("/devices/foo/serial/0xDEADBEEF"),
('devices-foo-serial', {'serial': "0xDEADBEEF"}))
self.assertEqual(app.url_map.bind('devices-email').match("/devices/email/user@example.com"),
('devices-email', {'email': "user@example.com"}))
def test_register_event_api_endpoints(self):
app = klein.Klein()
auth = DummyAuthProvider()
result_foo = [{'timestamp': 0}]
result_bar = [{'timestamp': 1}]
mock_hook = mock.Mock()
mock_hook.obj.transform.side_effect = lambda x: x
mock_hook_manager = stevedore.ExtensionManager.make_test_instance([mock_hook])
mock_extension_manager = stevedore.ExtensionManager.make_test_instance(
[get_mock_ext(result_foo, 'foo'), get_mock_ext(result_bar, 'bar')])
with mock.patch('stethoscope.plugins.utils.instantiate_plugins') as \
mock_instantiate_plugins:
mock_instantiate_plugins.side_effect = [mock_extension_manager, mock_hook_manager]
stethoscope.api.endpoints.events.register_event_api_endpoints(app, config, auth)
# see klein's test_app.py
self.assertEqual(
app.url_map.bind('events-foo-email').match("/events/foo/email/user@example.com"),
('events-foo-email', {'email': "user@example.com"})
)
self.assertEqual(
app.url_map.bind('events-bar-email').match("/events/bar/email/user@example.com"),
('events-bar-email', {'email': "user@example.com"})
def test_register_notification_api_endpoints(self):
app = klein.Klein()
auth = DummyAuthProvider()
result_foo = [{'_source': {'event_timestamp': 0}}]
result_bar = [{'_source': {'event_timestamp': 1}}]
mock_hook = mock.Mock()
mock_hook.obj.transform.side_effect = lambda x: x
mock_hook_manager = stevedore.ExtensionManager.make_test_instance([mock_hook])
mock_extension_manager = stevedore.ExtensionManager.make_test_instance(
[get_mock_ext(result_foo, 'foo'), get_mock_ext(result_bar, 'bar')])
with mock.patch('stethoscope.plugins.utils.instantiate_plugins') as \
mock_instantiate_plugins:
mock_instantiate_plugins.side_effect = [mock_extension_manager, mock_hook_manager]
stethoscope.api.endpoints.notifications.register_notification_api_endpoints(app, config, auth)
# see klein's test_app.py
adapter_foo = app.url_map.bind('notifications-foo-email')
self.assertEqual(
adapter_foo.match("/notifications/foo/email/user@example.com"),
('notifications-foo-email', {'email': "user@example.com"})
)
adapter_bar = app.url_map.bind('notifications-bar-email')
self.assertEqual(
def test_register_notification_api_endpoints(self):
app = klein.Klein()
auth = DummyAuthProvider()
result_foo = [{'_source': {'event_timestamp': 0}}]
result_bar = [{'_source': {'event_timestamp': 1}}]
mock_hook = mock.Mock()
mock_hook.obj.transform.side_effect = lambda x: x
mock_hook_manager = stevedore.ExtensionManager.make_test_instance([mock_hook])
mock_extension_manager = stevedore.ExtensionManager.make_test_instance(
[get_mock_ext(result_foo, 'foo'), get_mock_ext(result_bar, 'bar')])
with mock.patch('stethoscope.plugins.utils.instantiate_plugins') as \
mock_instantiate_plugins:
mock_instantiate_plugins.side_effect = [mock_extension_manager, mock_hook_manager]
stethoscope.api.endpoints.notifications.register_notification_api_endpoints(app, config, auth)
# see klein's test_app.py
adapter_foo = app.url_map.bind('notifications-foo-email')
self.assertEqual(
adapter_foo.match("/notifications/foo/email/user@example.com"),
('notifications-foo-email', {'email': "user@example.com"})
)
adapter_bar = app.url_map.bind('notifications-bar-email')
def test_register_userinfo_api_endpoints(self):
app = klein.Klein()
auth = DummyAuthProvider()
result = ['foobar']
with mock.patch('stethoscope.plugins.utils.instantiate_plugins') as \
mock_instantiate_plugins:
mock_instantiate_plugins.return_value = stevedore.ExtensionManager.make_test_instance(
[get_mock_ext(result)])
stethoscope.api.endpoints.userinfo.register_userinfo_api_endpoints(app, config, auth)
# see klein's test_app.py
self.assertEqual(
app.url_map.bind('userinfo-foo-email').match("/userinfo/foo/email/user@example.com"),
('userinfo-foo-email', {'email': "user@example.com"})
)
self.assertEqual(len(app.endpoints), 1)
self.check_result(app, b'/userinfo/foo/email/user@example.com', result)
def test_register_account_api_endpoints(self):
app = klein.Klein()
auth = DummyAuthProvider()
result = ['foobar']
with mock.patch('stethoscope.plugins.utils.instantiate_plugins') as \
mock_instantiate_plugins:
mock_instantiate_plugins.return_value = stevedore.ExtensionManager.make_test_instance(
[get_mock_ext(result)])
stethoscope.api.endpoints.accounts.register_account_api_endpoints(app, config, auth)
# see klein's test_app.py
self.assertEqual(
app.url_map.bind('account-foo-email').match("/account/foo/email/user@example.com"),
('account-foo-email', {'email': "user@example.com"})
)
self.assertEqual(
app.url_map.bind('accounts-merged').match("/accounts/merged/user@example.com"),
('accounts-merged', {'email': "user@example.com"})
)
self.assertEqual(len(app.endpoints), 2)
self.check_result(app, b'/account/foo/email/user@example.com', result)
self.check_result(app, b'/accounts/merged/user@example.com', [result])
def test_register_event_api_endpoints(self):
app = klein.Klein()
auth = DummyAuthProvider()
result_foo = [{'timestamp': 0}]
result_bar = [{'timestamp': 1}]
mock_hook = mock.Mock()
mock_hook.obj.transform.side_effect = lambda x: x
mock_hook_manager = stevedore.ExtensionManager.make_test_instance([mock_hook])
mock_extension_manager = stevedore.ExtensionManager.make_test_instance(
[get_mock_ext(result_foo, 'foo'), get_mock_ext(result_bar, 'bar')])
with mock.patch('stethoscope.plugins.utils.instantiate_plugins') as \
mock_instantiate_plugins:
mock_instantiate_plugins.side_effect = [mock_extension_manager, mock_hook_manager]
stethoscope.api.endpoints.events.register_event_api_endpoints(app, config, auth)
# see klein's test_app.py
self.assertEqual(
app.url_map.bind('events-foo-email').match("/events/foo/email/user@example.com"),
('events-foo-email', {'email': "user@example.com"})
)
self.assertEqual(
app.url_map.bind('events-bar-email').match("/events/bar/email/user@example.com"),
('events-bar-email', {'email': "user@example.com"})
)