Conditions | 8 |
Total Lines | 28 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Tests | 17 |
CRAP Score | 8.0747 |
Changes | 0 |
1 | #!/usr/bin/python |
||
16 | 1 | def verify_status_code(request_response: requests.Response, file_name: str) -> tuple: |
|
17 | """Verify the status code of the post request to the search url and raise exceptions if the code is unexpected |
||
18 | |||
19 | :type request_response: requests.Response |
||
20 | :type file_name: str |
||
21 | :return: |
||
22 | """ |
||
23 | 1 | if request_response.status_code == 200: |
|
24 | 1 | return STATUS_CODE_OK, '' |
|
25 | |||
26 | 1 | elif request_response.status_code == 429: |
|
27 | 1 | if 'Search Rate Too High.' in request_response.text: |
|
28 | msg = "Search rate limit reached" |
||
29 | return STATUS_CODE_REPEAT, msg |
||
30 | 1 | if 'limit of 150 searches' in request_response.text: |
|
31 | 1 | raise DailyLimitReachedException('Daily search limit for unregistered users reached') |
|
32 | 1 | elif 'limit of 300 searches' in request_response.text: |
|
33 | 1 | raise DailyLimitReachedException('Daily search limit for basic users reached') |
|
34 | else: |
||
35 | 1 | raise DailyLimitReachedException('Daily search limit reached') |
|
36 | 1 | elif request_response.status_code == 403: |
|
37 | 1 | raise InvalidOrWrongApiKeyException("Invalid or wrong API key") |
|
38 | 1 | elif request_response.status_code == 413: |
|
39 | 1 | msg = "Payload too large, skipping file: {0:s}".format(file_name) |
|
40 | 1 | return STATUS_CODE_SKIP, msg |
|
41 | else: |
||
42 | 1 | msg = "Unknown status code: {0:d}".format(request_response.status_code) |
|
43 | return STATUS_CODE_REPEAT, msg |
||
44 |