def test_today_timezone(self, mock_now): """Values are normalized to local time correctly.""" d = datetime.datetime(2012, 1, 2, 23, 10, tzinfo=denver) with timezone.override(denver): assert serializers.naturaldatetime(d) == u"11:10pm" with timezone.override(timezone.utc): assert serializers.naturaldatetime(d) == u"6:10am"
def test_timezone_naive(self, mock_now): """A naive datetime is assumed to be local time.""" d = datetime.datetime(2012, 1, 15, 10, 34) with timezone.override(denver): assert serializers.naturaldatetime(d) == u"Jan 15 2012, 10:34am"
def test_different_year(self, mock_now): """A date in a different year is date and time with year.""" d = datetime.datetime(2012, 1, 15, 10, 34, tzinfo=timezone.utc) assert serializers.naturaldatetime(d) == u"Jan 15 2012, 10:34am"
def test_same_year(self, mock_now): """A date within the current year is date and time without year.""" d = datetime.datetime(2013, 1, 15, 8, 12, tzinfo=timezone.utc) assert serializers.naturaldatetime(d) == u"Jan 15, 8:12am"
def test_day_of_week(self, mock_now): """A date within the past week is rendered as weekday and time.""" d = datetime.datetime(2013, 2, 5, 15, 45, tzinfo=timezone.utc) assert serializers.naturaldatetime(d) == u"Tue 3:45pm"
def test_today(self, mock_now): """A date today is rendered as just the time.""" d = datetime.datetime(2012, 1, 3, 8, 23, tzinfo=timezone.utc) assert serializers.naturaldatetime(d) == u"8:23am"