|
7 | 7 |
|
8 | 8 |
|
9 | 9 | @pytest.fixture |
10 | | -def dummy_secret_key(): |
11 | | - return "ogNjY44MhvKPGTtVsI8zG82JqWQa68woYQH" |
| 10 | +def file_path() -> Path: |
| 11 | + return ASYNC_DIR / "get_completed_empty.json" |
12 | 12 |
|
13 | 13 |
|
14 | | -@pytest.fixture |
15 | | -def signature(): |
16 | | - return "5ed1673e34421217a5dbfcad905ee62261a3dd66c442f3edd19302072bbf70d0" |
17 | | - |
18 | | - |
19 | | -@pytest.fixture |
20 | | -def file_path(): |
21 | | - return Path(ASYNC_DIR / "get_completed_empty.json") |
| 14 | +def _assert_local_response(local_response): |
| 15 | + fake_hmac_signing = "ogNjY44MhvKPGTtVsI8zG82JqWQa68woYQH" |
| 16 | + signature = "5ed1673e34421217a5dbfcad905ee62261a3dd66c442f3edd19302072bbf70d0" |
| 17 | + assert local_response._file is not None |
| 18 | + assert not local_response.is_valid_hmac_signature( |
| 19 | + fake_hmac_signing, "invalid signature" |
| 20 | + ) |
| 21 | + assert signature == local_response.get_hmac_signature(fake_hmac_signing) |
| 22 | + assert local_response.is_valid_hmac_signature(fake_hmac_signing, signature) |
22 | 23 |
|
23 | 24 |
|
24 | | -def test_valid_file_local_response(dummy_secret_key, signature, file_path): |
| 25 | +def test_valid_file_local_response(file_path): |
25 | 26 | with open(file_path, "rb") as file: |
26 | 27 | local_response = LocalResponse(file) |
27 | | - assert local_response._file is not None |
28 | | - assert not local_response.is_valid_hmac_signature( |
29 | | - dummy_secret_key, "invalid signature" |
30 | | - ) |
31 | | - assert signature == local_response.get_hmac_signature(dummy_secret_key) |
32 | | - assert local_response.is_valid_hmac_signature(dummy_secret_key, signature) |
| 28 | + _assert_local_response(local_response) |
33 | 29 |
|
34 | 30 |
|
35 | | -def test_valid_path_local_response(dummy_secret_key, signature, file_path): |
| 31 | +def test_valid_path_local_response(file_path): |
36 | 32 | local_response = LocalResponse(file_path) |
37 | 33 | assert local_response._file is not None |
38 | | - assert not local_response.is_valid_hmac_signature( |
39 | | - dummy_secret_key, "invalid signature" |
40 | | - ) |
41 | | - assert signature == local_response.get_hmac_signature(dummy_secret_key) |
42 | | - assert local_response.is_valid_hmac_signature(dummy_secret_key, signature) |
| 34 | + _assert_local_response(local_response) |
43 | 35 |
|
44 | 36 |
|
45 | | -def test_valid_bytes_local_response(dummy_secret_key, signature, file_path): |
| 37 | +def test_valid_bytes_local_response(file_path): |
46 | 38 | with open(file_path, "r") as f: |
47 | 39 | str_response = f.read().replace("\r", "").replace("\n", "") |
48 | 40 | file_bytes = str_response.encode("utf-8") |
49 | 41 | local_response = LocalResponse(file_bytes) |
50 | | - assert local_response._file is not None |
51 | | - assert not local_response.is_valid_hmac_signature( |
52 | | - dummy_secret_key, "invalid signature" |
53 | | - ) |
54 | | - assert signature == local_response.get_hmac_signature(dummy_secret_key) |
55 | | - assert local_response.is_valid_hmac_signature(dummy_secret_key, signature) |
| 42 | + _assert_local_response(local_response) |
0 commit comments