Skip to content
This repository has been archived by the owner on Dec 27, 2024. It is now read-only.

Commit

Permalink
FSPT-189: Update import paths and test mock paths
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcUsher committed Dec 16, 2024
1 parent 3bea0f5 commit 2f2e620
Show file tree
Hide file tree
Showing 19 changed files with 78 additions and 76 deletions.
6 changes: 3 additions & 3 deletions authenticator/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from api.magic_links.routes import MagicLinksView # noqa
from api.session.auth_session import AuthSessionUserView, AuthSessionSignOutView # noqa
from api.sso.routes import SsoLoginView, SsoLogoutView, SsoGraphCallView, SsoGetTokenView # noqa
from authenticator.api.magic_links.routes import MagicLinksView # noqa
from authenticator.api.session.auth_session import AuthSessionUserView, AuthSessionSignOutView # noqa
from authenticator.api.sso.routes import SsoLoginView, SsoLogoutView, SsoGraphCallView, SsoGetTokenView # noqa
2 changes: 1 addition & 1 deletion authenticator/api/magic_links/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from models.account import AccountMethods
from models.magic_link import MagicLinkMethods

from api.session.auth_session import AuthSessionBase
from authenticator.api.session.auth_session import AuthSessionBase
from common.blueprints import Blueprint
from config import Config

Expand Down
10 changes: 5 additions & 5 deletions authenticator/api/session/auth_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
from flask import current_app, make_response, redirect, request, session, url_for
from flask.views import MethodView
from fsd_utils import clear_sentry
from models.magic_link import MagicLinkMethods
from security.utils import create_token, decode_with_options, validate_token

from api.responses import error_response
from api.session.exceptions import SessionCreateError
from authenticator.api.responses import error_response
from authenticator.api.session.exceptions import SessionCreateError
from authenticator.models.magic_link import MagicLinkMethods
from authenticator.security.utils import create_token, decode_with_options, validate_token
from common.blueprints import Blueprint
from config import Config

if TYPE_CHECKING:
from models.account import Account as Account
from authenticator.models.account import Account as Account


api_sessions_bp = Blueprint("api_sessions", __name__)
Expand Down
4 changes: 2 additions & 2 deletions authenticator/api/sso/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from flask import abort, current_app, make_response, redirect, request, session
from flask.views import MethodView
from fsd_utils import clear_sentry
from models.account import AccountMethods
from authenticator.models.account import AccountMethods

from api.session.auth_session import AuthSessionBase
from authenticator.api.session.auth_session import AuthSessionBase
from common.blueprints import Blueprint
from config import Config

Expand Down
12 changes: 6 additions & 6 deletions authenticator/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
from flask_redis import FlaskRedis
from flask_session import Session
from flask_talisman import Talisman
from frontend.magic_links.filters import datetime_format
from fsd_utils import LanguageSelector, init_sentry
from fsd_utils.healthchecks.checkers import FlaskRunningChecker, RedisChecker
from fsd_utils.healthchecks.healthcheck import Healthcheck
from fsd_utils.locale_selector.get_lang import get_lang
from fsd_utils.logging import logging
from fsd_utils.services.aws_extended_client import SQSExtendedClient
from jinja2 import ChoiceLoader, PackageLoader, PrefixLoader
from models.fund import FundMethods

from authenticator.frontend.magic_links.filters import datetime_format
from authenticator.models.fund import FundMethods
from config import Config

redis_mlinks = FlaskRedis(config_prefix="REDIS_MLINKS")
Expand Down Expand Up @@ -115,14 +115,14 @@ def _get_service_title():
return dict(get_service_title=_get_service_title)

