Saturday, October 20, 2018

test error

I try to make a test with has an error
any suggestions?
tim


    expected_author = f'{post.author}
                                    ^
SyntaxError: EOL while scanning string literal


----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (errors=1)
Destroying test database for alias 'default'...
MacBook-Pro-15-Officerebel:blogapi timvogt$


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

from .models import Post

class BlogTests(TestCase):

@classmethod
def setUpTestData(cls):
#Create a user
testuser1 = User.objects.create_user(
username='testuser1', password='abc123')
testuser1.save()

# Create a blog post
test_post = Post.objects.create(
author=testuser1, title='Blog title', body='Body content...')
test_post.save()

def test_blog_content(self):
post = Post.objects.get(id=1)
expected_author = f'{post.author}'
expected_title = f'{post.title}'
expected_body = f'{post.body}'
self.assertEquals(expected_author, 'testuser1')
self.assertEquals(expected_title,'Blog title')
self.assertEquals(expected_body, 'Body content ...')

No comments:

Post a Comment