Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions features/smoking_history.feature
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ Feature: Smoking history pages

Then I am on "/rolling-tobacco-smoking-change"
When I check "Yes, I used to smoke more than 25 grams of rolling tobacco a week"
And I check "Yes, I used to smoke fewer than 25 grams of rolling tobacco a week"
And I check "Yes, I used to smoke less than 25 grams of rolling tobacco a week"
And I submit the form

Then I am on "/rolling-tobacco-smoking-increased-frequency"
Expand All @@ -205,7 +205,7 @@ Feature: Smoking history pages
And I submit the form

Then I am on "/rolling-tobacco-smoked-decreased-amount"
When I fill in "When you smoked fewer than 25 grams of rolling tobacco a week, roughly how many grams of rolling tobacco did you normally smoke a month?" with "5"
When I fill in "When you smoked less than 25 grams of rolling tobacco a week, roughly how many grams of rolling tobacco did you normally smoke a month?" with "5"
And I submit the form

Then I am on "/rolling-tobacco-smoked-decreased-years"
Expand Down
4 changes: 2 additions & 2 deletions lung_cancer_screening/questions/forms/smoked_amount_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def normal_label(self):

def changed_label(self):
return (
f"When you smoked {self.presenter.more_or_fewer()} than "
f"When you smoked {self.presenter.more_or_fewer_or_less()} than "
f"{self.normal_presenter.to_sentence()}, "
f"roughly how many {self.presenter.unit()} "
f"did you normally smoke a {self.presenter.frequency()}?"
Expand All @@ -69,7 +69,7 @@ def normal_required_error_message(self):
def changed_required_error_message(self):
return (
f"Enter the number of {self.presenter.unit()} "
f"you smoked when you smoked {self.presenter.more_or_fewer()} than "
f"you smoked when you smoked {self.presenter.more_or_fewer_or_less()} than "
f"{self.normal_presenter.to_sentence()}"
)

Expand Down
13 changes: 8 additions & 5 deletions lung_cancer_screening/questions/forms/smoking_change_form.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django import forms

from ...nhsuk_forms.choice_field import MultipleChoiceField
from ..models.tobacco_smoking_history import TobaccoSmokingHistory
from ..models.tobacco_smoking_history import TobaccoSmokingHistory, TobaccoSmokingHistoryTypes
from .mixins.smoking_form_presenter import SmokingFormPresenter


Expand Down Expand Up @@ -64,10 +64,13 @@ def generate_label(self, value, label):
if value == TobaccoSmokingHistory.Levels.NO_CHANGE:
return label

return (
f"{TobaccoSmokingHistory.Levels(value).label} "
f" than {self.presenter.to_sentence()}"
)
if (value == TobaccoSmokingHistory.Levels.DECREASED.value and
self.tobacco_type == TobaccoSmokingHistoryTypes.ROLLING_TOBACCO):
prefix = "Yes, I used to smoke less"
else:
prefix = TobaccoSmokingHistory.Levels(value).label

return f"{prefix} than {self.presenter.to_sentence()}"

def required_error_message(self):
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def normal_label(self):

def changed_label(self):
return (
f"When you smoked {self.presenter.more_or_fewer()} "
f"When you smoked {self.presenter.more_or_fewer_or_less()} "
f"than {self.normal_presenter.to_sentence()}, how often did "
f"you smoke {self.presenter.human_type().lower()}?"
)
Expand All @@ -77,7 +77,7 @@ def normal_required_error_message(self):
def changed_required_error_message(self):
return (
f"Select how often you smoked {self.presenter.human_type().lower()} "
f"when you smoked {self.presenter.more_or_fewer()} "
f"when you smoked {self.presenter.more_or_fewer_or_less()} "
f"than {self.normal_presenter.to_sentence()}"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ def have_you_smoked_or_did_you_smoke(self):
return "did you smoke"


def more_or_fewer(self):
def more_or_fewer_or_less(self):
if self.tobacco_smoking_history.is_increased():
return "more"
elif self.tobacco_smoking_history.is_decreased():
if self.tobacco_smoking_history.is_rolling_tobacco():
return "less"
return "fewer"

def increased_or_decreased(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,17 @@
)
from lung_cancer_screening.questions.models.tobacco_smoking_history import TobaccoSmokingHistory


class TestTobaccoSmokingHistoryPresenter(TestCase):
class TestTobaccoSmokingHistoryPresenterAllTobaccoTypes(TestCase):
def setUp(self):
self.response_set = ResponseSetFactory.create()
self.age_when_started_smoking_response = AgeWhenStartedSmokingResponseFactory.create(
response_set=self.response_set
)
self.tobacco_smoking_history = TobaccoSmokingHistoryFactory.create(
rolling_tobacco=True,
complete=True,
response_set=self.response_set
)

def test_delegates_human_type_to_tobacco_smoking_history(self):
presenter = TobaccoSmokingHistoryPresenter(self.tobacco_smoking_history)

self.assertEqual(
presenter.human_type(),
"Rolling tobacco"
)

def test_url_type_returns_the_url_type_of_the_tobacco_smoking_history(self):
presenter = TobaccoSmokingHistoryPresenter(self.tobacco_smoking_history)

self.assertEqual(
presenter.url_type(),
"rolling-tobacco"
)

def test_duration_years_returns_not_answered_text_if_duration_years_is_not_set(self):
self.tobacco_smoking_history.smoked_total_years_response = None
presenter = TobaccoSmokingHistoryPresenter(self.tobacco_smoking_history)
Expand Down Expand Up @@ -67,26 +49,6 @@ def is_current_delegates_to_tobacco_smoking_history(self):
)


def test_to_sentence_returns_the_amount_of_type_per_frequency(self):
self.tobacco_smoking_history.smoked_amount_response.value = 7
self.tobacco_smoking_history.smoking_frequency_response.value = SmokingFrequencyValues.WEEKLY

presenter = TobaccoSmokingHistoryPresenter(self.tobacco_smoking_history)

self.assertEqual(
presenter.to_sentence(),
"7 grams of rolling tobacco a week"
)

def test_unit_returns_the_unit_of_the_tobacco_smoking_history(self):
presenter = TobaccoSmokingHistoryPresenter(self.tobacco_smoking_history)

self.assertEqual(
presenter.unit(),
"grams of rolling tobacco"
)


def test_smoke_or_smoked_returns_present_tense_if_current_normal_level(self):
self.tobacco_smoking_history.smoking_current_response.value = True
self.tobacco_smoking_history.smoking_current_response.save()
Expand Down Expand Up @@ -129,28 +91,17 @@ def test_frequency_returns_the_human_frequency_of_the_tobacco_smoking_history(se
)


def test_more_or_fewer_text_returns_more_if_increased_level(self):
def test_more_or_fewer_or_less_text_returns_more_if_increased_level(self):
self.tobacco_smoking_history.level = TobaccoSmokingHistory.Levels.INCREASED
self.tobacco_smoking_history.save()

presenter = TobaccoSmokingHistoryPresenter(self.tobacco_smoking_history)

self.assertEqual(
presenter.more_or_fewer(),
presenter.more_or_fewer_or_less(),
"more"
)

def test_more_or_fewer_text_returns_fewer_if_decreased_level(self):
self.tobacco_smoking_history.level = TobaccoSmokingHistory.Levels.DECREASED
self.tobacco_smoking_history.save()

presenter = TobaccoSmokingHistoryPresenter(self.tobacco_smoking_history)

self.assertEqual(
presenter.more_or_fewer(),
"fewer"
)

def test_do_or_did_returns_do_if_current_normal_level(self):
self.tobacco_smoking_history.smoking_current_response.value = True
self.tobacco_smoking_history.smoking_current_response.save()
Expand Down Expand Up @@ -207,7 +158,7 @@ def test_have_you_smoked_or_did_you_smoke_returns_did_if_not_current_normal_leve
)


