from django.test import TestCase
from django.contrib import auth
from django.contrib.auth import get_user_model

from accounts.models import Token

User = get_user_model()


class UserModelTest(TestCase):
    
    def test_user_is_valid_with_email_only(self):
        user = User(email='test@example.com')
        user.full_clean()

    def test_email_is_pk(self):
        user = User(email='test@example.com')
        self.assertEqual(user.pk, 'test@example.com')

    def test_no_problem_with_auth_login(self):
        user = User.objects.create(email='edith@example.com')
        user.backend = ''
        request = self.client.request().wsgi_request
        auth.login(request, user)

class TokenModelTest(TestCase):

    def test_link_user_with_autogenerated_uid(self):
        token_1 = Token.objects.create(email='test@example.com')
        token_2 = Token.objects.create(email='test@example.com')
        self.assertNotEqual(token_1.uid, token_2.uid)
