Skip to content

Commit 059ce2d

Browse files
committed
refactor
1 parent 62d7fde commit 059ce2d

File tree

4 files changed

+20
-40
lines changed

4 files changed

+20
-40
lines changed

tests/conftest.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
"""Pytest entry point."""
2-
import pytest # noqa: I001
2+
import pytest
33

44
from starlette.config import environ
55

66
environ["TESTING"] = "True"
77
environ["ELASTICSEARCH_HOST"] = "http://localhost:9202"
88
environ["CONSOLE_LOG_LEVEL"] = "DEBUG"
9+
environ["AUTH_JWT_PUBKEY_PATH"] = "assets/testing/pubkey.pem"
910

10-
from . import common_data, utils # nopep8 # noqa: E402, F401
11+
from . import common_data, utils
1112

1213

1314
@pytest.fixture
14-
def json_schema_config(): # noqa: ANN201
15+
def json_schema_config():
1516
return common_data.CONFIG_PLACES

tests/e2e/conftest.py

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,13 @@ def as_header(self) -> typing.Dict[str, str]:
3333

3434

3535
@pytest.fixture(scope="session")
36-
def setup_environment() -> None:
37-
os.environ["AUTH_JWT_PUBKEY_PATH"] = "assets/testing/pubkey.pem"
38-
39-
40-
@pytest.fixture(scope="session")
41-
def apply_migrations(setup_environment: None): # noqa: ANN201
36+
def apply_migrations():
4237
from karp.main.migrations import use_cases
4338

4439
use_cases.run_migrations_up()
4540
yield
4641

4742

48-
@pytest.fixture(scope="session", name="runner")
49-
def fixture_runner() -> CliRunner:
50-
return CliRunner()
51-
52-
53-
@pytest.fixture(scope="session", name="cliapp")
54-
def fixture_cliapp() -> Typer:
55-
from karp.cliapp.main import create_app
56-
57-
return create_app()
58-
59-
6043
@pytest.fixture(name="app", scope="session")
6144
def fixture_app(
6245
apply_migrations: None, init_search_service: None
@@ -129,8 +112,8 @@ def fixture_fa_data_client( # noqa: ANN201
129112

130113

131114
def create_bearer_token(
132-
user: str,
133-
scope: Optional[typing.Dict] = None,
115+
scope: typing.Dict,
116+
user: Optional[str] = "abc123",
134117
) -> AccessToken:
135118
levels = auth_levels
136119
return AccessToken(
@@ -165,7 +148,6 @@ def user2_token() -> AccessToken:
165148
@pytest.fixture(scope="session")
166149
def user4_token() -> AccessToken:
167150
return create_bearer_token(
168-
user="user4",
169151
scope={
170152
"lexica": {
171153
"places": auth_levels[auth.PermissionLevel.admin],
@@ -177,7 +159,6 @@ def user4_token() -> AccessToken:
177159
@pytest.fixture(scope="session")
178160
def admin_token() -> AccessToken:
179161
return create_bearer_token(
180-
181162
scope={
182163
"lexica": {
183164
"places": auth_levels[auth.PermissionLevel.admin],
@@ -191,7 +172,6 @@ def admin_token() -> AccessToken:
191172
@pytest.fixture(scope="session")
192173
def read_token() -> AccessToken:
193174
return create_bearer_token(
194-
195175
scope={
196176
"lexica": {
197177
"places": auth_levels[auth.PermissionLevel.read],
@@ -205,7 +185,6 @@ def read_token() -> AccessToken:
205185
@pytest.fixture(scope="session")
206186
def write_token() -> AccessToken:
207187
return create_bearer_token(
208-
209188
scope={
210189
"lexica": {
211190
"places": auth_levels[auth.PermissionLevel.write],
@@ -219,7 +198,6 @@ def write_token() -> AccessToken:
219198
@pytest.fixture(scope="session")
220199
def no_municipalities_token() -> AccessToken:
221200
return create_bearer_token(
222-
223201
scope={"lexica": {}},
224202
)
225203

tests/e2e/test_cliapp_main.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
from karp.main import config
2-
from typer import Typer
32
from typer.testing import CliRunner
3+
from karp.cliapp.main import create_app
4+
5+
runner = CliRunner()
6+
cliapp = create_app()
47

58

69
class TestCli:
7-
def test_version(self, runner: CliRunner, cliapp: Typer): # noqa: ANN201
10+
def test_version(self):
811
result = runner.invoke(cliapp, ["--version"])
912
assert result.exit_code == 0
1013
assert f"{config.PROJECT_NAME} CLI {config.VERSION}\n" == result.stdout

tests/e2e/test_cliapp_resources.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
import pytest # noqa: I001
2-
3-
from typer import Typer
41
from typer.testing import CliRunner
5-
from karp import lex
62
from karp.lex.application import ResourceQueries
73

84
from karp.main import AppContext
5+
from karp.cliapp.main import create_app
6+
7+
runner = CliRunner()
8+
cliapp = create_app()
99

1010

1111
class TestCliResourceLifetime:
12-
def test_help(self, runner: CliRunner, cliapp: Typer): # noqa: ANN201
12+
def test_help(self):
1313
result = runner.invoke(cliapp, ["resource", "--help"])
1414
assert result.exit_code == 0
1515

16-
def test_create_and_publish_repo( # noqa: ANN201
16+
def test_create_and_publish_repo(
1717
self,
18-
runner: CliRunner,
19-
cliapp: Typer,
2018
app_context: AppContext,
2119
):
2220
result = runner.invoke(
@@ -27,11 +25,11 @@ def test_create_and_publish_repo( # noqa: ANN201
2725
"assets/testing/config/lexlex.json",
2826
],
2927
)
30-
# print(f"{result.stdout=}")
28+
3129
if isinstance(result.exception, Exception):
3230
raise result.exception
3331
else:
3432
assert result.exit_code == 0
3533

36-
resource_queries = app_context.injector.get(ResourceQueries) # type: ignore [misc]
34+
resource_queries = app_context.injector.get(ResourceQueries)
3735
assert resource_queries.by_resource_id_optional("lexlex") is not None

0 commit comments

Comments
 (0)