# Path: html5_appcache/cache.py
# def get_cached_manifest():
#     return get_cached_value("manifest")
# 
# def set_cached_manifest(manifest):
#     """
#     When setting new manifest, both versions are updated.
#     """
#     set_cached_value("data_clean", 1)
#     set_cached_value("manifest", manifest, 1)
#     set_cached_value("manifest", manifest, 2)
# 
# def clear_cache_manifest():
#     """
#     Clear all the values in the cache for both version
#     """
#     for key in manifest_cache_keys:
#         set_cached_value(key, None, 1)
#         set_cached_value(key, None, 2)
# 
# def get_cache_version():
#     return get_cached_value("data_clean", 1)
# 
# def reset_cache_manifest():
#     """
#     Move to version 2 (meaning stale data).
#     """
#     set_cached_value("data_clean", 2)
# 
# def set_cached_value(key, value, version=1):
#     from django.core.cache import cache
#     return cache.set(get_cache_key(key), value, get_setting('CACHE_DURATION'),
#                      version=version)
# 
# Path: html5_appcache/views.py
# class ManifestAppCache(TemplateView):
#     """
#     Basic template view.
#     It just get the temlate from AppCacheManager and wrap it in a response
#     """
#     template_name = "html5_appcache/manifest"
#     appcache_update = 0
#     force_empty_manifest = False
# 
#     def _do_update(self, request, appcache_registry):
#         """ Actual update function """
#         if (request.user.is_authenticated() and
#                 request.user.has_perm('html5_appcache.can_update_manifest')):
#             appcache_registry.extract_urls()
#             return appcache_registry.get_manifest(update=True)
#         else:
#             return None
# 
#     def get(self, request, *args, **kwargs):
#         empty_manifest = render_to_string(self.template_name, dictionary={
#             'version': 0, 'date': '-', 'network_urls': ['*']
#         })
#         manifest = None
#         if not get_setting("DISABLE"):
#             appcache_registry.setup(request, self.template_name)
#             if self.appcache_update:
#                 manifest = self._do_update(request, appcache_registry)
#                 if not manifest:
#                     return HttpResponseForbidden(
#                         _("Current user is not authorized for this action"))
#             else:
#                 manifest = appcache_registry.get_manifest()
#         if manifest and request.user.is_authenticated():
#             manifest += "\n# version %s" % "auth"
# 
#         if (not manifest or self.force_empty_manifest or
#                 kwargs.get("parameter", False) == 'empty'):
#             manifest = empty_manifest
#         return HttpResponse(content=manifest, content_type="text/cache-manifest")


from django.test import RequestFactory, TransactionTestCase
from html5_appcache.cache import (get_cached_manifest, set_cached_manifest,
                                  clear_cache_manifest, get_cache_version,
                                  reset_cache_manifest, set_cached_value)
from html5_appcache.views import ManifestAppCache
# -*- coding: utf-8 -*-



class CacheTest(TransactionTestCase):

    def setUp(self):
        super(CacheTest, self).setUp()
        clear_cache_manifest()

    def test_cache(self):
        self.assertIsNone(get_cache_version())
        self.assertIsNone(get_cached_manifest())
        set_cached_manifest("ciao")
        self.assertEqual(get_cache_version(), 1)

# Path: html5_appcache/cache.py
# def get_cached_manifest():
#     return get_cached_value("manifest")
# 
# def set_cached_manifest(manifest):
#     """
#     When setting new manifest, both versions are updated.
#     """
#     set_cached_value("data_clean", 1)
#     set_cached_value("manifest", manifest, 1)
#     set_cached_value("manifest", manifest, 2)
# 
# def clear_cache_manifest():
#     """
#     Clear all the values in the cache for both version
#     """
#     for key in manifest_cache_keys:
#         set_cached_value(key, None, 1)
#         set_cached_value(key, None, 2)
# 
# def get_cache_version():
#     return get_cached_value("data_clean", 1)
# 
# def reset_cache_manifest():
#     """
#     Move to version 2 (meaning stale data).
#     """
#     set_cached_value("data_clean", 2)
# 
# def set_cached_value(key, value, version=1):
#     from django.core.cache import cache
#     return cache.set(get_cache_key(key), value, get_setting('CACHE_DURATION'),
#                      version=version)
# 
# Path: html5_appcache/views.py
# class ManifestAppCache(TemplateView):
#     """
#     Basic template view.
#     It just get the temlate from AppCacheManager and wrap it in a response
#     """
#     template_name = "html5_appcache/manifest"
#     appcache_update = 0
#     force_empty_manifest = False
# 
#     def _do_update(self, request, appcache_registry):
#         """ Actual update function """
#         if (request.user.is_authenticated() and
#                 request.user.has_perm('html5_appcache.can_update_manifest')):
#             appcache_registry.extract_urls()
#             return appcache_registry.get_manifest(update=True)
#         else:
#             return None
# 
#     def get(self, request, *args, **kwargs):
#         empty_manifest = render_to_string(self.template_name, dictionary={
#             'version': 0, 'date': '-', 'network_urls': ['*']
#         })
#         manifest = None
#         if not get_setting("DISABLE"):
#             appcache_registry.setup(request, self.template_name)
#             if self.appcache_update:
#                 manifest = self._do_update(request, appcache_registry)
#                 if not manifest:
#                     return HttpResponseForbidden(
#                         _("Current user is not authorized for this action"))
#             else:
#                 manifest = appcache_registry.get_manifest()
#         if manifest and request.user.is_authenticated():
#             manifest += "\n# version %s" % "auth"
# 
#         if (not manifest or self.force_empty_manifest or
#                 kwargs.get("parameter", False) == 'empty'):
#             manifest = empty_manifest
#         return HttpResponse(content=manifest, content_type="text/cache-manifest")


# Path: html5_appcache/tests/cache.py
from django.test import RequestFactory, TransactionTestCase
from html5_appcache.cache import (get_cached_manifest, set_cached_manifest,
                                  clear_cache_manifest, get_cache_version,
                                  reset_cache_manifest, set_cached_value)
from html5_appcache.views import ManifestAppCache

# -*- coding: utf-8 -*-



class CacheTest(TransactionTestCase):

    def setUp(self):
        super(CacheTest, self).setUp()
        clear_cache_manifest()

    def test_cache(self):
        self.assertIsNone(get_cache_version())
        self.assertIsNone(get_cached_manifest())
        set_cached_manifest("ciao")
        self.assertEqual(get_cache_version(), 1)

        self.assertEqual(get_cached_manifest(), "ciao")