'Tests that when used in combination, the page is cached to the
shortest TTL.'

def test_expiration_cache_plugins(self):

    page1 = create_page('test    page    1', 'nav_playground.html', 'en', published=True)
    placeholder1 = page1.placeholders.filter(slot='body')[0]
    placeholder2 = page1.placeholders.filter(slot='right-column')[0]
    plugin_pool.register_plugin(TTLCacheExpirationPlugin)
    try:
        plugin_pool.register_plugin(DateTimeCacheExpirationPlugin)
    except PluginAlreadyRegistered:
        pass
    try:
        plugin_pool.register_plugin(NoCachePlugin)
    except PluginAlreadyRegistered:
        pass
    add_plugin(placeholder1, 'TextPlugin', 'en', body='English')
    add_plugin(placeholder2, 'TextPlugin', 'en', body='Deutsch')
    add_plugin(placeholder1, 'TTLCacheExpirationPlugin', 'en')
    add_plugin(placeholder2, 'DateTimeCacheExpirationPlugin', 'en')
    exclude = ['django.middleware.cache.UpdateCacheMiddleware', 'django.middleware.cache.CacheMiddleware', 'django.middleware.cache.FetchFromCacheMiddleware']
    overrides = dict()
    if getattr(settings, 'MIDDLEWARE', None):
        overrides['MIDDLEWARE'] = [mw for mw in settings.MIDDLEWARE if (mw not in exclude)]
    else:
        overrides['MIDDLEWARE_CLASSES'] = [mw for mw in settings.MIDDLEWARE_CLASSES if (mw not in exclude)]
    with self.settings(**overrides):
        page1.publish('en')
        request = self.get_request('/en/')
        request.current_page = Page.objects.get(pk=page1.pk)
        request.toolbar = CMSToolbar(request)
        with self.assertNumQueries(FuzzyInt(14, 26)):
            response = self.client.get('/en/')
            resp1 = response.content.decode('utf8').split('$$$')[1]
        self.assertTrue(('max-age=40' in response['Cache-Control']), response['Cache-Control'])
        cache_control1 = response['Cache-Control']
        expires1 = response['Expires']
        last_modified1 = response['Last-Modified']
        time.sleep(1)
        request = self.get_request('/en/')
        request.current_page = Page.objects.get(pk=page1.pk)
        request.toolbar = CMSToolbar(request)
        with self.assertNumQueries(0):
            response = self.client.get('/en/')
            resp2 = response.content.decode('utf8').split('$$$')[1]
        self.assertEqual(resp2, resp1)
        self.assertNotEqual(response['Cache-Control'], cache_control1)
        self.assertEqual(response['Expires'], expires1)
        self.assertEqual(response['Last-Modified'], last_modified1)
    plugin_pool.unregister_plugin(TTLCacheExpirationPlugin)
    plugin_pool.unregister_plugin(DateTimeCacheExpirationPlugin)
    plugin_pool.unregister_plugin(NoCachePlugin)
