# Path: wwwhisper_auth/site_cache.py
# class CachingSitesCollection(SitesCollection):
#     """Like models.SitesCollection but returns cached results when possible."""
# 
#     def __init__(self, site_cache=None):
#         if site_cache is None:
#             site_cache = SiteCache(CacheUpdater())
#         self.site_cache = site_cache
# 
#     def create_item(self, site_id, **kwargs):
#         site = super(CachingSitesCollection, self).create_item(
#             site_id=site_id, **kwargs)
#         self.site_cache.insert(site)
#         return site
# 
#     def find_item(self, site_id):
#         site = self.site_cache.get(site_id)
#         if site is not None:
#             return site
#         site = super(CachingSitesCollection, self).find_item(site_id=site_id)
#         if site is not None:
#             self.site_cache.insert(site)
#         return site
# 
#     def delete_item(self, site_id):
#         rv = super(CachingSitesCollection, self).delete_item(site_id=site_id)
#         self.site_cache.delete(site_id)
#         return rv
# 
# Path: wwwhisper_auth/site_cache.py
# class SiteCache(object):
#     def __init__(self, updater):
#         self._updater = updater
#         self._items = {}
# 
#     def insert(self, site):
#         self._items[site.site_id] = site
# 
#     def get(self, site_id):
#         site = self._items.get(site_id, None)
#         if site is None:
#             return None
#         if self._updater.is_obsolete(site):
#             self.delete(site_id)
#             return None
#         return site
# 
#     def delete(self, site_id):
#         self._items.pop(site_id, None)


from django.test import TestCase
from mock import Mock
from wwwhisper_auth.site_cache import CachingSitesCollection
from wwwhisper_auth.site_cache import SiteCache
# wwwhisper - web access control.
# Copyright (C) 2013 Jan Wrobel <jan@mixedbit.org>


TEST_SITE = 'https://example.com'

class FakeCacheUpdater(object):
    def __init__(self):
        self.return_value = False

    def is_obsolete(self, site):
        return self.return_value

class SiteCacheTest(TestCase):

    def setUp(self):

# Path: wwwhisper_auth/site_cache.py
# class CachingSitesCollection(SitesCollection):
#     """Like models.SitesCollection but returns cached results when possible."""
# 
#     def __init__(self, site_cache=None):
#         if site_cache is None:
#             site_cache = SiteCache(CacheUpdater())
#         self.site_cache = site_cache
# 
#     def create_item(self, site_id, **kwargs):
#         site = super(CachingSitesCollection, self).create_item(
#             site_id=site_id, **kwargs)
#         self.site_cache.insert(site)
#         return site
# 
#     def find_item(self, site_id):
#         site = self.site_cache.get(site_id)
#         if site is not None:
#             return site
#         site = super(CachingSitesCollection, self).find_item(site_id=site_id)
#         if site is not None:
#             self.site_cache.insert(site)
#         return site
# 
#     def delete_item(self, site_id):
#         rv = super(CachingSitesCollection, self).delete_item(site_id=site_id)
#         self.site_cache.delete(site_id)
#         return rv
# 
# Path: wwwhisper_auth/site_cache.py
# class SiteCache(object):
#     def __init__(self, updater):
#         self._updater = updater
#         self._items = {}
# 
#     def insert(self, site):
#         self._items[site.site_id] = site
# 
#     def get(self, site_id):
#         site = self._items.get(site_id, None)
#         if site is None:
#             return None
#         if self._updater.is_obsolete(site):
#             self.delete(site_id)
#             return None
#         return site
# 
#     def delete(self, site_id):
#         self._items.pop(site_id, None)


# Path: wwwhisper_auth/tests/tests_site_cache.py
from django.test import TestCase
from mock import Mock
from wwwhisper_auth.site_cache import CachingSitesCollection
from wwwhisper_auth.site_cache import SiteCache

# wwwhisper - web access control.
# Copyright (C) 2013 Jan Wrobel <jan@mixedbit.org>


TEST_SITE = 'https://example.com'

class FakeCacheUpdater(object):
    def __init__(self):
        self.return_value = False

    def is_obsolete(self, site):
        return self.return_value

class SiteCacheTest(TestCase):

    def setUp(self):

        self.updater = FakeCacheUpdater()