forked from dapr/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_crypto.py
More file actions
48 lines (38 loc) · 1.48 KB
/
test_crypto.py
File metadata and controls
48 lines (38 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from pathlib import Path
import pytest
REPO_ROOT = Path(__file__).resolve().parent.parent.parent
CRYPTO_DIR = REPO_ROOT / 'examples' / 'crypto'
EXPECTED_COMMON = [
'Running encrypt/decrypt operation on string',
'Decrypted the message, got 24 bytes',
'The secret is "passw0rd"',
'Running encrypt/decrypt operation on file',
'Wrote encrypted data to encrypted.out',
'Wrote decrypted data to decrypted.out.jpg',
]
@pytest.fixture()
def cleanup_crypto_outputs():
"""Clean up output files written by the crypto example on teardown.
Example RSA and AES keys are in ``examples/crypto/keys/``.
"""
yield
(CRYPTO_DIR / 'encrypted.out').unlink(missing_ok=True)
(CRYPTO_DIR / 'decrypted.out.jpg').unlink(missing_ok=True)
@pytest.mark.example_dir('crypto')
def test_crypto(dapr, cleanup_crypto_outputs):
output = dapr.run(
'--app-id crypto --resources-path ./components/ -- python3 crypto.py',
timeout=30,
)
assert 'Running gRPC client synchronous API' in output
for line in EXPECTED_COMMON:
assert line in output, f'Missing in output: {line}'
@pytest.mark.example_dir('crypto')
def test_crypto_async(dapr, cleanup_crypto_outputs):
output = dapr.run(
'--app-id crypto-async --resources-path ./components/ -- python3 crypto-async.py',
timeout=30,
)
assert 'Running gRPC client asynchronous API' in output
for line in EXPECTED_COMMON:
assert line in output, f'Missing in output: {line}'