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.

49 lines
1.5 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_sub_second_works(self):
  6. s = format_hms(td(seconds=0.12))
  7. self.assertEqual(s, "0.12 sec")
  8. def test_mins_secs_work(self):
  9. s = format_hms(td(seconds=0))
  10. self.assertEqual(s, "0 sec")
  11. s = format_hms(td(seconds=1))
  12. self.assertEqual(s, "1 sec")
  13. s = format_hms(td(seconds=61))
  14. self.assertEqual(s, "1 min 1 sec")
  15. s = format_hms(td(seconds=62))
  16. self.assertEqual(s, "1 min 2 sec")
  17. def test_hours_work(self):
  18. s = format_hms(td(seconds=62 + 60 * 60))
  19. self.assertEqual(s, "1 h 1 min 2 sec")
  20. s = format_hms(td(seconds=60 * 60))
  21. self.assertEqual(s, "1 h 0 min 0 sec")
  22. class NextReportDateTestCase(TestCase):
  23. def test_it_works(self):
  24. # October
  25. nao = dt(year=2019, month=10, day=15, hour=6)
  26. result = choose_next_report_date(nao)
  27. self.assertEqual(result.year, 2019)
  28. self.assertEqual(result.month, 11)
  29. self.assertEqual(result.day, 1)
  30. self.assertTrue(result.hour >= 12)
  31. # December
  32. nao = dt(year=2019, month=12, day=15, hour=6)
  33. result = choose_next_report_date(nao)
  34. self.assertEqual(result.year, 2020)
  35. self.assertEqual(result.month, 1)
  36. self.assertEqual(result.day, 1)
  37. self.assertTrue(result.hour >= 12)