| Total Complexity | 2 |
| Total Lines | 56 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import re |
||
|
|
|||
| 2 | import pytest |
||
| 3 | |||
| 4 | |||
| 5 | @pytest.fixture |
||
| 6 | def get_data(): |
||
| 7 | page_content = ''' |
||
| 8 | <!DOCTYPE html> |
||
| 9 | <html> |
||
| 10 | <head> |
||
| 11 | <!-- ... --> |
||
| 12 | </head> |
||
| 13 | <body> |
||
| 14 | <script> |
||
| 15 | window.init = { |
||
| 16 | "hosts": { |
||
| 17 | "host": "vk.com", |
||
| 18 | "api": "api.vk.com", |
||
| 19 | "id": "id.vk.com", |
||
| 20 | "login": "login.vk.com", |
||
| 21 | "oauth": "oauth.vk.com", |
||
| 22 | "domain": "vk.com" |
||
| 23 | }, |
||
| 24 | "auth": { |
||
| 25 | "access_token": "access_token_test_example", |
||
| 26 | "anonymous_token": "anonymous_token_test_example", |
||
| 27 | "host_app_id": 6102407, |
||
| 28 | "auth_app_id": 0, |
||
| 29 | "user_id": 0 |
||
| 30 | }, |
||
| 31 | "params": { |
||
| 32 | "debug": false, |
||
| 33 | "origin": "", |
||
| 34 | "localhost": false, |
||
| 35 | "vkui_scheme": "space_gray" |
||
| 36 | } |
||
| 37 | }; |
||
| 38 | </script> |
||
| 39 | </body> |
||
| 40 | </html> |
||
| 41 | ''' |
||
| 42 | |||
| 43 | # Define the regular expression pattern |
||
| 44 | pattern = r'"auth":\s*{\s*"(?:\w+|_\w+)"\s*:\s*"(.*?)",\s*"(?:\w+|_\w+)"' \ |
||
| 45 | r'\s*:\s*"(.*?)",\s*"(?:\w+|_\w+)"\s*:\s*([0-9]+),\s*"(?:\w+|_\w+)"\s*:\s*([0-9]+),' \ |
||
| 46 | r'\s*"(?:\w+|_\w+)"\s*:\s*([0-9]+)\s*}' |
||
| 47 | |||
| 48 | # Find all matches using the regular expression |
||
| 49 | matches = re.findall(pattern, page_content) |
||
| 50 | |||
| 51 | return matches[0] |
||
| 52 | |||
| 53 | |||
| 54 | def test_auth_regexp(get_data): |
||
| 55 | assert get_data == ('access_token_test_example', 'anonymous_token_test_example', '6102407', '0', '0') |
||
| 56 |