-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
82 lines (65 loc) · 2.24 KB
/
Copy pathconftest.py
File metadata and controls
82 lines (65 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""Shared fixtures for qbo-cli tests."""
from __future__ import annotations
import argparse
import json
from pathlib import Path
from unittest.mock import MagicMock
import pytest
from qbo_cli.auth import TokenManager
from qbo_cli.client import QBOClient
from qbo_cli.config import Config
FIXTURES_DIR = Path(__file__).parent / "fixtures"
@pytest.fixture
def gl_fixture():
"""Loaded GL report JSON fixture."""
return json.loads((FIXTURES_DIR / "gl_report_nested.json").read_text())
@pytest.fixture
def customers_fixture():
"""Loaded customer query JSON fixture."""
return json.loads((FIXTURES_DIR / "query_customers.json").read_text())
@pytest.fixture
def fake_config():
"""Config object without disk IO."""
cfg = Config.__new__(Config)
cfg.profile = "prod"
cfg.client_id = "test-client-id"
cfg.client_secret = "test-client-secret"
cfg.redirect_uri = "http://localhost:8844/callback"
cfg.realm_id = "1234567890"
cfg.sandbox = False
return cfg
@pytest.fixture
def fake_token_mgr(fake_config):
"""TokenManager with mocked get_valid_token."""
mgr = TokenManager.__new__(TokenManager)
mgr.config = fake_config
mgr._tokens = {
"access_token": "fake-access-token",
"refresh_token": "fake-refresh-token",
"expires_at": 9999999999,
"refresh_expires_at": 9999999999,
"realm_id": "1234567890",
}
mgr.get_valid_token = MagicMock(return_value="fake-access-token") # type: ignore[method-assign]
mgr.load = MagicMock(return_value=mgr._tokens) # type: ignore[method-assign]
return mgr
@pytest.fixture
def mock_client(fake_config, fake_token_mgr):
"""QBOClient with mocked request method."""
client = QBOClient(fake_config, fake_token_mgr)
client.request = MagicMock() # type: ignore[method-assign]
return client
def make_args(**overrides) -> argparse.Namespace:
"""Factory for argparse.Namespace with sensible defaults."""
defaults = {
"command": "query",
"format": "text",
"profile": None,
"sandbox": False,
"output": None,
"sql": "SELECT * FROM Customer",
"max_pages": 100,
"list_reports": False,
}
defaults.update(overrides)
return argparse.Namespace(**defaults)