Skip to content

Commit

Permalink
feat(vaccinations_gender_by_date): return None...
Browse files Browse the repository at this point in the history
if date is out of range
  • Loading branch information
jalezi committed May 18, 2021
1 parent b9c65dd commit b12f43c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cepimose/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,14 @@ def vaccinations_gender_by_date(date: datetime.datetime = None):
print(f"Elapsed time: {finish - start}")
return result

day = list(
filtered_days = list(
filter(lambda item: item["date"] == date, _vaccinations_gender_by_date_requests)
)[0]
)

if len(filtered_days) == 0:
return None

day = filtered_days[0]

date = day["date"]
female = day[Gender.FEMALE]
Expand Down
11 changes: 11 additions & 0 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ def test_vaccinations_gender_by_date(self):
data5 = cepimose.vaccinations_gender_by_date(test_date5)

def assertRow(row, expected_date, expected_data):
print(row)
self.assertEqual(row.date, expected_date)
self.assertAlmostEqual(row.female_first, expected_data[0], delta=300)
self.assertAlmostEqual(row.female_second, expected_data[1], delta=300)
Expand All @@ -392,3 +393,13 @@ def assertRow(row, expected_date, expected_data):
assertRow(data3, test_date3, [2851, 3024, 1870, 1902])
assertRow(data4, test_date4, [4652, 76, 4400, 53])
assertRow(data5, test_date5, [1009, 690, 1321, 681])

def test_vaccinations_gender_by_date_for_today(self):
test_date_today = datetime.datetime.today()
test_today_year = test_date_today.year
test_today_month = test_date_today.month
test_today_day = test_date_today.day
test_today_without_time = datetime.datetime(test_today_year, test_today_month, test_today_day)
data_today = cepimose.vaccinations_gender_by_date(test_today_without_time)
print(f"Today: {test_date_today}")
self.assertIsNot(data_today, None)

0 comments on commit b12f43c

Please sign in to comment.