|
2 | 2 | import json
|
3 | 3 |
|
4 | 4 |
|
5 |
| -def test_bo_to_small_tc_error_with_pair(): |
6 |
| - file_path = 'test/sample_data/errors/bo_too_small_with_pair.json' |
| 5 | +def read_error(file_path) -> ThreeCommasError: |
7 | 6 | with open(file_path, 'r+') as f:
|
8 | 7 | error = json.loads(f.read())
|
9 | 8 | error_model = ThreeCommasError(error)
|
| 9 | + return error_model |
| 10 | + |
10 | 11 |
|
11 |
| - bo_error = error_model.bo_to_small_error() |
12 |
| - assert len(bo_error) == 1 |
13 |
| - assert bo_error[0].amount == 33.35 |
14 |
| - assert bo_error[0].pair == 'USDT_YFI' |
| 12 | +def test_bo_to_small_tc_error_with_pair(): |
| 13 | + error = read_error('test/sample_data/errors/bo_too_small_with_pair.json') |
| 14 | + |
| 15 | + assert error.is_bo_to_small_error() |
| 16 | + bo_error = error.get_bo_to_small_error() |
| 17 | + assert len(bo_error) == 1 |
| 18 | + assert bo_error[0].amount == 33.35 |
| 19 | + assert bo_error[0].pair == 'USDT_YFI' |
15 | 20 |
|
16 | 21 |
|
17 | 22 | def test_multiple_bo_error():
|
18 |
| - file_path = 'test/sample_data/errors/multiple_bo_so_errors.json' |
19 |
| - with open(file_path, 'r+') as f: |
20 |
| - error = json.loads(f.read()) |
21 |
| - error_model = ThreeCommasError(error) |
| 23 | + error = read_error('test/sample_data/errors/multiple_bo_so_errors.json') |
22 | 24 |
|
23 |
| - bo_error = error_model.bo_to_small_error() |
24 |
| - assert len(bo_error) == 4 |
25 |
| - assert set(map(lambda be: be.pair, bo_error)) == {'USDT_1INCH', 'USDT_AAVE', 'USDT_ACM', 'USDT_ADA'} |
26 |
| - assert list(map(lambda be: be.amount, bo_error)) == [10.0, 10.0, 10.0, 10.0] |
| 25 | + bo_error = error.get_bo_to_small_error() |
| 26 | + assert len(bo_error) == 4 |
| 27 | + assert set(map(lambda be: be.pair, bo_error)) == {'USDT_1INCH', 'USDT_AAVE', 'USDT_ACM', 'USDT_ADA'} |
| 28 | + assert list(map(lambda be: be.amount, bo_error)) == [10.0, 10.0, 10.0, 10.0] |
27 | 29 |
|
28 | 30 |
|
29 | 31 | def test_bo_to_small_tc_error_no_pair():
|
30 |
| - file_path = 'test/sample_data/errors/bo_too_small_no_pair.json' |
31 |
| - with open(file_path, 'r+') as f: |
32 |
| - error = json.loads(f.read()) |
33 |
| - error_model = ThreeCommasError(error) |
| 32 | + error = read_error('test/sample_data/errors/bo_too_small_no_pair.json') |
34 | 33 |
|
35 |
| - bo_error = error_model.bo_to_small_error() |
36 |
| - assert bo_error[0].amount == 9.4674 |
37 |
| - assert not bo_error[0].pair |
| 34 | + bo_error = error.get_bo_to_small_error() |
| 35 | + assert bo_error[0].amount == 9.4674 |
| 36 | + assert not bo_error[0].pair |
38 | 37 |
|
39 | 38 |
|
40 | 39 | def test_no_bo_error():
|
41 |
| - file_path = 'test/sample_data/errors/signature_invalid.json' |
42 |
| - with open(file_path, 'r+') as f: |
43 |
| - error = json.loads(f.read()) |
44 |
| - error_model = ThreeCommasError(error) |
| 40 | + error = read_error('test/sample_data/errors/signature_invalid.json') |
45 | 41 |
|
46 |
| - bo_error = error_model.bo_to_small_error() |
47 |
| - assert len(bo_error) == 0 |
| 42 | + bo_error = error.get_bo_to_small_error() |
| 43 | + assert len(bo_error) == 0 |
| 44 | + assert not error.is_bo_to_small_error() |
48 | 45 |
|
49 |
| - error_model = ThreeCommasError({'custom_message': 'some error occured'}) |
50 |
| - bo_error = error_model.bo_to_small_error() |
| 46 | + error = ThreeCommasError({'custom_message': 'some error occured'}) |
| 47 | + bo_error = error.get_bo_to_small_error() |
51 | 48 | assert len(bo_error) == 0
|
| 49 | + |
| 50 | + |
| 51 | +def test_api_key_invalid_or_expired(): |
| 52 | + error = read_error('test/sample_data/errors/api_key_invalid_or_expired_error.json') |
| 53 | + assert error.is_api_key_invalid_or_expired() |
| 54 | + |
| 55 | + |
| 56 | +def test_api_key_has_no_permission_error(): |
| 57 | + error = read_error('test/sample_data/errors/api_key_has_no_permission_error.json') |
| 58 | + assert error.is_api_key_has_no_permission_error() |
| 59 | + |
0 commit comments