def currently_or_previously_returns_currently_if_current_normal_level(self):
def test_currently_or_previously_returns_currently_if_current_normal_level(self):
self.tobacco_smoking_history.smoking_current_response.value = True
self.tobacco_smoking_history.smoking_current_response.save()

Expand All @@ -218,7 +169,7 @@ def currently_or_previously_returns_currently_if_current_normal_level(self):
"currently"
)

def currently_or_previously_returns_previously_if_not_current_normal_level(self):
def test_currently_or_previously_returns_previously_if_not_current_normal_level(self):
self.tobacco_smoking_history.smoking_current_response.value = False
self.tobacco_smoking_history.smoking_current_response.save()

Expand All @@ -229,7 +180,7 @@ def currently_or_previously_returns_previously_if_not_current_normal_level(self)
"previously"
)

def currently_or_previously_returns_previously_if_changed_level(self):
def test_currently_or_previously_returns_previously_if_changed_level(self):
self.tobacco_smoking_history.level = TobaccoSmokingHistory.Levels.INCREASED
self.tobacco_smoking_history.save()

Expand All @@ -240,7 +191,38 @@ def currently_or_previously_returns_previously_if_changed_level(self):
"previously"
)

class TestTobaccoSmokingHistoryPresenterRollingTobaccoAndPipe(TestCase):
def setUp(self):
self.response_set = ResponseSetFactory.create()
self.age_when_started_smoking_response = AgeWhenStartedSmokingResponseFactory.create(
response_set=self.response_set
)
self.tobacco_smoking_history = TobaccoSmokingHistoryFactory.create(
complete=True,
response_set=self.response_set
)

