# Path: lazysignup/models.py
# class LazyUser(models.Model):
#     user = models.OneToOneField(constants.LAZYSIGNUP_USER_MODEL, on_delete=models.CASCADE)
#     created = models.DateTimeField(default=now, db_index=True)
#     objects = LazyUserManager()
# 
#     @classmethod
#     def get_user_class(cls):
#         related_user_field = cls._meta.get_field('user')
#         # Django < 1.9 has rel.to
#         if hasattr(related_user_field, 'rel'):
#             rel_to = related_user_field.rel.to if related_user_field.rel else None
#         elif hasattr(related_user_field, 'remote_field'):
#             rel_to = related_user_field.remote_field.model if related_user_field.remote_field else None
#         return rel_to
# 
#     def __str__(self):
#         return '{0}:{1}'.format(self.user, self.created)


from django.test import TestCase
from mock import Mock
from lazysignup.models import LazyUser



class LazyUserManagerTests(TestCase):
    """
    Tests for LazyUserManager
    """
    def test_generate_username_no_method(self):
        """
        Tests auto generated UUID username
        """
        mock_user_class = Mock(generate_username=1)
        del mock_user_class.generate_username

        mock_user_class._meta.get_field.return_value.max_length = 32

        username = LazyUser.objects.generate_username(mock_user_class)

        self.assertEqual(len(username), 32)

    def test_generate_username_has_method(self):
        """
        Tests auto generated UUID username
        """
        mock_user_class = Mock()
        mock_user_class.generate_username.return_value = 'testusername'


# Path: lazysignup/models.py
# class LazyUser(models.Model):
#     user = models.OneToOneField(constants.LAZYSIGNUP_USER_MODEL, on_delete=models.CASCADE)
#     created = models.DateTimeField(default=now, db_index=True)
#     objects = LazyUserManager()
# 
#     @classmethod
#     def get_user_class(cls):
#         related_user_field = cls._meta.get_field('user')
#         # Django < 1.9 has rel.to
#         if hasattr(related_user_field, 'rel'):
#             rel_to = related_user_field.rel.to if related_user_field.rel else None
#         elif hasattr(related_user_field, 'remote_field'):
#             rel_to = related_user_field.remote_field.model if related_user_field.remote_field else None
#         return rel_to
# 
#     def __str__(self):
#         return '{0}:{1}'.format(self.user, self.created)


# Path: lazysignup/tests/test_manager.py
from django.test import TestCase
from mock import Mock
from lazysignup.models import LazyUser




class LazyUserManagerTests(TestCase):
    """
    Tests for LazyUserManager
    """
    def test_generate_username_no_method(self):
        """
        Tests auto generated UUID username
        """
        mock_user_class = Mock(generate_username=1)
        del mock_user_class.generate_username

        mock_user_class._meta.get_field.return_value.max_length = 32

        username = LazyUser.objects.generate_username(mock_user_class)

        self.assertEqual(len(username), 32)

    def test_generate_username_has_method(self):
        """
        Tests auto generated UUID username
        """
        mock_user_class = Mock()
        mock_user_class.generate_username.return_value = 'testusername'


        username = LazyUser.objects.generate_username(mock_user_class)