Skip to content

Commit

Permalink
Clean up auth fixtures, rename parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathangreen committed Aug 7, 2023
1 parent 366a52f commit 0f51c60
Show file tree
Hide file tree
Showing 13 changed files with 234 additions and 148 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ module = [
"core.settings.*",
"core.util.authentication_for_opds",
"core.util.cache",
"tests.fixtures.authenticator",
"tests.migration.*",
]
no_implicit_reexport = true
Expand Down
43 changes: 23 additions & 20 deletions tests/api/admin/controller/test_patron_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,21 @@
from api.sip import SIP2AuthenticationProvider
from core.integration.goals import Goals
from core.model import AdminRole, Library, get_one
from core.model.integration import (
IntegrationConfiguration,
IntegrationLibraryConfiguration,
)
from core.model.integration import IntegrationConfiguration
from core.util.problem_detail import ProblemDetail

if TYPE_CHECKING:
from tests.fixtures.api_admin import SettingsControllerFixture
from tests.fixtures.authenticator import AuthProviderFixture
from tests.fixtures.database import DatabaseTransactionFixture
from tests.fixtures.authenticator import (
MilleniumAuthIntegrationFixture,
SamlAuthIntegrationFixture,
SimpleAuthIntegrationFixture,
Sip2AuthIntegrationFixture,
)
from tests.fixtures.database import (
DatabaseTransactionFixture,
IntegrationLibraryConfigurationFixture,
)


