Skip to content

Commit

Permalink
[staged-updates] fixes test logging bug
Browse files Browse the repository at this point in the history
  • Loading branch information
biblicabeebli committed Nov 29, 2023
1 parent 2781af2 commit 3e0b390
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions tests/test_endpoints.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import logging
from copy import copy
from datetime import date, datetime, timedelta
from io import BytesIO
Expand Down Expand Up @@ -423,15 +424,22 @@ def test_mfa_required_site_admin_setting(self, patch1: MagicMock, patch2: MagicM

class TestDowntime(BasicSessionTestCase):
""" Tests our very basic downtime middleware """

def test_downtime(self):
GlobalSettings.get_singleton_instance().update(downtime_enabled=False)
self.easy_get("login_pages.login_page", status_code=200)
GlobalSettings.get_singleton_instance().update(downtime_enabled=True)
self.easy_get("login_pages.login_page", status_code=503)
GlobalSettings.get_singleton_instance().update(downtime_enabled=False)
self.easy_get("login_pages.login_page", status_code=200)

# this test emits a logging statement `ERROR:django.request:Service Unavailable: /`
# that we want to squash, but we want to set logging level back to normal when we are done.
previous_logging_level = logging.getLogger("django.request").level
try:
logging.getLogger("django.request").setLevel(logging.CRITICAL)
GlobalSettings.get_singleton_instance().update(downtime_enabled=False)
self.easy_get("login_pages.login_page", status_code=200)
GlobalSettings.get_singleton_instance().update(downtime_enabled=True)
self.easy_get("login_pages.login_page", status_code=503)
GlobalSettings.get_singleton_instance().update(downtime_enabled=False)
self.easy_get("login_pages.login_page", status_code=200)
except Exception:
raise
finally:
logging.getLogger("django.request").setLevel(previous_logging_level)

class TestChooseStudy(ResearcherSessionTest):
ENDPOINT_NAME = "admin_pages.choose_study"
Expand Down

0 comments on commit 3e0b390

Please sign in to comment.