# Tests for Rolling Tobacco
def test_delegates_human_type_to_tobacco_smoking_history_rolling_tobacco(self):
self.tobacco_smoking_history.type = TobaccoSmokingHistoryTypes.ROLLING_TOBACCO
presenter = TobaccoSmokingHistoryPresenter(self.tobacco_smoking_history)

self.assertEqual(
presenter.human_type(),
"Rolling tobacco"
)

def test_url_type_returns_the_url_type_of_the_tobacco_smoking_history_rolling_tobacco(self):
self.tobacco_smoking_history.type = TobaccoSmokingHistoryTypes.ROLLING_TOBACCO
presenter = TobaccoSmokingHistoryPresenter(self.tobacco_smoking_history)

self.assertEqual(
presenter.url_type(),
"rolling-tobacco"
)

def test_amount_prefix_when_rolling_tobacco(self):
self.tobacco_smoking_history.type = TobaccoSmokingHistoryTypes.ROLLING_TOBACCO
self.tobacco_smoking_history.rolling_tobacco = True
self.tobacco_smoking_history.save()

Expand All @@ -251,13 +233,60 @@ def test_amount_prefix_when_rolling_tobacco(self):
"grams of "
)

def test_amount_prefix_defaults_to_empty_string(self):
def test_to_sentence_returns_the_amount_of_type_per_frequency_rolling_tobacco(self):
self.tobacco_smoking_history.type = TobaccoSmokingHistoryTypes.ROLLING_TOBACCO
self.tobacco_smoking_history.smoked_amount_response.value = 7
self.tobacco_smoking_history.smoking_frequency_response.value = SmokingFrequencyValues.WEEKLY

presenter = TobaccoSmokingHistoryPresenter(self.tobacco_smoking_history)

self.assertEqual(
presenter.to_sentence(),
"7 grams of rolling tobacco a week"
)

def test_unit_returns_the_unit_of_the_tobacco_smoking_history_rolling_tobacco(self):
self.tobacco_smoking_history.type = TobaccoSmokingHistoryTypes.ROLLING_TOBACCO
presenter = TobaccoSmokingHistoryPresenter(self.tobacco_smoking_history)

self.assertEqual(
presenter.unit(),
"grams of rolling tobacco"
)

def test_more_or_fewer_or_less_text_returns_less_if_decreased_level_rolling_tobacco(self):
self.tobacco_smoking_history.type = TobaccoSmokingHistoryTypes.ROLLING_TOBACCO
self.tobacco_smoking_history.level = TobaccoSmokingHistory.Levels.DECREASED
self.tobacco_smoking_history.save()

presenter = TobaccoSmokingHistoryPresenter(self.tobacco_smoking_history)

self.assertEqual(
presenter.more_or_fewer_or_less(),
"less"
)

# Tests for Pipe
def test_more_or_fewer_or_less_text_returns_fewer_if_decreased_level_cigarettes(self):
self.tobacco_smoking_history.type = TobaccoSmokingHistoryTypes.PIPE
self.tobacco_smoking_history.level = TobaccoSmokingHistory.Levels.DECREASED
self.tobacco_smoking_history.save()

presenter = TobaccoSmokingHistoryPresenter(self.tobacco_smoking_history)

self.assertEqual(
presenter.amount_prefix(),
""
presenter.more_or_fewer_or_less(),
"fewer"
)

def test_to_sentence_returns_the_amount_of_type_per_frequency_pipe(self):
self.tobacco_smoking_history.type = TobaccoSmokingHistoryTypes.PIPE
self.tobacco_smoking_history.smoked_amount_response.value = 7
self.tobacco_smoking_history.smoking_frequency_response.value = SmokingFrequencyValues.WEEKLY

presenter = TobaccoSmokingHistoryPresenter(self.tobacco_smoking_history)

self.assertEqual(
presenter.to_sentence(),
"7 full pipe loads a week"
)
Loading