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_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_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'
class SettingForm(forms.ModelForm): class Meta: model = Setting fields = [ "age", "sex", "height", "activity", "goal", "goal_weight", "goal_date", "unit_preference", ] goal_weight = MeasurementField( widget=MeasurementWidget(unit_choices=(("lb", "lbs"), ("kg", "kgs")), ), measurement=Weight, required=True, ) goal_date = forms.DateField( widget=DatePickerInput(attrs={ "style": "display: inline-block;", }, ), required=True, ) goal = forms.ChoiceField( widget=forms.Select(attrs={ "class": "form-control", "style": "display: inline-block;", }, ), choices=Setting.goal_choices, required=True, ) unit_preference = forms.ChoiceField( widget=forms.Select(attrs={ "class": "form-control", "style": "display: inline-block;", }, ), choices=Setting.unit_choices, required=True, ) age = forms.IntegerField( widget=forms.NumberInput( attrs={ "class": "form-control", "style": "display: inline-block;", "placeholder": "30", }), required=True, ) sex = forms.ChoiceField( widget=forms.Select(attrs={ "class": "form-control", "style": "display: inline-block;", }, ), choices=Setting.sex_choices, required=True, ) height = MeasurementField( widget=MeasurementWidget(unit_choices=(("inch", "in"), ("cm", "cm")), ), measurement=Distance, required=True, ) activity = forms.ChoiceField( widget=forms.Select(attrs={ "class": "form-control", "style": "display: inline-block;", }, ), choices=Setting.activity_choices, required=True, )
class LogDataForm(forms.ModelForm): class Meta: model = Log fields = ( "date", "weight", "calories_in", "calories_out", "activity_lvl", "front_progress_pic", "side_progress_pic", "back_progress_pic", ) front_progress_pic = CloudinaryFileField( label="Front Facing Progress Pic:", widget=forms.FileInput(attrs={ "style": "display: inline-block;", }), options={ "folder": "progress_pics", }, required=False, ) side_progress_pic = CloudinaryFileField( label="Side Facing Progress Pic:", widget=forms.FileInput(attrs={ "style": "display: inline-block;", }), options={ "folder": "progress_pics", }, required=False, ) back_progress_pic = CloudinaryFileField( label="Back Facing Progress Pic:", widget=forms.FileInput(attrs={ "style": "display: inline-block;", }), options={ "folder": "progress_pics", }, required=False, ) date = forms.DateField( widget=DatePickerInput(attrs={ "style": "display: inline-block;", }, ), required=True, ) weight = MeasurementField( widget=MeasurementWidget(unit_choices=(("lb", "lbs"), ("kg", "kgs")), ), measurement=Weight, required=True, ) calories_in = forms.IntegerField( widget=forms.NumberInput( attrs={ "class": "form-control", "style": "display: inline-block;", "placeholder": "2000", }), required=True, ) calories_out = forms.IntegerField( widget=forms.NumberInput(attrs={ "class": "form-control", "style": "display: inline-block;", }), required=False, ) activity_lvl = forms.ChoiceField( widget=forms.Select(attrs={ "class": "form-control", "style": "display: inline-block;", }, ), choices=Log.choices, required=False, )
class BiDimensionalLabelTestForm(forms.Form): simple = MeasurementField(DegreePerTime)
class SITestForm(forms.Form): simple = MeasurementField(Time)
class LabelTestForm(forms.Form): simple = MeasurementField(Temperature)