import unittest
from random import randrange
from utils import fancy_datetime
import datetime

class TestFancyDatetime(unittest.TestCase):
    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_seconds(self):
        time = datetime.datetime.now() - datetime.timedelta(seconds=randrange(0,60))
        self.assertEqual(fancy_datetime(time), "a few seconds ago")
        time = datetime.datetime.now() - datetime.timedelta(seconds=randrange(60,119))
        self.assertEqual(fancy_datetime(time), "1 minute ago")

    def test_minutes(self):
        delta = randrange(1, 60)
        time = datetime.datetime.now() - datetime.timedelta(minutes=delta)
        self.assertEqual(fancy_datetime(time), "%d minutes ago" % delta)

        delta = randrange(1, 59)
        delta2 = randrange(1, 60)
        time = datetime.datetime.now() - datetime.timedelta(minutes=delta,seconds=delta2)
        # seconds do not matter here
        self.assertEqual(fancy_datetime(time), "%d minutes ago" % delta)

    def test_minutes(self):
        delta = randrange(1, 60)
        time = datetime.datetime.now() - datetime.timedelta(minutes=delta)
        self.assertEqual(fancy_datetime(time), "%d minutes ago" % delta)

        hours_delta = randrange(1, 23)
        minutes_delta = randrange(1, 59)
        time = datetime.datetime.now() - datetime.timedelta(minutes=minutes_delta,
            hours=hours_delta)
        # once we are in the range of minutes, seconds do not matter!
        self.assertEqual(fancy_datetime(time), "%d hours, %d minutes ago" % (hours_delta,
            minutes_delta))

def suite():
   suite = unittest.TestSuite()
   suite.addTest(unittest.makeSuite(TestFancyDatetime))
   return suite

