diff --git a/consultation_analyser/consultations/dummy_data.py b/consultation_analyser/consultations/dummy_data.py index 41a54644..d7d0a1ca 100644 --- a/consultation_analyser/consultations/dummy_data.py +++ b/consultation_analyser/consultations/dummy_data.py @@ -1,4 +1,4 @@ -from django.conf import settings # replace with HostingEnvironment +from consultation_analyser.hosting_environment import HostingEnvironment from tests.factories import ( FakeConsultationData, QuestionFactory, @@ -11,7 +11,7 @@ class DummyConsultation: def __init__(self, responses=10, **options): - if not settings.DEBUG: + if not HostingEnvironment.is_local(): raise RuntimeError("Dummy data generation should only be run in development") consultation = ConsultationFactory(**options) diff --git a/tests/commands/test_dummy_data.py b/tests/commands/test_dummy_data.py index f4eb8f8a..4eff8fc6 100644 --- a/tests/commands/test_dummy_data.py +++ b/tests/commands/test_dummy_data.py @@ -1,4 +1,5 @@ import pytest +from unittest.mock import patch from io import StringIO from consultation_analyser.consultations.models import Consultation @@ -6,9 +7,8 @@ @pytest.mark.django_db -def test_name_parameter_sets_consultation_name(settings): - settings.DEBUG = True # command will only work in DEBUG - +@patch("consultation_analyser.hosting_environment.HostingEnvironment.is_local", return_value=True) +def test_name_parameter_sets_consultation_name(mock_is_local): call_command( "generate_dummy_data", name="My special consultation", diff --git a/tests/unit/test_generate_dummy_data.py b/tests/unit/test_generate_dummy_data.py index 94fdf733..0fd0eed0 100644 --- a/tests/unit/test_generate_dummy_data.py +++ b/tests/unit/test_generate_dummy_data.py @@ -1,12 +1,13 @@ import pytest +from unittest.mock import patch from consultation_analyser.consultations.dummy_data import DummyConsultation from consultation_analyser.consultations.models import Consultation, Question, Answer @pytest.mark.django_db +@patch("consultation_analyser.hosting_environment.HostingEnvironment.is_local", return_value=True) def test_a_consultation_is_generated(settings): - settings.DEBUG = True assert Consultation.objects.count() == 0 DummyConsultation() @@ -17,8 +18,7 @@ def test_a_consultation_is_generated(settings): @pytest.mark.django_db +@patch("consultation_analyser.hosting_environment.HostingEnvironment.is_local", return_value=False) def test_the_tool_will_only_run_in_dev(settings): - settings.DEBUG = False - with pytest.raises(Exception, match=r"should only be run in development"): DummyConsultation()