문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판이전 판다음 판 | 이전 판 | ||
| python:django:test [2021/10/04 03:10] – [TestCase만들기] taekgu | python:django:test [2025/04/15 10:05] (현재) – 바깥 편집 127.0.0.1 | ||
|---|---|---|---|
| 줄 1: | 줄 1: | ||
| + | ====== Test ====== | ||
| + | ===== TestCase만들기 ===== | ||
| + | <code python tests.py> | ||
| + | import datetime | ||
| + | |||
| + | from django.test import TestCase | ||
| + | from django.utils import timezone | ||
| + | from django.urls import reverse | ||
| + | from django.views import generic | ||
| + | |||
| + | from .models import Question | ||
| + | |||
| + | def create_question(question_text, | ||
| + | time = timezone.now() + datetime.timedelta(days=days) | ||
| + | return Question.objects.create(question_text=question_text, | ||
| + | |||
| + | class QuestionModelTests(TestCase): | ||
| + | def test_was_published_recently_with_future_question(self): | ||
| + | time = timezone.now() + datetime.timedelta(days=30) | ||
| + | future_question = Question(pub_date=time) | ||
| + | self.assertIs(future_question.was_published_recently(), | ||
| + | |||
| + | class DetailView(generic.DetailView): | ||
| + | def get_queryset(self): | ||
| + | return Question.objects.filter(pub_date__lte=timezone.now()) | ||
| + | </ | ||
| + | |||
| + | ===== Selenium ===== | ||
| + | 브라우저 자동화하여 테스트를 가능하도록 한다. 주로 테스트 목적으로 웹 애플리케이션을 자동화하기 위한 것이지만, | ||
| + | |||
| + | 지루한 웹 기반 관리 작업도 자동화할 수 있습니다. | ||