def test_form_storage(self):
        form = MeasurementTestForm({
            'measurement_distance_0': 2.0,
            'measurement_distance_1': 'mi',
        })
        assert form.is_valid()
        obj = form.save()

        assert obj.measurement_distance == measures.Distance(mi=2)
    def test_form_bidir(self):
        form = MeasurementTestForm({
            'measurement_speed_0': 2.0,
            'measurement_speed_1': 'mi__hr',
        })
        assert form.is_valid()
        obj = form.save()

        assert obj.measurement_speed == measures.Speed(mi__hr=2)
    def test_form_bidir(self):
        form = MeasurementTestForm({
            'measurement_speed_0': 2.0,
            'measurement_speed_1': 'mi__hr',
        })
        assert form.is_valid()
        obj = form.save()

        assert obj.measurement_speed == measures.Speed(mi__hr=2)
    def test_form_storage(self):
        form = MeasurementTestForm({
            'measurement_distance_0': 2.0,
            'measurement_distance_1': 'mi',
        })
        assert form.is_valid()
        obj = form.save()

        assert obj.measurement_distance == measures.Distance(mi=2)
示例#5
0
    def test_form_bidir(self):
        form = MeasurementTestForm({
            "measurement_speed_0": 2.0,
            "measurement_speed_1": "mi__hr"
        })
        assert form.is_valid()
        obj = form.save()

        assert obj.measurement_speed == measures.Speed(mi__hr=2)
示例#6
0
    def test_form_storage(self):
        form = MeasurementTestForm({
            "measurement_distance_0": 2.0,
            "measurement_distance_1": "mi"
        })
        assert form.is_valid()
        obj = form.save()

        assert obj.measurement_distance == measures.Distance(mi=2)
 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()
    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'
    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'