def test_new_class(self):
        """Test a new class based on ``CacheTag``."""

        expected = "foobar  foo 1  !!"

        t = """
            {% load adv_cache_test %}
            {% cache_test 1 multiplicator test_cached_template obj.pk obj.updated_at %}
                {{ obj.get_name }}
                {% nocache_test %}
                    {{ obj.get_foo }}
                {% endnocache_test %}
                !!
            {% endcache_test %}
        """

        # Render a first time, should miss the cache
        self.assertStripEqual(self.render(t, {'multiplicator': 10}), expected)
        self.assertEqual(self.get_name_called, 1)
        self.assertEqual(self.get_foo_called, 1)

        # Now the rendered template should be in cache
        key = self.get_template_key('test_cached_template',
                                    vary_on=[self.obj['pk'], self.obj['updated_at']],
                                    prefix='template.cache_test')
        self.assertEqual(
            key, 'template.cache_test.test_cached_template.0cac9a03d5330dd78ddc9a0c16f01403')

        # It should be in the cache, with the RAW part
        cache_expected = b"1:: foobar {%endRAW_38a11088962625eb8c913e791931e2bc2e3c7228%} " \
                         b"{{obj.get_foo}} {%RAW_38a11088962625eb8c913e791931e2bc2e3c7228%} !! "
        self.assertStripEqual(get_cache('default').get(key), cache_expected)

        # We'll check that our multiplicator was really applied
        cache = get_cache('default')
        expire_at = cache._expire_info[cache.make_key(key, version=None)]
        now = time.time()
        # In more that one second (default expiry we set) and less than ten
        self.assertTrue(now + 1 < now + 10 < expire_at)

        # Render a second time, should hit the cache but not for ``get_foo``
        expected = "foobar  foo 2  !!"
        self.assertStripEqual(self.render(t, {'multiplicator': 10}), expected)
        self.assertEqual(self.get_name_called, 1)  # Still 1
        self.assertEqual(self.get_foo_called, 2)  # One more call to the non-cached part
dataset/ETHPy150Open twidi/django-adv-cache-tag/adv_cache_tag/tests/tests.py/BasicTestCase.test_new_class/swapped operands of `<`