Example #1
0
 def test_filled_calendar(self):
     c = Calendar(nickname='CalendarMonth', year=2018, month=1)
     c.save()
     r1 = Recipe(title='Recipe')
     r2 = Recipe(title='Recipe2')
     r1.save()
     r2.save()
     c.day01recipe0 = r1
     c.day01recipe1 = r2
     c.day05recipe0 = r2
     c.day23recipe0 = r2
     c.day23recipe1 = r1
     c.day31recipe1 = r1
     c.save()
     self.assertEqual([None, None], c.get_recipes_for_day_of_month(
         'a'))  # might throw exception in the future
     self.assertEqual([None, None], c.get_recipes_for_day_of_month(
         -10))  # might throw exception in the future
     self.assertEqual([None, None], c.get_recipes_for_day_of_month(
         0))  # might throw exception in the future
     self.assertEqual([r1, r2], c.get_recipes_for_day_of_month(1))
     self.assertEqual([r2, None], c.get_recipes_for_day_of_month(5))
     self.assertEqual([r2, r1], c.get_recipes_for_day_of_month(23))
     self.assertEqual([None, r1], c.get_recipes_for_day_of_month(31))
     self.assertEqual([None, None], c.get_recipes_for_day_of_month(
         32))  # might throw exception in the future
Example #2
0
 def test_calendar_with_one_day_filled(self):
     c = Calendar(year=2018, month=5)
     r = Recipe(title='temporary')
     r.save()
     c.day01recipe0 = r
     c.day01recipe1 = r
     c.save()
     url_path = reverse('planner:api:calendar-monthly-data', args=[1])
     response = self.client.get(url_path)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     response_data = response.json()
     self.assertEqual(u'1', response_data['id'])
Example #3
0
 def test_calendar_shows_today_properly(self):
     today = datetime.datetime.now(tzlocal())
     c = Calendar(year=today.year, month=today.month)
     r = Recipe(title='temporary')
     r.save()
     c.day01recipe0 = r
     c.day01recipe1 = r
     c.save()
     url_path = reverse('planner:api:calendar-monthly-data', args=[1])
     response = self.client.get(url_path)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     response_data = response.json()
     date_data = response_data['data']
     for week in date_data:
         for day in week:
             if day['date_number'] == today.day:
                 self.assertTrue(day['is_today'])
             else:
                 self.assertFalse(day['is_today'])
 def setUp(self):
     r = Recipe()
     r.save()
Example #5
0
 def test_duplicate_recipe_titles_fails(self):
     self._add_recipe('Hey')
     r2 = Recipe(title='Hey')
     with self.assertRaises(IntegrityError):
         r2.save()