@pytest.fixture
Expand Down Expand Up @@ -116,10 +121,8 @@ def test_patron_auth_services_get_with_simple_auth_service(
self,
settings_ctrl_fixture: SettingsControllerFixture,
db: DatabaseTransactionFixture,
create_simple_auth_integration: Callable[..., AuthProviderFixture],
create_integration_library_configuration: Callable[
..., IntegrationLibraryConfiguration
],
create_simple_auth_integration: SimpleAuthIntegrationFixture,
create_integration_library_configuration: IntegrationLibraryConfigurationFixture,
get_response: Callable[[], dict[str, Any] | ProblemDetail],
):
auth_service, _ = create_simple_auth_integration(
Expand Down Expand Up @@ -163,7 +166,7 @@ def test_patron_auth_services_get_with_millenium_auth_service(
self,
settings_ctrl_fixture: SettingsControllerFixture,
db: DatabaseTransactionFixture,
create_millenium_auth_integration: Callable[..., AuthProviderFixture],
create_millenium_auth_integration: MilleniumAuthIntegrationFixture,
get_response: Callable[[], dict[str, Any] | ProblemDetail],
):
auth_service, _ = create_millenium_auth_integration(
Expand Down Expand Up @@ -194,7 +197,7 @@ def test_patron_auth_services_get_with_sip2_auth_service(
self,
settings_ctrl_fixture: SettingsControllerFixture,
db: DatabaseTransactionFixture,
create_sip2_auth_integration: Callable[..., AuthProviderFixture],
create_sip2_auth_integration: Sip2AuthIntegrationFixture,
get_response: Callable[[], dict[str, Any] | ProblemDetail],
):
auth_service, _ = create_sip2_auth_integration(
Expand Down Expand Up @@ -229,7 +232,7 @@ def test_patron_auth_services_get_with_saml_auth_service(
self,
settings_ctrl_fixture: SettingsControllerFixture,
db: DatabaseTransactionFixture,
create_saml_auth_integration: Callable[..., AuthProviderFixture],
create_saml_auth_integration: SamlAuthIntegrationFixture,
get_response: Callable[[], dict[str, Any] | ProblemDetail],
):
auth_service, _ = create_saml_auth_integration(
Expand Down Expand Up @@ -284,7 +287,7 @@ def test_patron_auth_services_post_missing_service(
def test_patron_auth_services_post_cannot_change_protocol(
self,
post_response: Callable[..., Response | ProblemDetail],
create_simple_auth_integration: Callable[..., AuthProviderFixture],
create_simple_auth_integration: SimpleAuthIntegrationFixture,
):
auth_service, _ = create_simple_auth_integration()
form = ImmutableMultiDict(
Expand All @@ -299,7 +302,7 @@ def test_patron_auth_services_post_cannot_change_protocol(
def test_patron_auth_services_post_name_in_use(
self,
post_response: Callable[..., Response | ProblemDetail],
create_simple_auth_integration: Callable[..., AuthProviderFixture],
create_simple_auth_integration: SimpleAuthIntegrationFixture,
):
auth_service, _ = create_simple_auth_integration()
form = ImmutableMultiDict(
Expand All @@ -314,7 +317,7 @@ def test_patron_auth_services_post_name_in_use(
def test_patron_auth_services_post_invalid_configuration(
self,
post_response: Callable[..., Response | ProblemDetail],
create_millenium_auth_integration: Callable[..., AuthProviderFixture],
create_millenium_auth_integration: MilleniumAuthIntegrationFixture,
common_args: list[tuple[str, str]],
):
auth_service, _ = create_millenium_auth_integration()
Expand All @@ -336,7 +339,7 @@ def test_patron_auth_services_post_invalid_configuration(
def test_patron_auth_services_post_incomplete_configuration(
self,
post_response: Callable[..., Response | ProblemDetail],
create_simple_auth_integration: Callable[..., AuthProviderFixture],
create_simple_auth_integration: SimpleAuthIntegrationFixture,
common_args: list[tuple[str, str]],
):
auth_service, _ = create_simple_auth_integration()
Expand Down Expand Up @@ -385,7 +388,7 @@ def test_patron_auth_services_post_missing_patron_auth_no_such_library(
def test_patron_auth_services_post_missing_patron_auth_multiple_basic(
self,
post_response: Callable[..., Response | ProblemDetail],
create_simple_auth_integration: Callable[..., AuthProviderFixture],
create_simple_auth_integration: SimpleAuthIntegrationFixture,
default_library: Library,
common_args: list[tuple[str, str]],
):
Expand Down Expand Up @@ -544,7 +547,7 @@ def test_patron_auth_services_post_edit(
post_response: Callable[..., Response | ProblemDetail],
common_args: List[Tuple[str, str]],
settings_ctrl_fixture: SettingsControllerFixture,
create_simple_auth_integration: Callable[..., AuthProviderFixture],
create_simple_auth_integration: SimpleAuthIntegrationFixture,
db: DatabaseTransactionFixture,
monkeypatch: MonkeyPatch,
):
Expand Down Expand Up @@ -610,7 +613,7 @@ def test_patron_auth_service_delete(
self,
common_args: List[Tuple[str, str]],
settings_ctrl_fixture: SettingsControllerFixture,
create_simple_auth_integration: Callable[..., AuthProviderFixture],
create_simple_auth_integration: SimpleAuthIntegrationFixture,
):
controller = settings_ctrl_fixture.manager.admin_patron_auth_services_controller
db = settings_ctrl_fixture.ctrl.db
Expand Down
14 changes: 7 additions & 7 deletions tests/api/admin/controller/test_patron_auth_self_tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import json
from typing import TYPE_CHECKING, Callable
from typing import TYPE_CHECKING
from unittest.mock import MagicMock

import pytest
Expand All @@ -23,7 +23,7 @@
from _pytest.monkeypatch import MonkeyPatch
from flask.ctx import RequestContext

from tests.fixtures.authenticator import AuthProviderFixture
from tests.fixtures.authenticator import SimpleAuthIntegrationFixture
from tests.fixtures.database import DatabaseTransactionFixture


Expand Down Expand Up @@ -56,7 +56,7 @@ def test_patron_auth_self_tests_get_with_no_libraries(
self,
controller: PatronAuthServiceSelfTestsController,
get_request_context: RequestContext,
create_simple_auth_integration: Callable[..., AuthProviderFixture],
create_simple_auth_integration: SimpleAuthIntegrationFixture,
):
auth_service, _ = create_simple_auth_integration()
response_obj = controller.process_patron_auth_service_self_tests(
Expand All @@ -75,7 +75,7 @@ def test_patron_auth_self_tests_test_get_no_results(
self,
controller: PatronAuthServiceSelfTestsController,
get_request_context: RequestContext,
create_simple_auth_integration: Callable[..., AuthProviderFixture],
create_simple_auth_integration: SimpleAuthIntegrationFixture,
default_library: Library,
):
auth_service, _ = create_simple_auth_integration(library=default_library)
Expand All @@ -99,7 +99,7 @@ def test_patron_auth_self_tests_test_get(
self,
controller: PatronAuthServiceSelfTestsController,
get_request_context: RequestContext,
create_simple_auth_integration: Callable[..., AuthProviderFixture],
create_simple_auth_integration: SimpleAuthIntegrationFixture,
monkeypatch: MonkeyPatch,
default_library: Library,
):
Expand Down Expand Up @@ -136,7 +136,7 @@ def test_patron_auth_self_tests_post_with_no_libraries(
self,
controller: PatronAuthServiceSelfTestsController,
post_request_context: RequestContext,
create_simple_auth_integration: Callable[..., AuthProviderFixture],
create_simple_auth_integration: SimpleAuthIntegrationFixture,
):
auth_service, _ = create_simple_auth_integration()
response = controller.process_patron_auth_service_self_tests(auth_service.id)
Expand All @@ -149,7 +149,7 @@ def test_patron_auth_self_tests_test_post(
self,
controller: PatronAuthServiceSelfTestsController,
post_request_context: RequestContext,
create_simple_auth_integration: Callable[..., AuthProviderFixture],
create_simple_auth_integration: SimpleAuthIntegrationFixture,
monkeypatch: MonkeyPatch,
db: DatabaseTransactionFixture,
):
Expand Down
19 changes: 11 additions & 8 deletions tests/api/test_authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@

if TYPE_CHECKING:
from ..fixtures.api_controller import ControllerFixture
from ..fixtures.authenticator import AuthProviderFixture
from ..fixtures.authenticator import (
CreateAuthIntegrationFixture,
MilleniumAuthIntegrationFixture,
)
from ..fixtures.database import DatabaseTransactionFixture
from ..fixtures.vendor_id import VendorIDFixture

Expand Down Expand Up @@ -471,7 +474,7 @@ class TestAuthenticator:
def test_init(
self,
controller_fixture: ControllerFixture,
create_millenium_auth_integration: Callable[..., AuthProviderFixture],
create_millenium_auth_integration: MilleniumAuthIntegrationFixture,
):
db = controller_fixture.db

Expand Down Expand Up @@ -601,7 +604,7 @@ class TestLibraryAuthenticator:
def test_from_config_basic_auth_only(
self,
db: DatabaseTransactionFixture,
create_millenium_auth_integration: Callable[..., AuthProviderFixture],
create_millenium_auth_integration: MilleniumAuthIntegrationFixture,
):
# Only a basic auth provider.
create_millenium_auth_integration(db.default_library())
Expand Down Expand Up @@ -657,8 +660,8 @@ def test_config_succeeds_when_no_providers_configured(
def test_configuration_exception_during_from_config_stored(
self,
db: DatabaseTransactionFixture,
create_millenium_auth_integration: Callable[..., AuthProviderFixture],
create_auth_integration_configuration: Callable[..., AuthProviderFixture],
create_millenium_auth_integration: MilleniumAuthIntegrationFixture,
create_auth_integration_configuration: CreateAuthIntegrationFixture,
):
# If the initialization of an AuthenticationProvider from config
# raises CannotLoadConfiguration or ImportError, the exception
Expand Down Expand Up @@ -753,15 +756,15 @@ def __init__(self, *args, **kwargs):
def test_register_provider_basic_auth(
self,
db: DatabaseTransactionFixture,
create_auth_integration_configuration: Callable[..., AuthProviderFixture],
create_auth_integration_configuration: CreateAuthIntegrationFixture,
patron_auth_registry: PatronAuthRegistry,
):
library = db.default_library()
protocol = patron_auth_registry.get_protocol(SIP2AuthenticationProvider)
protocol = patron_auth_registry.get_protocol(SIP2AuthenticationProvider, "")
_, integration = create_auth_integration_configuration(
protocol,
library,
settings={
settings_dict={
"url": "http://url/",
"password": "secret",
},
Expand Down
6 changes: 3 additions & 3 deletions tests/api/test_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import ssl
import urllib
from functools import partial
from typing import TYPE_CHECKING, Callable
from typing import TYPE_CHECKING
from unittest.mock import MagicMock, Mock, PropertyMock

import pytest
Expand Down Expand Up @@ -68,7 +68,7 @@

if TYPE_CHECKING:
from ..fixtures.api_axis_files import AxisFilesFixture
from ..fixtures.authenticator import AuthProviderFixture
from ..fixtures.authenticator import SimpleAuthIntegrationFixture
from ..fixtures.database import DatabaseTransactionFixture


Expand Down Expand Up @@ -140,7 +140,7 @@ def test_external_integration(self, axis360: Axis360Fixture):
def test__run_self_tests(
self,
axis360: Axis360Fixture,
create_simple_auth_integration: Callable[..., AuthProviderFixture],
create_simple_auth_integration: SimpleAuthIntegrationFixture,
):
# Verify that Axis360API._run_self_tests() calls the right
# methods.
Expand Down
14 changes: 3 additions & 11 deletions tests/api/test_bibliotheca.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,7 @@
import random
from datetime import datetime, timedelta
from io import BytesIO, StringIO
from typing import (
TYPE_CHECKING,
Any,
Callable,
ClassVar,
Optional,
Protocol,
runtime_checkable,
)
from typing import TYPE_CHECKING, Any, ClassVar, Optional, Protocol, runtime_checkable
from unittest import mock
from unittest.mock import MagicMock

Expand Down Expand Up @@ -77,7 +69,7 @@

if TYPE_CHECKING:
from tests.fixtures.api_bibliotheca_files import BibliothecaFilesFixture
from tests.fixtures.authenticator import AuthProviderFixture
from tests.fixtures.authenticator import SimpleAuthIntegrationFixture
from tests.fixtures.database import DatabaseTransactionFixture
from tests.fixtures.time import Time

Expand Down Expand Up @@ -110,7 +102,7 @@ def test_external_integration(self, bibliotheca_fixture: BibliothecaAPITestFixtu
def test__run_self_tests(
self,
bibliotheca_fixture: BibliothecaAPITestFixture,
create_simple_auth_integration: Callable[..., AuthProviderFixture],
create_simple_auth_integration: SimpleAuthIntegrationFixture,
):
db = bibliotheca_fixture.db
# Verify that BibliothecaAPI._run_self_tests() calls the right
Expand Down
6 changes: 3 additions & 3 deletions tests/api/test_enki.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import datetime
import json
from typing import TYPE_CHECKING, Callable
from typing import TYPE_CHECKING

import pytest

Expand Down Expand Up @@ -31,7 +31,7 @@

if TYPE_CHECKING:
from tests.fixtures.api_enki_files import EnkiFilesFixture
from tests.fixtures.authenticator import AuthProviderFixture
from tests.fixtures.authenticator import SimpleAuthIntegrationFixture


class EnkiTestFixure:
Expand Down Expand Up @@ -96,7 +96,7 @@ def test_collection(self, enki_test_fixture: EnkiTestFixure):
def test__run_self_tests(
self,
enki_test_fixture: EnkiTestFixure,
create_simple_auth_integration: Callable[..., AuthProviderFixture],
create_simple_auth_integration: SimpleAuthIntegrationFixture,
):
db = enki_test_fixture.db

Expand Down
6 changes: 3 additions & 3 deletions tests/api/test_odilo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import json
from typing import TYPE_CHECKING, Callable
from typing import TYPE_CHECKING

import pytest

Expand Down Expand Up @@ -32,7 +32,7 @@

if TYPE_CHECKING:
from ..fixtures.api_odilo_files import OdiloFilesFixture
from ..fixtures.authenticator import AuthProviderFixture
from ..fixtures.authenticator import SimpleAuthIntegrationFixture
from ..fixtures.database import DatabaseTransactionFixture


Expand Down Expand Up @@ -226,7 +226,7 @@ def test_external_integration(self, odilo: OdiloFixture):
def test__run_self_tests(
self,
odilo: OdiloFixture,
create_simple_auth_integration: Callable[..., AuthProviderFixture],
create_simple_auth_integration: SimpleAuthIntegrationFixture,
):
"""Verify that OdiloAPI._run_self_tests() calls the right
methods.
Expand Down
Loading

0 comments on commit 0f51c60

Please sign in to comment.