Skip to content

Commit

Permalink
test(app): metrics_enabled setings checks
Browse files Browse the repository at this point in the history
ref:#469 fixes #470 closes #156
  • Loading branch information
jon-nfc committed Jan 14, 2025
1 parent ea02798 commit ca1cc4e
Showing 1 changed file with 106 additions and 2 deletions.
108 changes: 106 additions & 2 deletions app/app/tests/unit/test_settings.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import pytest

from django.conf import settings as django_settings
from django.shortcuts import reverse
from django.test import TestCase, Client

from app import settings


import pytest
import unittest



class SettingsDefault(TestCase):
Expand All @@ -22,20 +23,68 @@ def test_setting_default_debug_off(self):
assert not settings.DEBUG


def test_setting_default_debug_off_type(self):
""" Settings attribute type check
setting `DEBUG` must be of type bool
"""

assert type(settings.DEBUG) is bool



def test_setting_default_login_required(self):
""" By default login should be required
"""

assert settings.LOGIN_REQUIRED


def test_setting_default_login_required_type(self):
""" Settings attribute type check
setting `LOGIN_REQUIRED` must be of type bool
"""

assert type(settings.LOGIN_REQUIRED) is bool



def test_setting_default_metrics_off(self):
""" Ensure that metrics is off within settings by default
Metrics is only required when user turns it on
"""

assert not settings.METRICS_ENABLED


def test_setting_default_metrics_off_type(self):
""" Settings attribute type check
setting `METRICS_ENABLED` must be of type bool
"""

assert type(settings.METRICS_ENABLED) is bool



def test_setting_default_use_tz(self):
""" Ensure that 'USE_TZ = True' is within settings
"""

assert settings.USE_TZ


def test_setting_default_use_tz_type(self):
""" Settings attribute type check
setting `USE_TZ` must be of type bool
"""

assert type(settings.USE_TZ) is bool



class SettingsValues(TestCase):
""" Test Each setting that offers different functionality """
Expand Down Expand Up @@ -64,3 +113,58 @@ def test_setting_value_login_required_not(self):
response = client.get(url)

assert response.status_code == 200



def test_setting_value_metrics_off_middleware(self):
""" Metrics off check
when metrics are off, its middleware must not exist in settings
"""

assert (
'django_prometheus.middleware.PrometheusBeforeMiddleware' not in settings.MIDDLEWARE
and
'django_prometheus.middleware.PrometheusAfterMiddleware' not in settings.MIDDLEWARE
)



def test_setting_value_metrics_off_installed_apps(self):
""" Metrics off check
when metrics are off, it should not be installed.
"""

assert 'django_prometheus' not in settings.INSTALLED_APPS


@pytest.mark.skip( reason = 'figure out how to test' )
def test_setting_value_metrics_on_middleware(self):
""" Metrics off check
logic in settings adjusts middleware when `METRICS_ENABLED=True`
when metrics are off, its middleware must not exist in settings
"""

assert (
'django_prometheus.middleware.PrometheusBeforeMiddleware' in settings.MIDDLEWARE
and
'django_prometheus.middleware.PrometheusAfterMiddleware' in settings.MIDDLEWARE
)



@pytest.mark.skip( reason = 'figure out how to test' )
def test_setting_value_metrics_on_installed_apps(self):
""" Metrics off check
logic in settings adjusts installed apps when `METRICS_ENABLED=True`
when metrics are off, it should not be installed.
"""

settings.METRICS_ENABLED = True

assert 'django_prometheus' in settings.INSTALLED_APPS

0 comments on commit ca1cc4e

Please sign in to comment.