Passed
Pull Request — master (#460)
by Aldo
05:49
created

tests.conftest.mock_hashing()   A

Complexity

Conditions 3

Size

Total Lines 9
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 8
nop 0
dl 0
loc 9
ccs 8
cts 8
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
"""Unit test fixtures."""
2
# pylint: disable=redefined-outer-name
3
4 1
from unittest import mock
5
6 1
import pytest
7 1
from httpx import AsyncClient
8
9 1
from kytos.core import Controller
10 1
from kytos.core.auth import Auth
11 1
from kytos.core.dead_letter import DeadLetter
12 1
from kytos.lib.helpers import get_controller_mock
13
14
15 1
@pytest.fixture
16 1
def controller() -> Controller:
17
    """Controller fixture."""
18 1
    yield get_controller_mock()
19
20
21 1
@pytest.fixture
22 1
def dead_letter(controller) -> DeadLetter:
23
    """DeadLetter fixture."""
24 1
    yield controller.dead_letter
25
26
27 1
@pytest.fixture
28 1
def api_client(controller) -> AsyncClient:
29
    """App test_client instance."""
30 1
    base_url = "http://127.0.0.1/api/"
31 1
    app = controller.api_server.app
32 1
    yield AsyncClient(app=app, base_url=base_url)
33
34
35 1
@pytest.fixture
36 1
def auth(controller) -> Auth:
37
    """Auth fixture."""
38 1
    auth = Auth(controller)
39 1
    controller.start_auth()
40 1
    yield auth
41
42
43 1
@pytest.fixture
44 1
def minimal_openapi_spec_dict():
45
    """Sample minimal openapi spec."""
46
    return {
47
        "openapi": "3.0.0",
48
        "info": {"title": "Minimal OpenAPI specification", "version": "0.1"},
49
        "paths": {
50
            "/status": {
51
                "get": {
52
                    "responses": {"default": {"description": "status"}}
53
                }
54
            }
55
        },
56
    }
57
58
59 1
@pytest.fixture(scope='session', autouse=True)
60 1
def mock_hashing():
61
    """Mock hasinh method from user.py"""
62 1
    def new_hashing(password: bytes, _hash) -> str:
63 1
        if password == b"password":
64 1
            return "some_hash"
65 1
        return "wrong_hash"
66 1
    with mock.patch("kytos.core.auth.hashing", wraps=new_hashing) as mock_all:
67
        yield mock_all
68