def test_unauthenticated_related_validations(resource_in_unit): activate('en') resource_in_unit.min_age = 2 resource_in_unit.max_age = 20 resource_in_unit.max_reservations_per_user = 5 resource_in_unit.access_code_type = Resource.ACCESS_CODE_TYPE_PIN6 resource_in_unit.authentication = 'unauthenticated' with pytest.raises(ValidationError) as error: resource_in_unit.clean() assert 'This value cannot be set to more than zero if resource authentication is: Unauthenticated' \ in get_field_errors(error.value, 'min_age') resource_in_unit.min_age = 0 with pytest.raises(ValidationError) as error: resource_in_unit.clean() assert 'This value cannot be set to more than zero if resource authentication is: Unauthenticated' \ in get_field_errors(error.value, 'max_age') resource_in_unit.max_age = 0 with pytest.raises(ValidationError) as error: resource_in_unit.clean() assert 'This value cannot be set to more than zero if resource authentication is: Unauthenticated' \ in get_field_errors(error.value, 'max_reservations_per_user') resource_in_unit.max_reservations_per_user = 0 with pytest.raises(ValidationError) as error: resource_in_unit.clean() assert 'This cannot be enabled if resource authentication is: Unauthenticated' \ in get_field_errors(error.value, 'access_code_type') resource_in_unit.access_code_type = Resource.ACCESS_CODE_TYPE_NONE resource_in_unit.full_clean()
def test_price_validations(resource_in_unit): activate('en') resource_in_unit.min_price_per_hour = Decimal(1) resource_in_unit.max_price_per_hour = None resource_in_unit.full_clean() # should not raise resource_in_unit.min_price_per_hour = Decimal(8) resource_in_unit.max_price_per_hour = Decimal(5) with pytest.raises(ValidationError) as ei: resource_in_unit.full_clean() assert 'This value cannot be greater than max price per hour' in get_field_errors(ei.value, 'min_price_per_hour') resource_in_unit.min_price_per_hour = Decimal(-5) resource_in_unit.max_price_per_hour = Decimal(-8) with pytest.raises(ValidationError) as ei: resource_in_unit.full_clean() assert 'Ensure this value is greater than or equal to 0.00.' in get_field_errors(ei.value, 'min_price_per_hour') assert 'Ensure this value is greater than or equal to 0.00.' in get_field_errors(ei.value, 'max_price_per_hour')
def test_time_slot_validations(resource_in_unit): activate('en') resource_in_unit.min_period = datetime.timedelta(hours=2) resource_in_unit.slot_size = datetime.timedelta(minutes=45) with pytest.raises(ValidationError) as error: resource_in_unit.full_clean() assert 'This value must be a multiple of slot_size' in get_field_errors(error.value, 'min_period') resource_in_unit.min_period = datetime.timedelta(hours=2) resource_in_unit.slot_size = datetime.timedelta(minutes=30) resource_in_unit.full_clean()
def test_time_slot_validations(resource_in_unit): activate('en') resource_in_unit.min_period = datetime.timedelta(hours=2) resource_in_unit.slot_size = datetime.timedelta(minutes=45) with pytest.raises(ValidationError) as error: resource_in_unit.full_clean() assert 'This value must be a multiple of slot_size' in get_field_errors( error.value, 'min_period') resource_in_unit.min_period = datetime.timedelta(hours=2) resource_in_unit.slot_size = datetime.timedelta(minutes=30) resource_in_unit.full_clean()