강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

최민석님의 프로필 이미지
최민석

작성한 질문수

파이썬 사용자를 위한 웹개발 입문 A to Z Django + Bootstrap

Post List 페이지 테스트 코드 작성하기 part B

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

작성

·

164

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

SungYong Lee님의 프로필 이미지
SungYong Lee
지식공유자

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

최민석님의 프로필 이미지
최민석

작성한 질문수

질문하기