tests.test_auth_object_re   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 11
dl 0
loc 56
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A get_data() 0 47 1
A test_auth_regexp() 0 2 1
1
import re
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
import pytest
3
4
5
@pytest.fixture
6
def get_data():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
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):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Comprehensibility Bug introduced by
get_data is re-defining a name which is already available in the outer-scope (previously defined on line 6).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
55
    assert get_data == ('access_token_test_example', 'anonymous_token_test_example', '6102407', '0', '0')
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (105/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
56