def test_min_value(self): field = MeasurementField(measures.Distance, min_value=measures.Distance(mi=1.0)) field.clean([2.0, 'mi']) with pytest.raises(ValidationError) as e: field.clean([0.5, 'mi']) assert 'Ensure this value is greater than or equal to 1.0 mi.' in str(e) with pytest.raises(ValueError) as e: MeasurementField(measures.Distance, min_value=1.0) assert str(e) == '"min_value" must be a measure, got float'
def test_min_value(self): field = MeasurementField(measures.Distance, min_value=measures.Distance(mi=1.0)) field.clean([2.0, 'mi']) with pytest.raises(ValidationError) as e: field.clean([0.5, 'mi']) assert 'Ensure this value is greater than or equal to 1.0 mi.' in force_text(e) with pytest.raises(ValueError) as e: MeasurementField(measures.Distance, min_value=1.0) assert force_text(e) == '"min_value" must be a measure, got float'
def test_max_value(self): valid_form = MeasurementTestForm({ 'measurement_distance_0': 2.0, 'measurement_distance_1': 'mi', }) invalid_form = MeasurementTestForm({ 'measurement_distance_0': 4.0, 'measurement_distance_1': 'mi', }) assert valid_form.is_valid() assert not invalid_form.is_valid() field = MeasurementField(measures.Distance, max_value=measures.Distance(mi=1)) field.clean([0.5, 'mi']) with pytest.raises(ValidationError) as e: field.clean([2.0, 'mi']) assert 'Ensure this value is less than or equal to 1.0 mi.' in str(e) with pytest.raises(ValueError) as e: MeasurementField(measures.Distance, max_value=1.0) assert bytes(e) == '"max_value" must be a measure, got float'
def test_max_value(self): valid_form = MeasurementTestForm({ 'measurement_distance_0': 2.0, 'measurement_distance_1': 'mi', }) invalid_form = MeasurementTestForm({ 'measurement_distance_0': 4.0, 'measurement_distance_1': 'mi', }) assert valid_form.is_valid() assert not invalid_form.is_valid() field = MeasurementField(measures.Distance, max_value=measures.Distance(mi=1)) field.clean([0.5, 'mi']) with pytest.raises(ValidationError) as e: field.clean([2.0, 'mi']) assert 'Ensure this value is less than or equal to 1.0 mi.' in force_text(e) with pytest.raises(ValueError) as e: MeasurementField(measures.Distance, max_value=1.0) assert force_text(e) == '"max_value" must be a measure, got float'