# Path: app/accounts/models.py
# class UserProfile(models.Model):
#     """
#     Models extra information about users that are not built into Django's default user model.
# 
#     Example of extra information can be google user id, facebook user id, etc.
#     """
# 
#     user = models.OneToOneField(User, on_delete=models.CASCADE, related_name="profile")
#     custom_auth_id = models.CharField(max_length=255, blank=True)
#     facebook_oauth_id = models.CharField(max_length=255, blank=True)
#     google_oauth_id = models.CharField(max_length=255, blank=True)
#     twitter_oauth_id = models.CharField(max_length=255, blank=True)
# 
#     def __str__(self):
#         return self.user.username
# 
# Path: app/timetables/factories.py
# class UserFactory(DjangoModelFactory):
#     """Django admin user model factory."""
# 
#     class Meta:
#         model = get_user_model()
# 
#     username = 'admin'
#     email = 'admin@admin.com'
#     password = 'adminpassword'
#     is_superuser = True
#     is_active = True


from django.db import IntegrityError
from django.test import TestCase
from app.accounts.models import UserProfile
from app.timetables.factories import UserFactory



class UserProfileTest(TestCase):
    """Test UserProfile model"""

    def setUp(self):
        self.user = UserFactory()

    def test_user_can_only_have_one_profile_entry(self):
        profile = UserProfile(user=self.user, custom_auth_id='134664323567')
        self.assertRaises(IntegrityError, profile.save)

    def test_profile_is_created_on_user_creation(self):

# Path: app/accounts/models.py
# class UserProfile(models.Model):
#     """
#     Models extra information about users that are not built into Django's default user model.
# 
#     Example of extra information can be google user id, facebook user id, etc.
#     """
# 
#     user = models.OneToOneField(User, on_delete=models.CASCADE, related_name="profile")
#     custom_auth_id = models.CharField(max_length=255, blank=True)
#     facebook_oauth_id = models.CharField(max_length=255, blank=True)
#     google_oauth_id = models.CharField(max_length=255, blank=True)
#     twitter_oauth_id = models.CharField(max_length=255, blank=True)
# 
#     def __str__(self):
#         return self.user.username
# 
# Path: app/timetables/factories.py
# class UserFactory(DjangoModelFactory):
#     """Django admin user model factory."""
# 
#     class Meta:
#         model = get_user_model()
# 
#     username = 'admin'
#     email = 'admin@admin.com'
#     password = 'adminpassword'
#     is_superuser = True
#     is_active = True


# Path: app/accounts/tests/test_models.py
from django.db import IntegrityError
from django.test import TestCase
from app.accounts.models import UserProfile
from app.timetables.factories import UserFactory




class UserProfileTest(TestCase):
    """Test UserProfile model"""

    def setUp(self):
        self.user = UserFactory()

    def test_user_can_only_have_one_profile_entry(self):
        profile = UserProfile(user=self.user, custom_auth_id='134664323567')
        self.assertRaises(IntegrityError, profile.save)

    def test_profile_is_created_on_user_creation(self):

        user_profile = UserProfile.objects.get(user=self.user)