test.py 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. from basic_event import basic_event
  2. from almanaque import Almanaque
  3. from datetime import datetime, timedelta
  4. from dateutil.relativedelta import relativedelta
  5. import icalendar
  6. import unittest
  7. class TestMyModule(unittest.TestCase):
  8. #Yearly
  9. def test_FREQ_YEARLY(self):
  10. a = Almanaque()
  11. a.event_list.append(basic_event("test", datetime.today(), datetime.today(), icalendar.vRecur({'FREQ': ['YEARLY']})))
  12. self.assertTrue(a.freq(0, datetime.today()))
  13. def test_FREQ_BYDAY_YEARLY(self):
  14. a = Almanaque()
  15. a.event_list.append(basic_event("test", datetime.today(), datetime.today(), icalendar.vRecur({'FREQ': ['YEARLY'], 'BYDAY': ['2']})))
  16. self.assertEqual(a.freq(0, datetime.today()), True)
  17. self.assertTrue(a.freq(0, datetime.today()))
  18. def test_FREQ_BYDAYMONTH_YEARLY(self):
  19. a = Almanaque()
  20. a.event_list.append(basic_event("test", datetime.today(), datetime.today(), icalendar.vRecur({'FREQ': ['YEARLY'], 'BYMONTHDAY' : ['2']})))
  21. self.assertTrue(a.freq(0, datetime.today()))
  22. def test_FREQ_OTHER_YEARLY(self):
  23. a = Almanaque()
  24. a.event_list.append(basic_event("test", datetime.today(), datetime.today(), icalendar.vRecur({'FREQ': ['YEARLY']})))
  25. self.assertFalse(a.freq(0, datetime.today() + timedelta(1)))
  26. def test_FREQ_INTERVAL_YEARLY(self):
  27. a = Almanaque()
  28. a.event_list.append(basic_event("test", datetime.today(), datetime.today(), icalendar.vRecur({'FREQ': ['YEARLY'], 'INTERVAL': [2]})))
  29. date1 = datetime.today() + relativedelta(years=+2)
  30. self.assertTrue(a.freq(0, date1))
  31. #Monthly
  32. def test_FREQ_MONTHLY(self):
  33. a = Almanaque()
  34. a.event_list.append(basic_event("test", datetime.today(), datetime.today(), icalendar.vRecur({'FREQ': ['MONTHLY']})))
  35. self.assertTrue(a.freq(0, datetime.today()))
  36. def test_FREQ_BYDAY_MONTHLY(self):
  37. a = Almanaque()
  38. a.event_list.append(basic_event("test", datetime.today(), datetime.today(), icalendar.vRecur({'FREQ': ['MONTHLY'], 'BYDAY': ['2']})))
  39. self.assertEqual(a.freq(0, datetime.today()), True)
  40. self.assertTrue(a.freq(0, datetime.today()))
  41. def test_FREQ_BYDAYMONTH_MONTHLY(self):
  42. a = Almanaque()
  43. a.event_list.append(basic_event("test", datetime.today(), datetime.today(), icalendar.vRecur({'FREQ': ['MONTHLY'], 'BYMONTHDAY' : ['2']})))
  44. self.assertTrue(a.freq(0, datetime.today()))
  45. def test_FREQ_OTHER_MONTHLY(self):
  46. a = Almanaque()
  47. a.event_list.append(basic_event("test", datetime.today(), datetime.today(), icalendar.vRecur({'FREQ': ['MONTHLY']})))
  48. self.assertFalse(a.freq(0, datetime.today() + timedelta(1)))
  49. def test_FREQ_INTERVAL_MONTHLY(self):
  50. a = Almanaque()
  51. today = datetime(1956, 12, 5)
  52. a.event_list.append(basic_event("test", today, today, icalendar.vRecur({'FREQ': ['MONTHLY'], 'INTERVAL': [2]})))
  53. date1 = today + relativedelta(months=2)
  54. self.assertTrue(a.freq(0, date1))
  55. #WEEKLY
  56. def test_FREQ_WEEKLY(self):
  57. a = Almanaque()
  58. a.event_list.append(basic_event("test", datetime.today(), datetime.today(), icalendar.vRecur({'FREQ': ['WEEKLY']})))
  59. self.assertTrue(a.freq(0, datetime.today()))
  60. def test_FREQ_BYDAY_WEEKLY(self):
  61. a = Almanaque()
  62. a.event_list.append(basic_event("test", datetime.today(), datetime.today(), icalendar.vRecur({'FREQ': ['WEEKLY'], 'BYDAY': ['2']})))
  63. self.assertEqual(a.freq(0, datetime.today()), True)
  64. self.assertTrue(a.freq(0, datetime.today()))
  65. def test_FREQ_BYDAYMONTH_WEEKLY(self):
  66. a = Almanaque()
  67. a.event_list.append(basic_event("test", datetime.today(), datetime.today(), icalendar.vRecur({'FREQ': ['WEEKLY'], 'BYMONTHDAY' : ['2']})))
  68. self.assertTrue(a.freq(0, datetime.today()))
  69. def test_FREQ_OTHER_WEEKLY(self):
  70. a = Almanaque()
  71. a.event_list.append(basic_event("test", datetime.today(), datetime.today(), icalendar.vRecur({'FREQ': ['WEEKLY']})))
  72. self.assertFalse(a.freq(0, datetime.today() + timedelta(1)))
  73. def test_FREQ_INTERVAL_WEEKLY(self):
  74. a = Almanaque()
  75. a.event_list.append(basic_event("test", datetime.today(), datetime.today(), icalendar.vRecur({'FREQ': ['WEEKLY'], 'INTERVAL': [2]})))
  76. date1 = datetime.today() + relativedelta(weeks=+2)
  77. self.assertTrue(a.freq(0, date1))
  78. #DAILY
  79. def test_FREQ(self):
  80. a = Almanaque()
  81. a.event_list.append(basic_event("test", datetime.today(), datetime.today(), icalendar.vRecur({'FREQ': ['DAILY']})))
  82. self.assertTrue(a.freq(0, datetime.today()))
  83. def test_FREQ_INTERVAL(self):
  84. a = Almanaque()
  85. a.event_list.append(basic_event("test", datetime.today(), datetime.today(), icalendar.vRecur({'FREQ': ['DAILY'], 'INTERVAL': [2]})))
  86. date1 = datetime.today() + relativedelta(days=+2)
  87. self.assertTrue(a.freq(0, date1))
  88. #BYYEARDAY
  89. def test_BYYEARDAY(self):
  90. a = Almanaque()
  91. today = datetime(2020, 7, 31)
  92. a.event_list.append(basic_event("test", today, today, icalendar.vRecur({'FREQ': ['DAILY'], 'BYYEARDAY': 213})))
  93. self.assertTrue(a.byyearday(0, today))
  94. #BYWEEKNO
  95. def test_BYWEEKNO(self):
  96. a = Almanaque()
  97. today = datetime(2020, 7, 31)
  98. a.event_list.append(basic_event("test", today, today, icalendar.vRecur({'FREQ': ['DAILY'], 'BYWEEKNO': 31})))
  99. self.assertTrue(a.byweekno(0, today))
  100. #BYSECOND
  101. def test_BYSECOND(self):
  102. a = Almanaque()
  103. today = datetime(2020, 7, 31,18,22,23)
  104. a.event_list.append(basic_event("test", datetime.today(), datetime.today(), icalendar.vRecur({'FREQ': ['DAILY'], 'BYSECOND': 23})))
  105. self.assertTrue(a.bysecond(0, today))
  106. #BYYEAR
  107. def test_BYYEAR(self):
  108. a = Almanaque()
  109. today = datetime(2020, 7, 31)
  110. a.event_list.append(basic_event("test", datetime.today(), datetime.today(), icalendar.vRecur({'FREQ': ['DAILY'], 'BYYEAR': 2020})))
  111. self.assertTrue(a.byyear(0, datetime.today()))
  112. #check_byday_array
  113. def test_byday_array(self):
  114. a = Almanaque()
  115. array = []
  116. days = ['MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU']
  117. i = 0
  118. today = datetime(2020, 8, 3)
  119. a.event_list.append(basic_event("test", today, today, icalendar.vRecur({'FREQ': ['DAILY'], 'BYDAY': 2020})))
  120. while(i < len(days)):
  121. temporal_array = []
  122. a.event_list[0].start = today
  123. temporal_array.append(days[i])
  124. self.assertTrue(a.check_byday_array(temporal_array, i, today))
  125. today = today + timedelta(1)
  126. i += 1
  127. def test_byday_array_week(self):
  128. a = Almanaque()
  129. i = 1
  130. today = datetime(2020, 7, 1)
  131. a.event_list.append(basic_event("test", today, today, icalendar.vRecur({'FREQ': ['WEEKLY'], 'BYDAY': ['1WE']})))
  132. while(i < 6):
  133. temporal_array = []
  134. rrule_byday = str(i)+ 'WE'
  135. temporal_array.append(rrule_byday)
  136. self.assertTrue(a.check_byday_array(temporal_array, 2, today))
  137. today = today + timedelta(7)
  138. i += 1
  139. #check_week_number
  140. def test_check_week_number(self):
  141. a = Almanaque()
  142. today = datetime(2020, 8, 5)
  143. a.event_list.append(basic_event("test", today, today, icalendar.vRecur({'FREQ': ['WEEKLY'], 'BYDAY': ['1WE']})))
  144. self.assertTrue(a.check_week_number(2, 1, today))
  145. #byday
  146. def test_byday_method(self):
  147. a = Almanaque()
  148. today = datetime(2020, 8, 5)
  149. a.event_list.append(basic_event("test", today, today, icalendar.vRecur({'FREQ': ['WEEKLY'], 'BYDAY': ['1WE']})))
  150. self.assertTrue(a.byday(0, today))
  151. #bymonthday
  152. def test_bymonthday_method(self):
  153. a = Almanaque()
  154. today = datetime(2020, 8, 5)
  155. a.event_list.append(basic_event("test", today, today, icalendar.vRecur({'FREQ': ['WEEKLY'], 'BYMONTHDAY': [5]})))
  156. self.assertTrue(a.bymonthday(0, today))
  157. #bymonth
  158. def test_bymonth_method(self):
  159. a = Almanaque()
  160. today = datetime(2020, 8, 5)
  161. a.event_list.append(basic_event("test", today, today, icalendar.vRecur({'FREQ': ['WEEKLY'], 'BYMONTH': [8]})))
  162. self.assertTrue(a.bymonth(0, today))
  163. #bymonth
  164. def test_until(self):
  165. a = Almanaque()
  166. today = datetime(2020, 8, 5)
  167. a.event_list.append(basic_event("test", today, today, icalendar.vRecur({'FREQ': ['WEEKLY'], 'UNTIL': [datetime(2020, 8, 8, 0, 0)]})))
  168. self.assertTrue(a.until(0, today))
  169. self.assertFalse(a.until(0, today + timedelta(20)))
  170. def test_count(self):
  171. a = Almanaque()
  172. today = datetime(2020, 8, 5)
  173. a.event_list.append(basic_event("test", today, today, icalendar.vRecur({'FREQ': ['WEEKLY'], 'COUNT': [2]})))
  174. self.assertTrue(a.count(0))
  175. if __name__ == "__main__":
  176. unittest.main()