-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_local_response.py
More file actions
55 lines (41 loc) · 1.86 KB
/
test_local_response.py
File metadata and controls
55 lines (41 loc) · 1.86 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
49
50
51
52
53
54
55
from pathlib import Path
import pytest
from mindee.input import LocalResponse
from tests.api.test_async_response import ASYNC_DIR
@pytest.fixture
def dummy_secret_key():
return "ogNjY44MhvKPGTtVsI8zG82JqWQa68woYQH"
@pytest.fixture
def signature():
return "5ed1673e34421217a5dbfcad905ee62261a3dd66c442f3edd19302072bbf70d0"
@pytest.fixture
def file_path():
return Path(ASYNC_DIR / "get_completed_empty.json")
def test_valid_file_local_response(dummy_secret_key, signature, file_path):
with open(file_path, "rb") as file:
local_response = LocalResponse(file)
assert local_response._file is not None
assert not local_response.is_valid_hmac_signature(
dummy_secret_key, "invalid signature"
)
assert signature == local_response.get_hmac_signature(dummy_secret_key)
assert local_response.is_valid_hmac_signature(dummy_secret_key, signature)
def test_valid_path_local_response(dummy_secret_key, signature, file_path):
local_response = LocalResponse(file_path)
assert local_response._file is not None
assert not local_response.is_valid_hmac_signature(
dummy_secret_key, "invalid signature"
)
assert signature == local_response.get_hmac_signature(dummy_secret_key)
assert local_response.is_valid_hmac_signature(dummy_secret_key, signature)
def test_valid_bytes_local_response(dummy_secret_key, signature, file_path):
with open(file_path, "r") as f:
str_response = f.read().replace("\r", "").replace("\n", "")
file_bytes = str_response.encode("utf-8")
local_response = LocalResponse(file_bytes)
assert local_response._file is not None
assert not local_response.is_valid_hmac_signature(
dummy_secret_key, "invalid signature"
)
assert signature == local_response.get_hmac_signature(dummy_secret_key)
assert local_response.is_valid_hmac_signature(dummy_secret_key, signature)