with flask_app.app_context():
from frontend.default.routes import (
from authenticator.frontend.default.routes import (
default_bp,
internal_server_error,
not_found,
)
from frontend.magic_links.routes import magic_links_bp
from frontend.sso.routes import sso_bp
from frontend.user.routes import user_bp
from authenticator.frontend.magic_links.routes import magic_links_bp
from authenticator.frontend.sso.routes import sso_bp
from authenticator.frontend.user.routes import user_bp

flask_app.register_error_handler(404, not_found)
flask_app.register_error_handler(500, internal_server_error)
Expand Down
12 changes: 6 additions & 6 deletions authenticator/frontend/magic_links/routes.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import uuid

from flask import Blueprint, abort, current_app, g, redirect, render_template, request, url_for
from frontend.magic_links.forms import EmailForm
from fsd_utils.authentication.decorators import login_requested
from models.account import AccountError, AccountMethods
from models.data import get_round_data
from models.fund import FundMethods
from models.magic_link import MagicLinkError, MagicLinkMethods
from models.notification import NotificationError

from authenticator.frontend.magic_links.forms import EmailForm
from authenticator.models.account import AccountError, AccountMethods
from authenticator.models.data import get_round_data
from authenticator.models.fund import FundMethods
from authenticator.models.magic_link import MagicLinkError, MagicLinkMethods
from authenticator.models.notification import NotificationError
from config import Config

magic_links_bp = Blueprint(
Expand Down
8 changes: 4 additions & 4 deletions authenticator/models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
from fsd_utils.config.notify_constants import NotifyConstants

import config
from authenticator.models.data import get_account_data, get_data, get_round_data, post_data, put_data
from authenticator.models.fund import FundMethods
from authenticator.models.magic_link import MagicLinkMethods
from authenticator.models.notification import Notification
from config import Config
from models.data import get_account_data, get_data, get_round_data, post_data, put_data
from models.fund import FundMethods
from models.magic_link import MagicLinkMethods
from models.notification import Notification


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion authenticator/models/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from flask import current_app
from fsd_utils.locale_selector.get_lang import get_lang

from authenticator.models.round import Round
from config import Config
from models.round import Round


def api_call(endpoint: str, method: str = "GET", params: dict = None):
Expand Down
4 changes: 2 additions & 2 deletions authenticator/models/fund.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from flask import request
from fsd_utils.locale_selector.get_lang import get_lang

from authenticator.models.data import get_data
from authenticator.models.round import Round
from config import Config
from models.data import get_data
from models.round import Round


@dataclass
Expand Down
4 changes: 2 additions & 2 deletions authenticator/models/magic_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

from flask import current_app
from flask_redis import FlaskRedis
from security.utils import create_token

from authenticator.security.utils import create_token
from config import Config

if TYPE_CHECKING:
from models.account import Account as Account
from authenticator.models.account import Account as Account


@dataclass
Expand Down
12 changes: 6 additions & 6 deletions authenticator/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pytest
from flask import current_app
from models.account import AccountMethods
from testing.mocks.mocks import * # noqa

from app import create_app
from authenticator.models.account import AccountMethods


@pytest.fixture
Expand All @@ -15,17 +15,17 @@ def app_context():

@pytest.fixture(scope="function")
def create_magic_link(mocker):
from models.fund import Fund
from models.round import Round
from authenticator.models.fund import Fund
from authenticator.models.round import Round

mocker.patch(
"models.account.FundMethods.get_fund",
"authenticator.models.account.FundMethods.get_fund",
return_value=Fund(
name="test fund", fund_title="hello", short_name="COF", identifier="asdfasdf", description="asdfasdfasdf"
),
)
mocker.patch("models.account.get_round_data", return_value=Round(contact_email="asdf@asdf.com"))
mocker.patch("models.account.Notification.send", return_value=True)
mocker.patch("authenticator.models.account.get_round_data", return_value=Round(contact_email="asdf@asdf.com"))
mocker.patch("authenticator.models.account.Notification.send", return_value=True)
auth_landing = AccountMethods.get_magic_link("a@example.com", "cof", "r1w1")
link_key_end = auth_landing.index("?fund=")
link_key = auth_landing[link_key_end - 8 : link_key_end] # noqa:E203
Expand Down
19 changes: 10 additions & 9 deletions authenticator/tests/test_account.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pytest
from models.account import Account, AccountMethods
from models.fund import Fund
from models.round import Round

from authenticator.models.account import Account, AccountMethods
from authenticator.models.fund import Fund
from authenticator.models.round import Round

test_user_id = "test_id"
test_user_email = "john@example.com"
Expand All @@ -15,7 +16,7 @@ def mock_get_account(mocker, request):
new_account = request.node.get_closest_marker("new_account")

mocker.patch(
"models.account.AccountMethods.get_account",
"authenticator.models.account.AccountMethods.get_account",
return_value=Account.from_json(
{
"account_id": test_user_id,
Expand All @@ -34,7 +35,7 @@ def mock_get_account(mocker, request):
@pytest.fixture(scope="function")
def mock_create_account(mocker):
mocker.patch(
"models.account.post_data",
"authenticator.models.account.post_data",
return_value={
"account_id": test_user_id,
"email_address": test_user_email,
Expand All @@ -47,7 +48,7 @@ def mock_create_account(mocker):
@pytest.fixture(scope="function")
def mock_update_account(mocker):
mocker.patch(
"models.account.put_data",
"authenticator.models.account.put_data",
return_value={
"account_id": test_user_id,
"email_address": "john.Doe@example.com",
Expand Down Expand Up @@ -95,7 +96,7 @@ def test_create_account(self, mock_create_account):

def test_create_magic_link(self, mocker, mock_get_account, flask_test_client, mock_redis_magic_links):
mocker.patch(
"models.account.FundMethods.get_fund",
"authenticator.models.account.FundMethods.get_fund",
return_value=Fund(
name="test fund",
fund_title="hello",
Expand All @@ -104,8 +105,8 @@ def test_create_magic_link(self, mocker, mock_get_account, flask_test_client, mo
description="asdfasdfasdf",
),
)
mocker.patch("models.account.get_round_data", return_value=Round(contact_email="asdf@asdf.com"))
mock_send_notification = mocker.patch("models.account.Notification.send", return_value=True)
mocker.patch("authenticator.models.account.get_round_data", return_value=Round(contact_email="asdf@asdf.com"))
mock_send_notification = mocker.patch("authenticator.models.account.Notification.send", return_value=True)

result = AccountMethods.get_magic_link(
email=test_user_email,
Expand Down
15 changes: 7 additions & 8 deletions authenticator/tests/test_fund.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from unittest import mock

from models.fund import Fund, FundMethods

from authenticator.models.fund import Fund, FundMethods
from config.envs.default import DefaultConfig
from config.envs.unit_test import UnitTestConfig

Expand All @@ -26,11 +25,11 @@ def test_get_service_name(self, app_context, mocker):
}
)
# Mock request object with query parameters
mock_request = mocker.patch("models.fund.request")
mock_request = mocker.patch("authenticator.models.fund.request")
mock_request.args.get = lambda arg: fund_short_name
# Call the method and check the output
with mock.patch(
"models.fund.FundMethods.get_fund",
"authenticator.models.fund.FundMethods.get_fund",
return_value=mock_fund,
) as mock_get_fund:
FundMethods.get_service_name()
Expand All @@ -39,11 +38,11 @@ def test_get_service_name(self, app_context, mocker):
def test_get_service_name_for_none_short_name(self, app_context, mocker):
fund_short_name = None
# Mock request object with query parameters
mock_request = mocker.patch("models.fund.request")
mock_request = mocker.patch("authenticator.models.fund.request")
mock_request.args.get = lambda arg: fund_short_name
# Call the method and check the output
with mock.patch(
"models.fund.FundMethods.get_fund",
"authenticator.models.fund.FundMethods.get_fund",
return_value=None,
) as mock_get_fund:
result = FundMethods.get_service_name()
Expand All @@ -52,7 +51,7 @@ def test_get_service_name_for_none_short_name(self, app_context, mocker):

def test_get_fund_success(self, app_context):
# Mock the get_data function to return a response with a valid "id"
with mock.patch("models.fund.get_data") as mock_get_data:
with mock.patch("authenticator.models.fund.get_data") as mock_get_data:
mock_get_data.return_value = {
"id": 1234,
"name": "Test Fund",
Expand All @@ -76,7 +75,7 @@ def test_get_fund_success(self, app_context):

def test_get_fund_failure(self, app_context):
# Mock the get_data function to return a response with a valid "id"
with mock.patch("models.fund.get_data") as mock_get_data:
with mock.patch("authenticator.models.fund.get_data") as mock_get_data:
mock_get_data.return_value = {}

# Call the get_fund function with a valid fund short name
Expand Down
24 changes: 12 additions & 12 deletions authenticator/tests/test_magic_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

import frontend
import pytest
from api.session.auth_session import AuthSessionBase
from bs4 import BeautifulSoup
from frontend.magic_links.forms import EmailForm
from models.account import AccountMethods
from security.utils import validate_token

from app import app
from authenticator.api.session.auth_session import AuthSessionBase
from authenticator.frontend.magic_links.forms import EmailForm
from authenticator.models.account import AccountMethods
from authenticator.security.utils import validate_token


@pytest.mark.usefixtures("flask_test_client")
Expand Down Expand Up @@ -122,8 +122,8 @@ def test_reused_magic_link_with_active_session_shows_landing(self, flask_test_cl
landing_endpoint = f"/service/magic-links/landing/{link_key}?fund=cof&round=r2w3"

with (
mock.patch("models.fund.FundMethods.get_fund") as mock_get_fund,
mock.patch("frontend.magic_links.routes.get_round_data") as mock_get_round_data,
mock.patch("authenticator.models.fund.FundMethods.get_fund") as mock_get_fund,
mock.patch("authenticator.frontend.magic_links.routes.get_round_data") as mock_get_round_data,
):
# Mock get_fund() called in get_magic_link()
mock_fund = mock.MagicMock()
Expand Down Expand Up @@ -265,13 +265,13 @@ def test_magic_link_route_new(self, flask_test_client):
mock_account.get_magic_link.return_value = True

# Test post request with fund and round short names:
with mock.patch("frontend.magic_links.routes.EmailForm", return_value=mock_form):
with mock.patch("authenticator.frontend.magic_links.routes.EmailForm", return_value=mock_form):
with mock.patch(
"frontend.magic_links.routes.AccountMethods",
"authenticator.frontend.magic_links.routes.AccountMethods",
return_value=mock_account,
):
with mock.patch(
"frontend.magic_links.routes.get_round_data",
"authenticator.frontend.magic_links.routes.get_round_data",
return_value=mock_account,
):
response = flask_test_client.post(
Expand Down Expand Up @@ -299,13 +299,13 @@ def test_magic_link_route_new_with_notify_reference(self, flask_test_client):
mock_account.get_magic_link.return_value = True

# Test post request with fund and round short names:
with mock.patch("frontend.magic_links.routes.EmailForm", return_value=mock_form):
with mock.patch("authenticator.frontend.magic_links.routes.EmailForm", return_value=mock_form):
with mock.patch(
"frontend.magic_links.routes.AccountMethods",
"authenticator.frontend.magic_links.routes.AccountMethods",
return_value=mock_account,
):
with mock.patch(
"frontend.magic_links.routes.get_round_data",
"authenticator.frontend.magic_links.routes.get_round_data",
return_value=mock_account,
):
response = flask_test_client.post(
Expand Down
Loading

0 comments on commit 2f2e620

Please sign in to comment.