Esempio n. 1
0
 def require_bool_field(self, field: str, cleaned_data) -> Optional[bool]:
     value = YesNoRadiosField.coerce(cleaned_data.get(field))
     if value is None:
         self.add_dynamically_required_error(field)
     else:
         assert isinstance(value, bool)
     return value
Esempio n. 2
0
    def clean(self):
        cleaned_data = super().clean()
        two_or_less = YesNoRadiosField.coerce(cleaned_data.get(TWO_OR_LESS_APARTMENTS_IN_BUILDING))

        if two_or_less is True:
            self.require_bool_field(MORE_THAN_ONE_FAMILY_PER_APARTMENT, cleaned_data)
        elif two_or_less is False:
            cleaned_data[MORE_THAN_ONE_FAMILY_PER_APARTMENT] = ''

        return cleaned_data
Esempio n. 3
0
    def clean(self):
        cleaned_data = super().clean()

        has_current_case = YesNoRadiosField.coerce(cleaned_data.get("has_current_case"))

        if has_current_case is True:
            self.require_text_field("index_number", cleaned_data)
        elif has_current_case is False:
            cleaned_data["index_number"] = ""

        return cleaned_data
Esempio n. 4
0
    def clean(self):
        cleaned_data = super().clean()
        filed_with_311 = YesNoRadiosField.coerce(cleaned_data.get(FILED_WITH_311))

        if filed_with_311 is True:
            hpd_issued_violations = self.require_bool_field(
                HPD_ISSUED_VIOLATIONS, cleaned_data)
            if hpd_issued_violations is False:
                self.require_bool_field(THIRTY_DAYS_SINCE_311, cleaned_data)
                cleaned_data[THIRTY_DAYS_SINCE_VIOLATIONS] = ''
            elif hpd_issued_violations is True:
                self.require_bool_field(THIRTY_DAYS_SINCE_VIOLATIONS, cleaned_data)
                cleaned_data[THIRTY_DAYS_SINCE_311] = ''
        elif filed_with_311 is False:
            cleaned_data[HPD_ISSUED_VIOLATIONS] = ''
            cleaned_data[THIRTY_DAYS_SINCE_311] = ''
            cleaned_data[THIRTY_DAYS_SINCE_VIOLATIONS] = ''

        return cleaned_data
Esempio n. 5
0
 def test_raises_value_error_on_unexpected_value(self):
     with pytest.raises(ValueError,
                        match="Invalid YesNoRadiosField value: blah"):
         YesNoRadiosField.coerce("blah")
Esempio n. 6
0
 def test_coerce_works(self, value, expected):
     assert YesNoRadiosField.coerce(value) is expected