from django.test import TestCase, Client
# Create your tests here.
+import pytest
+
from .models import QuoteTag, Author, Work, Quote
import re
import lxml.etree
-class QuoteTest(TestCase):
- def setUp(self):
+class Test_QuoteTest():
+ @pytest.fixture(scope='function')
+ def q1(self, db):
a1 = Author.objects.create(name="JFK")
w1 = Work.objects.create(name="Berlin speech", author=a1)
q1 = Quote.objects.create(text="<p>Ich bin...</p>", work=w1)
- self.q1 = q1
+ return q1
- def test_one(self):
+ @pytest.mark.django_db
+ def test_one(self, q1):
q = Quote.objects.filter(text__startswith="<p>Ich")
- self.assertEqual(q.count(), 1)
+ assert q.count() == 1
q = q[0]
- self.assertEqual(q, self.q1)
- self.assertEqual(q.work.author.name, "JFK")
+ assert q == q1
+ assert q.work.author.name == 'JFK'
class ViewsTest(TestCase):
def getPage(self, url, exp_status=200):