# Path: wwwhisper_auth/models.py
# class LimitExceeded(Exception):
#     pass
# 
# Path: wwwhisper_auth/models.py
# class SitesCollection(object):
#     def create_item(self, site_id, **kwargs):
#         """Creates a new Site object.
# 
#         Args:
#            site_id: A domain or other id of the created site.
#         Raises:
#            ValidationError if a site with a given id already exists.
#         """
#         site =  Site.objects.create(site_id=site_id, **kwargs)
#         site.heavy_init()
#         return site
# 
#     def find_item(self, site_id):
#         site = _find(Site, site_id=site_id)
#         if site is not None:
#             site.heavy_init()
#         return site
# 
#     def delete_item(self, site_id):
#         site = self.find_item(site_id)
#         if site is None:
#             return False
#         # Users, Locations and Permissions have foreign key to the Site
#         # and are deleted automatically.
#         site.delete()
#         return True


from django.db import transaction
from django.forms import ValidationError
from django.test import TestCase
from contextlib import contextmanager
from functools import wraps
from wwwhisper_auth.models import LimitExceeded
from wwwhisper_auth.models import SitesCollection
        self.aliases.create_item('http://example.org')
        with self.assert_site_not_modified(self.site):
            self.assertRaisesRegexp(ValidationError,
                                    'already exists',
                                    self.aliases.create_item,
                                    'http://example.org:80')

    def test_alias_for_different_site_can_duplicate(self):
        alias = self.aliases.create_item('http://example.org:123')
        self.assertIsNotNone(alias)
        alias = self.site2.aliases.create_item('http://example.org:123')
        self.assertIsNotNone(alias)

    def test_find_alias_by_url(self):
        self.assertIsNone(self.aliases.find_item_by_url(TEST_SITE))
        alias1 = self.aliases.create_item(TEST_SITE)
        with self.assert_site_not_modified(self.site):
            alias2 = self.aliases.find_item_by_url(TEST_SITE)
        self.assertIsNotNone(alias2)
        self.assertEqual(alias1, alias2)

    def test_find_alias_by_url_different_site(self):
        self.aliases.create_item(TEST_SITE)
        self.assertIsNone(self.site2.aliases.find_item_by_url(TEST_SITE))

    def test_aliases_limit(self):
        limit = 10
        self.site.aliases_limit = limit
        for i in range(0, limit):
            self.aliases.create_item('http://foo%d.org' % (i))

# Path: wwwhisper_auth/models.py
# class LimitExceeded(Exception):
#     pass
# 
# Path: wwwhisper_auth/models.py
# class SitesCollection(object):
#     def create_item(self, site_id, **kwargs):
#         """Creates a new Site object.
# 
#         Args:
#            site_id: A domain or other id of the created site.
#         Raises:
#            ValidationError if a site with a given id already exists.
#         """
#         site =  Site.objects.create(site_id=site_id, **kwargs)
#         site.heavy_init()
#         return site
# 
#     def find_item(self, site_id):
#         site = _find(Site, site_id=site_id)
#         if site is not None:
#             site.heavy_init()
#         return site
# 
#     def delete_item(self, site_id):
#         site = self.find_item(site_id)
#         if site is None:
#             return False
#         # Users, Locations and Permissions have foreign key to the Site
#         # and are deleted automatically.
#         site.delete()
#         return True


# Path: wwwhisper_auth/tests/tests_models.py
from django.db import transaction
from django.forms import ValidationError
from django.test import TestCase
from contextlib import contextmanager
from functools import wraps
from wwwhisper_auth.models import LimitExceeded
from wwwhisper_auth.models import SitesCollection

        self.aliases.create_item('http://example.org')
        with self.assert_site_not_modified(self.site):
            self.assertRaisesRegexp(ValidationError,
                                    'already exists',
                                    self.aliases.create_item,
                                    'http://example.org:80')

    def test_alias_for_different_site_can_duplicate(self):
        alias = self.aliases.create_item('http://example.org:123')
        self.assertIsNotNone(alias)
        alias = self.site2.aliases.create_item('http://example.org:123')
        self.assertIsNotNone(alias)

    def test_find_alias_by_url(self):
        self.assertIsNone(self.aliases.find_item_by_url(TEST_SITE))
        alias1 = self.aliases.create_item(TEST_SITE)
        with self.assert_site_not_modified(self.site):
            alias2 = self.aliases.find_item_by_url(TEST_SITE)
        self.assertIsNotNone(alias2)
        self.assertEqual(alias1, alias2)

    def test_find_alias_by_url_different_site(self):
        self.aliases.create_item(TEST_SITE)
        self.assertIsNone(self.site2.aliases.find_item_by_url(TEST_SITE))

    def test_aliases_limit(self):
        limit = 10
        self.site.aliases_limit = limit
        for i in range(0, limit):
            self.aliases.create_item('http://foo%d.org' % (i))

        self.assertRaisesRegexp(LimitExceeded,