• 카테고리

    질문 & 답변
  • 세부 분야

    풀스택

  • 해결 여부

    미해결

선생님 자꾸 self.author 가 Testview의 no attribute라고 뜹니다

20.03.21 13:45 작성 조회수 105

0

from django.test import TestCase, Client
from bs4 import BeautifulSoup
from .models import Post
from django.utils import timezone
from django.contrib.auth.models import User


class Testview(TestCase):
def setUP(self):
self.client = Client()
self.author_000 = User.objects.create(username='smith', password='nopassword')

def test_post_list(self):
response = self.client.get('/blog/')
self.assertEqual(response.status_code, 200)

soup = BeautifulSoup(response.content, 'html.parser')
title = soup.title
self.assertEqual(title.text, '컴퓨터-수업공부')

navbar = soup.find('div', id='navbar')
self.assertIn('Themes', navbar.text)
self.assertIn('영어독해', navbar.text)

self.assertEqual(Post.objects.count(), 0)
self.assertIn('아직 게시물이 없습니다', soup.body.text)

post_000 = Post.objects.create(
title='The first',
content='Hello',
created=timezone.now(),
author=self.author_000, <---이쪽이 자꾸 에러가 납니다
)

self.assertGreater(Post.objects.count(), 0)
response = self.client.get('/blog/')

self.assertEqual(response.status_code, 200)
soup = BeautifulSoup(response.content, 'html.parser')
title = soup.title
self.assertNotIn('아직 게시물이 없습니다', soup.body.text)
self.assertIn(post_000, soup.body.text)

도와주시면 감사하곘습니다 Testview에 seㅣf.author가
no atrribute라는데 무엇이 문제인지 모르겠습니다.

답변 1

답변을 작성해보세요.

0

models.py도 보여주실 수 있나요? 혹시 Post 모델에 author가 없는게 아닐까요?