mardi 18 décembre 2018

Unit testing CRUD functions in Django

I am trying to create a basic unit test for my code. Here is what I'm running...

from django.test import TestCase
from django.contrib.auth.models import User
from feed.models import Post

class PostTests(TestCase):

 def setUp(self):
    user = User.objects.first()
    Post.objects.create(title='test', content='more testing', author=user)

 def test_content(self):
    post = Post.objects.get(id=1)
    expected_object_name = f'{post.content}'
    self.assertEquals(expected_object_name, 'more testing')

The error I'm getting is "django.db.utils.IntegrityError: (1048, "Column 'author_id' cannot be null")" I believe the error is finding the user but when I run it in the shell it updates with no problems.

Aucun commentaire:

Enregistrer un commentaire