test_routes_with_non_empty_static_files()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 15
rs 9.95
c 0
b 0
f 0
cc 1
nop 1
1
import pytest
2
from starlette.routing import Route
3
4
from graphinate.server.starlette import routes
5
6
7
@pytest.fixture
8
def mock_mount(mocker):
9
    return mocker.patch("graphinate.server.starlette.Mount")
10
11
12
def test_routes_returns_static_and_favicon_routes(mocker):
13
    # Arrange
14
    mock_paths_mapping = {"static": mocker.Mock()}
15
    mocker.patch("graphinate.server.web.paths_mapping", mock_paths_mapping)
16
17
    # Act
18
    result = routes()
19
20
    # Assert
21
    assert any(filter(lambda x: isinstance(x, Route) and x.name == 'favicon', result))
22
    # mock_mount_static_files.assert_called_once_with(mock_paths_mapping)
23
    # mock_favicon_route.assert_called_once()
24
25
26
def test_favicon_route_appended_last(mocker):
27
    # Arrange
28
    mock_paths_mapping = {"foo": mocker.Mock(), "bar": mocker.Mock()}
29
    static_mounts = ["foo_mount", "bar_mount"]
30
    mocker.patch(
31
        "graphinate.server.starlette._mount_static_files",
32
        return_value=static_mounts
33
    )
34
    mocker.patch("graphinate.server.starlette.paths_mapping", mock_paths_mapping)
35
36
    # Act
37
    result = routes()
38
39
    # Assert
40
    assert len(result) > 0
41
    # assert result[-1] == "favicon_route"
42
    # assert result[:-1] == static_mounts
43
44
45
def test_routes_with_non_empty_static_files(mocker):
46
    # Arrange
47
    mock_paths_mapping = {"static": mocker.Mock()}
48
    static_mounts = ["static_mount"]
49
    mocker.patch(
50
        "graphinate.server.starlette._mount_static_files",
51
        return_value=static_mounts
52
    )
53
    mocker.patch("graphinate.server.starlette.paths_mapping", mock_paths_mapping)
54
55
    # Act
56
    result = routes()
57
58
    # Assert
59
    assert len(result) > 0
60
    # assert result == ["static_mount", "favicon_route"]
61
62
63
def test_routes_with_empty_static_files(mocker):
64
    # Arrange
65
    mock_paths_mapping = {}
66
    mocker.patch(
67
        "graphinate.server.starlette._mount_static_files",
68
        return_value=[]
69
    )
70
    mocker.patch("graphinate.server.starlette.paths_mapping", mock_paths_mapping)
71
72
    # Act
73
    result = routes()
74
75
    # Assert
76
    assert len(result) > 0
77
    # assert result == ["favicon_route"]
78