import datetime
from pytz import timezone

from django.test import TestCase

from ..subscriptions import Subscription


class SubscriptionFixture(TestCase):

    eastern = timezone("US/Eastern")
    title = "test title"
    start_date = datetime.datetime(2013, 1, 1, tzinfo=eastern)
    duration = 12
    expected_first_issue = datetime.datetime(2013, 1, 3, tzinfo=eastern)
    expected_last_issue = datetime.datetime(2014, 1, 2, tzinfo=eastern)

    def setUp(self):
        self.result = Subscription(self.title, self.start_date, self.duration)

    def test_set_startdate(self):
        first_issue = Subscription._calculate_first_issue(self.start_date)

    def test(self):
        self.assertEquals(self.result.title, self.title)
        self.assertEquals(self.result.purchase_date, self.start_date)
        self.assertEquals(self.result.duration, self.duration)
        self.assertEquals(self.result.first_issue, self.expected_first_issue)
        self.assertEquals(self.result.last_issue, self.expected_last_issue)


class BrokenDate(SubscriptionFixture):

    eastern = timezone("US/Eastern")
    start_date = datetime.datetime(2013, 3, 2, tzinfo=eastern)
    expected_first_issue = datetime.datetime(2013, 3, 7, tzinfo=eastern)
    expected_last_issue = datetime.datetime(2014, 3, 6, tzinfo=eastern)
