X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;f=quotes%2Ftest_massimport.py;fp=quotes%2Ftest_massimport.py;h=0a9fb4f70fafe6ea0ceb622b59f4904ae4dcfb81;hb=bb8b5bd36c5f921ba31635bb858db3d4788ef0e9;hp=0000000000000000000000000000000000000000;hpb=5be623b47010e85eddcfa152f606822231c13456;p=djsite.git diff --git a/quotes/test_massimport.py b/quotes/test_massimport.py new file mode 100644 index 0000000..0a9fb4f --- /dev/null +++ b/quotes/test_massimport.py @@ -0,0 +1,121 @@ +import pytest + +from .models import Author, Work, Quote, QuoteTag + +class Test_MassImport(): + @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="

Ich bin...

", work=w1) + return q1 + + @pytest.mark.django_db + def test_massimport_1(self, q1, c): + allquotes = """\ +Ich bin ein Berliner +--- +JFK +--- +Berlin speech +=== +To be or not to be, that is the question +--- +William Shakespeare +--- +Hamlet +=== +To thine own self, be true +--- +William Shakespeare +--- +Hamlet +--- +tag1, tag2, tag3 +=== +A rose by any other name... +--- +William Shakespeare +--- +Romeo and Juliet +--- +tag1, tag555 +===""" + + results = c.postPage('massimport/', {'quotes': allquotes}) + + assert "rejected" not in results + + assert Quote.objects.get(text="

To thine own self, be true

") + assert Quote.objects.get(text__contains="To be or not to be") + + assert Author.objects.get(name="JFK") + assert Author.objects.get(name="William Shakespeare") + assert Author.objects.all().count() == 2 + + hamlet = Work.objects.get(name="Hamlet") + assert hamlet + assert hamlet.author == Author.objects.get(name="William Shakespeare") + + for quote in Quote.objects.all(): + assert c.getPage(quote.get_absolute_url()) + + @pytest.mark.django_db + def test_massimport_2(self, q1, c): + allquotes = """\ + +A rose by any other name... +--- +William Shakespeare +--- +Romeo and Juliet +--- +tag1, tag555 +===""" + + results = c.postPage('massimport/', {'quotes': allquotes}) + assert "