Пример #1
0
    def testIssueEmbargoed(self):
        self.assertFalse(self.issue_1.embargoed())
        self.assertFalse(self.issue_2.embargoed())
        self.assertTrue(self.issue_3.embargoed())

        start_of_month = date.today().replace(day=1)

        if int(getattr(settings, 'MAGAZINE_EMBARGO_TIME_IN_MONTHS', 2)) > 0:
            twenty_d_from_start = start_of_month - timedelta(days=20)
            issue = Issue.objects.create(number=4,
                                         issue_date=twenty_d_from_start)
            issue_4 = Issue.objects.get(pk=issue.pk)
            self.assertTrue(issue_4.embargoed())

            embargo_key = 'MAGAZINE_EMBARGO_TIME_IN_MONTHS'
            magazine_embargo_months = int(getattr(settings,
                                                  embargo_key, 2))
            issue_4.issue_date = subtract_n_months(start_of_month,
                                                   magazine_embargo_months - 1)
            issue_4.save()
            self.assertTrue(issue_4.embargoed())

            issue_4.issue_date = subtract_n_months(start_of_month,
                                                   magazine_embargo_months)
            issue_4.save()
            self.assertFalse(issue_4.embargoed())
Пример #2
0
 def testWithDateAtMiddleOfYear(self):
     self.assertEqual(subtract_n_months(date(2010, 4, 7), 2),
                      date(2010, 2, 7))
Пример #3
0
 def testWithMoreThan12Months(self):
     self.assertEqual(subtract_n_months(date(2010, 3, 31), 25),
                      date(2008, 2, 29))
     self.assertEqual(subtract_n_months(date(2010, 3, 31), 37),
                      date(2007, 2, 28))
Пример #4
0
 def testWithDateAtBeginningOfYearAtEndOfMonth(self):
     self.assertEqual(subtract_n_months(date(2010, 3, 31), 4),
                      date(2009, 11, 30))
Пример #5
0
 def testWithDateAtBeginningOfYear(self):
     self.assertEqual(subtract_n_months(date(2010, 1, 31), 1),
                      date(2009, 12, 31))
Пример #6
0
 def testWithDateAtEndOfMonth(self):
     # September only has 30 days
     self.assertEqual(subtract_n_months(date(2010, 10, 31), 1),
                      date(2010, 9, 30))