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_get_secret(self):
dapr = DaprClient(f'localhost:{self.server_port}')
key1 = 'key_1'
resp = dapr.get_secret(
store_name='store_1',
key=key1,
metadata=(
('key1', 'value1'),
('key2', 'value2'),
),
)
self.assertEqual(1, len(resp.headers))
self.assertEqual(1, len(resp.trailers))
self.assertEqual([key1], resp.headers['keyh'])
self.assertEqual([key1], resp.trailers['keyt'])
self.assertEqual({key1: "val"}, resp._secret)
def test_invoke_binding_bytes_data(self):
dapr = DaprClient(f'localhost:{self.server_port}')
resp = dapr.invoke_binding(
name='binding',
operation='create',
data=b'haha',
metadata=(
('key1', 'value1'),
('key2', 'value2'),
),
)
self.assertEqual(b'haha', resp.content)
self.assertEqual({'key1': 'value1', 'key2': 'value2'}, resp.metadata)
self.assertEqual(2, len(resp.headers))
self.assertEqual(['value1'], resp.headers['hkey1'])
self.assertEqual(['value1'], resp.trailers['tkey1'])
def test_get_secret_metadata_absent(self):
dapr = DaprClient(f'localhost:{self.server_port}')
key1 = 'key_1'
resp = dapr.get_secret(
store_name='store_1',
key=key1,
)
self.assertEqual(1, len(resp.headers))
self.assertEqual(1, len(resp.trailers))
self.assertEqual([key1], resp.headers['keyh'])
self.assertEqual([key1], resp.trailers['keyt'])
self.assertEqual({key1: "val"}, resp._secret)
def test_invoke_binding_no_metadata(self):
dapr = DaprClient(f'localhost:{self.server_port}')
resp = dapr.invoke_binding(
name='binding',
operation='create',
data=b'haha',
)
self.assertEqual(b'haha', resp.content)
self.assertEqual({}, resp.metadata)
self.assertEqual(0, len(resp.headers))
self.assertEqual(0, len(resp.trailers))
def test_http_extension(self):
dapr = DaprClient(f'localhost:{self.server_port}')
# Test POST verb without querystring
ext = dapr._get_http_extension('POST')
self.assertEqual(common_v1.HTTPExtension.Verb.POST, ext.verb)
# Test Non-supported http verb
with self.assertRaises(ValueError):
ext = dapr._get_http_extension('')
# Test POST verb with querystring
qs = (
('query1', 'string1'),
('query2', 'string2'),
)
ext = dapr._get_http_extension('POST', qs)
def test_invoke_binding_no_create(self):
dapr = DaprClient(f'localhost:{self.server_port}')
resp = dapr.invoke_binding(
name='binding',
operation='delete',
data=b'haha',
)
self.assertEqual(b'INVALID', resp.content)
self.assertEqual({}, resp.metadata)
self.assertEqual(0, len(resp.headers))
self.assertEqual(0, len(resp.trailers))
def test_invoke_service_proto_data(self):
dapr = DaprClient(f'localhost:{self.server_port}')
req = common_v1.StateItem(key='test')
resp = dapr.invoke_service(
id='targetId',
method='proto',
data=req,
metadata=(
('key1', 'value1'),
('key2', 'value2'),
),
)
self.assertEqual(3, len(resp.headers))
self.assertEqual(['value1'], resp.headers['hkey1'])
self.assertEqual(['value1'], resp.trailers['tkey1'])
self.assertTrue(resp.is_proto())
def test_invoke_service_bytes_data(self):
dapr = DaprClient(f'localhost:{self.server_port}')
resp = dapr.invoke_service(
id='targetId',
method='bytes',
data=b'haha',
content_type="text/plain",
metadata=(
('key1', 'value1'),
('key2', 'value2'),
),
)
self.assertEqual(b'haha', resp.content)
self.assertEqual("text/plain", resp.content_type)
self.assertEqual(3, len(resp.headers))
self.assertEqual(['value1'], resp.headers['hkey1'])
self.assertEqual(['value1'], resp.trailers['tkey1'])
def test_publish_error(self):
dapr = DaprClient(f'localhost:{self.server_port}')
with self.assertRaisesRegex(ValueError, "invalid type for data "):
dapr.publish_event(
topic='example',
data=111,
)
def test_publish_event(self):
dapr = DaprClient(f'localhost:{self.server_port}')
resp = dapr.publish_event(
topic='example',
data=b'haha',
)
self.assertEqual(2, len(resp.headers))
self.assertEqual(2, len(resp.trailers))
self.assertEqual(['haha'], resp.headers['hdata'])
self.assertEqual(['example'], resp.trailers['ttopic'])