Make interval check more explicit

This commit is contained in:
Matias Bordese 2022-10-26 16:35:59 -03:00
parent 1d4f036303
commit 4bc3ed17a8
2 changed files with 4 additions and 4 deletions

View file

@ -116,9 +116,9 @@ class OnCallShiftSerializer(EagerLoadingMixin, serializers.ModelSerializer):
)
if frequency not in (CustomOnCallShift.FREQUENCY_WEEKLY, CustomOnCallShift.FREQUENCY_DAILY) and by_day:
raise serializers.ValidationError({"by_day": ["Cannot set days value for this frequency type"]})
if frequency == CustomOnCallShift.FREQUENCY_DAILY and by_day and interval > 1:
if frequency == CustomOnCallShift.FREQUENCY_DAILY and by_day and interval != 1:
raise serializers.ValidationError(
{"interval": ["Cannot set interval > 1 if a days value is set for a daily frequency"]}
{"interval": ["Interval must be 1 if a days value is set for a daily frequency"]}
)
def _validate_rotation_start(self, shift_start, rotation_start):

View file

@ -789,7 +789,7 @@ def test_create_on_call_shift_invalid_data_interval(on_call_shift_internal_api_s
assert response.status_code == status.HTTP_400_BAD_REQUEST
assert response.data["interval"][0] == "Cannot set interval for non-recurrent shifts"
# by_day, daily, interval > 1
# by_day, daily, interval != 1
data = {
"title": "Test Shift 2",
"type": CustomOnCallShift.TYPE_ROLLING_USERS_EVENT,
@ -808,7 +808,7 @@ def test_create_on_call_shift_invalid_data_interval(on_call_shift_internal_api_s
response = client.post(url, data, format="json", **make_user_auth_headers(user1, token))
assert response.status_code == status.HTTP_400_BAD_REQUEST
assert response.data["interval"][0] == "Cannot set interval > 1 if a days value is set for a daily frequency"
assert response.data["interval"][0] == "Interval must be 1 if a days value is set for a daily frequency"
@pytest.mark.django_db