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 fbcbd03
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 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 Expand Up @@ -107,6 +111,7 @@ def closed_points(self):
)

def total_closed_points_by_date(self, date):

# Milestone instance will keep a cache of the total closed points by date
if self._total_closed_points_by_date is None:
self._total_closed_points_by_date = {}
Expand Down Expand Up @@ -165,6 +170,7 @@ def total_closed_points_by_date(self, date):

acumulated_date_points = 0
current_date = self.estimated_start

while current_date <= self.estimated_finish:
acumulated_date_points += self._total_closed_points_by_date.get(current_date, 0)
self._total_closed_points_by_date[current_date] = acumulated_date_points
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 fbcbd03

Please sign in to comment.