I am writing a test case for my model to test the __str__ but apparently it is failing.
Here is my tests.py:
from todoapp.models import User, Task
from django.test import TestCase
class UserModelTest(TestCase):
def setUp(self):
self.user = User.objects.create(
first_name='john',
last_name='doe',
email='[email protected]',
password='johndoe')
def test_string_representation(self):
object_name = User.objects.get(id=50)
expected_object_name = object_name.email
self.assertEqual(expected_object_name, str(object_name))
Here is my models.py:
class User(AbstractUser):
username = None
email = models.EmailField(unique=True)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['first_name', 'last_name']
def __str__(self):
return self.email
P.S.:
A user with id=50 already exists