Skip to content

Commit

Permalink
Add tests for Value properties
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Nov 18, 2023
1 parent bcf2a46 commit 5015f3b
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions rdmo/projects/tests/test_value.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import datetime

from ..models import Value


def mocked_trans(self, field):
return self.text_lang1


def test_value_text(db):
value = Value.objects.get(id=1)
assert value.value == value.text
assert value.value_and_unit == value.text
assert value.option_text is None
assert value.option_additional_input is None


def test_value_textarea(db):
value = Value.objects.get(id=2)
assert value.value == value.text
assert value.value_and_unit == value.text
assert value.option_text is None
assert value.option_additional_input is None


def test_value_bool(db):
value = Value.objects.get(id=3)
assert value.value == 'Yes'
assert value.value_and_unit == 'Yes'
assert value.option_text is None
assert value.option_additional_input is None


def test_value_radio(db, mocker):
mocker.patch('rdmo.options.models.Option.trans', mocked_trans)

value = Value.objects.get(id=4)
assert value.value == 'Other: Lorem ipsum'
assert value.value_and_unit == 'Other: Lorem ipsum'
assert value.option_text == 'Other'
assert value.option_additional_input is True


def test_value_select(db):
value = Value.objects.get(id=5)
assert value.value == ''
assert value.value_and_unit == ''
assert value.option_text == ''
assert value.option_additional_input is False


def test_value_range(db):
value = Value.objects.get(id=6)
assert value.value == value.text
assert value.value_and_unit == value.text
assert value.option_text is None
assert value.option_additional_input is None


def test_value_datetime(db):
value = Value.objects.get(id=7)
assert value.value == datetime.date(2018, 1, 1)
assert value.value_and_unit == datetime.date(2018, 1, 1)
assert value.option_text is None
assert value.option_additional_input is None


def test_value_file(db):
value = Value.objects.get(id=238)
assert value.value == 'rdmo-logo.svg'
assert value.value_and_unit == 'rdmo-logo.svg'
assert value.option_text is None
assert value.option_additional_input is None

0 comments on commit 5015f3b

Please sign in to comment.