Skip to content

Commit

Permalink
Validate that the start date is earlier than the maximum year of the …
Browse files Browse the repository at this point in the history
…library datetime.
  • Loading branch information
ferzunzu committed Jul 26, 2024
1 parent f0eb001 commit bb99c31
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions taiga/projects/milestones/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def __repr__(self):
return "<Milestone {0}>".format(self.id)

def clean(self):

if self.estimated_start and self.estimated_start.year == datetime.MAXYEAR:
raise ValidationError(_("Invalid estimated start year, it must be less than 9999."))

# Don't allow draft entries to have a pub_date.
if self.estimated_start and self.estimated_finish and self.estimated_start >= self.estimated_finish:
raise ValidationError(_('The estimated start must be previous to the estimated finish.'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,23 @@ def test_milestone_create(client, data):
assert results == [401, 403, 403, 451, 451]


def test_milestone_create_invalid_dates(client, data):
url = reverse('milestones-list')

user = data.project_owner
create_data = json.dumps({
"name": "test",
"estimated_start": "9999-12-10",
"estimated_finish": "9999-12-24",
"project": data.public_project.pk,
})

client.login(user)

response = client.post(url, create_data, content_type="application/json")
assert response.status_code == 400
assert response.data["__all__"][0] == "Invalid estimated start year, it must be less than 9999."

def test_milestone_patch(client, data):
public_url = reverse('milestones-detail', kwargs={"pk": data.public_milestone.pk})
private_url1 = reverse('milestones-detail', kwargs={"pk": data.private_milestone1.pk})
Expand Down

0 comments on commit bb99c31

Please sign in to comment.