You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.4 KiB

  1. from datetime import datetime as dt, timedelta as td
  2. from django.test import TestCase
  3. from hc.lib.date import format_hms, choose_next_report_date
  4. class DateFormattingTestCase(TestCase):
  5. def test_mins_secs_work(self):
  6. s = format_hms(td(seconds=0))
  7. self.assertEqual(s, "0 sec")
  8. s = format_hms(td(seconds=1))
  9. self.assertEqual(s, "1 sec")
  10. s = format_hms(td(seconds=61))
  11. self.assertEqual(s, "1 min 1 sec")
  12. s = format_hms(td(seconds=62))
  13. self.assertEqual(s, "1 min 2 sec")
  14. def test_hours_work(self):
  15. s = format_hms(td(seconds=62 + 60 * 60))
  16. self.assertEqual(s, "1 h 1 min 2 sec")
  17. s = format_hms(td(seconds=60 * 60))
  18. self.assertEqual(s, "1 h 0 min 0 sec")
  19. class NextReportDateTestCase(TestCase):
  20. def test_it_works(self):
  21. # October
  22. nao = dt(year=2019, month=10, day=15, hour=6)
  23. result = choose_next_report_date(nao)
  24. self.assertEqual(result.year, 2019)
  25. self.assertEqual(result.month, 11)
  26. self.assertEqual(result.day, 1)
  27. self.assertTrue(result.hour >= 12)
  28. # December
  29. nao = dt(year=2019, month=12, day=15, hour=6)
  30. result = choose_next_report_date(nao)
  31. self.assertEqual(result.year, 2020)
  32. self.assertEqual(result.month, 1)
  33. self.assertEqual(result.day, 1)
  34. self.assertTrue(result.hour >= 12)