'Test the {% localtime %} templatetag and related filters.'

@requires_tz_support
def test_localtime_templatetag_and_filters(self):

    datetimes = {u'utc': datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC), u'eat': datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=EAT), u'ict': datetime.datetime(2011, 9, 1, 17, 20, 30, tzinfo=ICT), u'naive': datetime.datetime(2011, 9, 1, 13, 20, 30)}
    templates = {u'notag': Template(u'{%    load    tz    %}{{    dt    }}|{{    dt|localtime    }}|{{    dt|utc    }}|{{    dt|timezone:ICT    }}'), u'noarg': Template(u'{%    load    tz    %}{%    localtime    %}{{    dt    }}|{{    dt|localtime    }}|{{    dt|utc    }}|{{    dt|timezone:ICT    }}{%    endlocaltime    %}'), u'on': Template(u'{%    load    tz    %}{%    localtime    on    %}{{    dt    }}|{{    dt|localtime    }}|{{    dt|utc    }}|{{    dt|timezone:ICT    }}{%    endlocaltime    %}'), u'off': Template(u'{%    load    tz    %}{%    localtime    off    %}{{    dt    }}|{{    dt|localtime    }}|{{    dt|utc    }}|{{    dt|timezone:ICT    }}{%    endlocaltime    %}')}
    def t(*result):
        return u'|'.join((datetimes[key].isoformat() for key in result))
    results = {u'utc': {u'notag': t(u'eat', u'eat', u'utc', u'ict'), u'noarg': t(u'eat', u'eat', u'utc', u'ict'), u'on': t(u'eat', u'eat', u'utc', u'ict'), u'off': t(u'utc', u'eat', u'utc', u'ict')}, u'eat': {u'notag': t(u'eat', u'eat', u'utc', u'ict'), u'noarg': t(u'eat', u'eat', u'utc', u'ict'), u'on': t(u'eat', u'eat', u'utc', u'ict'), u'off': t(u'eat', u'eat', u'utc', u'ict')}, u'ict': {u'notag': t(u'eat', u'eat', u'utc', u'ict'), u'noarg': t(u'eat', u'eat', u'utc', u'ict'), u'on': t(u'eat', u'eat', u'utc', u'ict'), u'off': t(u'ict', u'eat', u'utc', u'ict')}, u'naive': {u'notag': t(u'naive', u'eat', u'utc', u'ict'), u'noarg': t(u'naive', u'eat', u'utc', u'ict'), u'on': t(u'naive', u'eat', u'utc', u'ict'), u'off': t(u'naive', u'eat', u'utc', u'ict')}}
    for (k1, dt) in six.iteritems(datetimes):
        for (k2, tpl) in six.iteritems(templates):
            ctx = Context({u'dt': dt, u'ICT': ICT})
            actual = tpl.render(ctx)
            expected = results[k1][k2]
            self.assertEqual(actual, expected, (u'%s    /    %s:    %r    !=    %r' % (k1, k2, actual, expected)))
    results[u'utc'][u'notag'] = t(u'utc', u'eat', u'utc', u'ict')
    results[u'ict'][u'notag'] = t(u'ict', u'eat', u'utc', u'ict')
    with self.settings(USE_TZ=False):
        for (k1, dt) in six.iteritems(datetimes):
            for (k2, tpl) in six.iteritems(templates):
                ctx = Context({u'dt': dt, u'ICT': ICT})
                actual = tpl.render(ctx)
                expected = results[k1][k2]
                self.assertEqual(actual, expected, (u'%s    /    %s:    %r    !=    %r' % (k1, k2, actual, expected)))
