Skip to content

Commit

Permalink
fix other tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-at-mit committed Sep 10, 2024
1 parent 47db578 commit 0a4157d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
10 changes: 6 additions & 4 deletions authentication/middleware_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ def test_process_exception_no_strategy(rf, settings):
assert middleware.process_exception(request, None) is None


def test_process_exception(rf, settings):
def test_process_exception(mocker, rf, settings):
"""Tests that a process_exception handles auth exceptions correctly"""
settings.DEBUG = False
request = rf.get(reverse("social:complete", args=("email",)))
# social_django depends on request.sesssion, so use the middleware to set that
SessionMiddleware().process_request(request)
get_response = mocker.MagicMock()
SessionMiddleware(get_response).process_request(request)
strategy = load_strategy(request)
backend = load_backend(strategy, "email", None)
request.social_strategy = strategy
Expand All @@ -39,12 +40,13 @@ def test_process_exception(rf, settings):
)


def test_process_exception_non_auth_error(rf, settings):
def test_process_exception_non_auth_error(mocker, rf, settings):
"""Tests that a process_exception handles non-auth exceptions correctly"""
settings.DEBUG = False
request = rf.get(reverse("social:complete", args=("email",)))
# social_django depends on request.sesssion, so use the middleware to set that
SessionMiddleware().process_request(request)
get_response = mocker.MagicMock()
SessionMiddleware(get_response).process_request(request)
strategy = load_strategy(request)
backend = load_backend(strategy, "email", None)
request.social_strategy = strategy
Expand Down
6 changes: 3 additions & 3 deletions cms/models_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def test_course_page_context_edx_access( # noqa: PLR0913
patched_get_relevant_run_qset.assert_called_once_with(course=course_page.course)


def generate_flexible_pricing_response(request_user, flexible_pricing_form):
def generate_flexible_pricing_response(mocker, request_user, flexible_pricing_form):
"""
Generates a fully realized request for the Flexible Pricing tests.
Expand All @@ -248,8 +248,8 @@ def generate_flexible_pricing_response(request_user, flexible_pricing_form):
rf = RequestFactory()
request = rf.get("/")
request.user = request_user

middleware = SessionMiddleware()
get_response = mocker.MagicMock()
middleware = SessionMiddleware(get_response)
middleware.process_request(request)
request.session.save()

Expand Down
3 changes: 2 additions & 1 deletion mail/verification_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def test_send_verification_email(mocker, rf):
email = "test@localhost"
request = rf.post(reverse("social:complete", args=("email",)), {"email": email})
# social_django depends on request.session, so use the middleware to set that
SessionMiddleware().process_request(request)
get_response = mocker.MagicMock()
SessionMiddleware(get_response).process_request(request)
strategy = load_strategy(request)
backend = load_backend(strategy, EmailAuth.name, None)
code = mocker.Mock(code="abc")
Expand Down
5 changes: 3 additions & 2 deletions main/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def list_of_dicts(specialty_dict_iter):
return list(map(dict, specialty_dict_iter))


def set_request_session(request, session_dict):
def set_request_session(mocker, request, session_dict):
"""
Sets session variables on a RequestFactory object
Args:
Expand All @@ -147,7 +147,8 @@ def set_request_session(request, session_dict):
Returns:
RequestFactory: The same request object with session variables set
"""
middleware = SessionMiddleware()
get_response = mocker.MagicMock()
middleware = SessionMiddleware(get_response)
middleware.process_request(request)
for key, value in session_dict.items():
request.session[key] = value
Expand Down

0 comments on commit 0a4157d

Please sign in to comment.