# 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
        with transaction.atomic():
            self.users.create_item('uSeR@bar.com')
        with transaction.atomic():
            with self.assert_site_not_modified(self.site):
                self.assertRaisesRegexp(ValidationError,
                                        'User already exists',
                                        self.users.create_item,
                                       'UsEr@bar.com')

    def test_create_user_twice_for_different_sites(self):
        self.users.create_item(TEST_USER_EMAIL)
        with self.assert_site_not_modified(self.site):
            with self.assert_site_modified(self.site2):
                self.site2.users.create_item(TEST_USER_EMAIL)
        # Should not raise

    def test_delete_user_twice(self):
        user = self.users.create_item(TEST_USER_EMAIL)
        self.assertTrue(self.users.delete_item(user.uuid))
        self.assertFalse(self.users.delete_item(user.uuid))

    def test_delete_user_different_site(self):
        user = self.users.create_item(TEST_USER_EMAIL)
        self.assertFalse(self.site2.users.delete_item(user.uuid))

    def test_get_all_users(self):
        user1 = self.users.create_item('foo@example.com')
        user2 = self.users.create_item('bar@example.com')
        user3 = self.site2.users.create_item('baz@example.com')
        self.assertEqual(2, self.users.count())

# 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

        with transaction.atomic():
            self.users.create_item('uSeR@bar.com')
        with transaction.atomic():
            with self.assert_site_not_modified(self.site):
                self.assertRaisesRegexp(ValidationError,
                                        'User already exists',
                                        self.users.create_item,
                                       'UsEr@bar.com')

    def test_create_user_twice_for_different_sites(self):
        self.users.create_item(TEST_USER_EMAIL)
        with self.assert_site_not_modified(self.site):
            with self.assert_site_modified(self.site2):
                self.site2.users.create_item(TEST_USER_EMAIL)
        # Should not raise

    def test_delete_user_twice(self):
        user = self.users.create_item(TEST_USER_EMAIL)
        self.assertTrue(self.users.delete_item(user.uuid))
        self.assertFalse(self.users.delete_item(user.uuid))

    def test_delete_user_different_site(self):
        user = self.users.create_item(TEST_USER_EMAIL)
        self.assertFalse(self.site2.users.delete_item(user.uuid))

    def test_get_all_users(self):
        user1 = self.users.create_item('foo@example.com')
        user2 = self.users.create_item('bar@example.com')
        user3 = self.site2.users.create_item('baz@example.com')
        self.assertEqual(2, self.users.count())

        self.assertEqual(1, self.site2.users.count())