From 3278c31fa59b41d03aea167f4cf85f4ddf7f848d Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Tue, 8 Feb 2022 12:27:04 +0100 Subject: [4.0.x] Refs #33476 -- Refactored code to strictly match 88 characters line length. Backport of 7119f40c9881666b6f9b5cf7df09ee1d21cc8344 from main. --- tests/model_formsets/tests.py | 284 +++++++++++++++++++++++++++--------------- 1 file changed, 182 insertions(+), 102 deletions(-) (limited to 'tests/model_formsets') diff --git a/tests/model_formsets/tests.py b/tests/model_formsets/tests.py index f10a7d92db..b2b0976a2b 100644 --- a/tests/model_formsets/tests.py +++ b/tests/model_formsets/tests.py @@ -189,7 +189,7 @@ class ModelFormsetTest(TestCase): self.assertHTMLEqual( formset.forms[2].as_p(), '

' - ' ' + '' '

', ) @@ -229,14 +229,16 @@ class ModelFormsetTest(TestCase): self.assertHTMLEqual( formset.forms[0].as_p(), '

' - '' + '' '

' % author2.id, ) self.assertHTMLEqual( formset.forms[1].as_p(), '

' - '' + '' '

' % author1.id, ) @@ -313,8 +315,8 @@ class ModelFormsetTest(TestCase): self.assertHTMLEqual( formset.forms[3].as_p(), '

' - '

' - '

' + '' + '

' '' '

', ) @@ -565,10 +567,11 @@ class ModelFormsetTest(TestCase): self.assertHTMLEqual( formset.forms[0].as_p(), '

' - '

' - '

' + '' + '

' '' - '

', + '' + "

", ) data = { @@ -593,19 +596,22 @@ class ModelFormsetTest(TestCase): self.assertHTMLEqual( formset.forms[0].as_p(), '

' - '

' + '

' '

' - '' - '

' - % hemingway_id, + '' + '

' % hemingway_id, ) self.assertHTMLEqual( formset.forms[1].as_p(), '

' - '

' - '

' + '' + '

' '' - '

', + '' + "

", ) data = { @@ -637,24 +643,31 @@ class ModelFormsetTest(TestCase): self.assertEqual(len(formset.forms), 3) self.assertHTMLEqual( formset.forms[0].as_p(), - '

' + '

' + '' + '' + '' "

" % author.id, ) self.assertHTMLEqual( formset.forms[1].as_p(), '

' - '' - '' + '' + '' '

' % author.id, ) self.assertHTMLEqual( formset.forms[2].as_p(), '

' - '' - '' + '' + '' '

' % author.id, ) @@ -693,8 +706,10 @@ class ModelFormsetTest(TestCase): '

' '' - '' - '

' + '' + '

' % ( author.id, book1.id, @@ -703,16 +718,20 @@ class ModelFormsetTest(TestCase): self.assertHTMLEqual( formset.forms[1].as_p(), '

' - '' - '' + '' + '' '

' % author.id, ) self.assertHTMLEqual( formset.forms[2].as_p(), '

' - '' - '' + '' + '' '

' % author.id, ) @@ -782,7 +801,8 @@ class ModelFormsetTest(TestCase): self.assertHTMLEqual( formset.forms[0].as_p(), '

' - '' + '' '' '

', ) @@ -790,7 +810,8 @@ class ModelFormsetTest(TestCase): self.assertHTMLEqual( formset.forms[1].as_p(), '

' - '' + '' '' '

', ) @@ -820,9 +841,12 @@ class ModelFormsetTest(TestCase): ) data = { - "bookwithcustompk_set-TOTAL_FORMS": "1", # the number of forms rendered - "bookwithcustompk_set-INITIAL_FORMS": "0", # the number of forms with initial data - "bookwithcustompk_set-MAX_NUM_FORMS": "", # the max number of forms + # The number of forms rendered. + "bookwithcustompk_set-TOTAL_FORMS": "1", + # The number of forms with initial data. + "bookwithcustompk_set-INITIAL_FORMS": "0", + # The max number of forms. + "bookwithcustompk_set-MAX_NUM_FORMS": "", "bookwithcustompk_set-0-my_pk": "77777", "bookwithcustompk_set-0-title": "Les Fleurs du Mal", } @@ -864,9 +888,12 @@ class ModelFormsetTest(TestCase): ) data = { - "alternatebook_set-TOTAL_FORMS": "1", # the number of forms rendered - "alternatebook_set-INITIAL_FORMS": "0", # the number of forms with initial data - "alternatebook_set-MAX_NUM_FORMS": "", # the max number of forms + # The number of forms rendered. + "alternatebook_set-TOTAL_FORMS": "1", + # The number of forms with initial data. + "alternatebook_set-INITIAL_FORMS": "0", + # The max number of forms. + "alternatebook_set-MAX_NUM_FORMS": "", "alternatebook_set-0-title": "Flowers of Evil", "alternatebook_set-0-notes": "English translation of Les Fleurs du Mal", } @@ -895,9 +922,12 @@ class ModelFormsetTest(TestCase): author = Author.objects.create(pk=1, name="Charles Baudelaire") data = { - "bookwithoptionalalteditor_set-TOTAL_FORMS": "2", # the number of forms rendered - "bookwithoptionalalteditor_set-INITIAL_FORMS": "0", # the number of forms with initial data - "bookwithoptionalalteditor_set-MAX_NUM_FORMS": "", # the max number of forms + # The number of forms rendered. + "bookwithoptionalalteditor_set-TOTAL_FORMS": "2", + # The number of forms with initial data. + "bookwithoptionalalteditor_set-INITIAL_FORMS": "0", + # The max number of forms. + "bookwithoptionalalteditor_set-MAX_NUM_FORMS": "", "bookwithoptionalalteditor_set-0-author": "1", "bookwithoptionalalteditor_set-0-title": "Les Fleurs du Mal", "bookwithoptionalalteditor_set-1-author": "1", @@ -965,37 +995,47 @@ class ModelFormsetTest(TestCase): '

' '' - '' - '

', + '' + '' + "

", ) self.assertHTMLEqual( formset.forms[1].as_p(), '

' '' - '' - '

', + '' + '' + "

", ) self.assertHTMLEqual( formset.forms[2].as_p(), '

' '' - '' - '

', + '' + '

', ) self.assertHTMLEqual( formset.forms[3].as_p(), '

' - '' - '' + '' + '' '

', ) self.assertHTMLEqual( formset.forms[4].as_p(), '

' - '' - '' + '' + '' '

', ) @@ -1022,21 +1062,27 @@ class ModelFormsetTest(TestCase): '

' '' - '' - '

', + '' + '

', ) self.assertHTMLEqual( formset.forms[1].as_p(), '

' - '' - '' + '' + '' '

', ) self.assertHTMLEqual( formset.forms[2].as_p(), '

' - '' - '' + '' + '' '

', ) @@ -1103,10 +1149,12 @@ class ModelFormsetTest(TestCase): self.assertEqual(len(formset.forms), 1) self.assertHTMLEqual( formset.forms[0].as_p(), - '

' + '

' + '

' '

' - '

', + '

', ) # Custom primary keys with ForeignKey, OneToOneField and AutoField ############ @@ -1121,16 +1169,22 @@ class ModelFormsetTest(TestCase): self.assertHTMLEqual( formset.forms[0].as_p(), '

' - '' - '' - '

', + '' + '' + '

', ) self.assertHTMLEqual( formset.forms[1].as_p(), '

' - '' - '' - '

', + '' + '' + '

', ) data = { @@ -1155,24 +1209,32 @@ class ModelFormsetTest(TestCase): self.assertHTMLEqual( formset.forms[0].as_p(), '

' - '' - '' - '

' - % owner1.auto_id, + '' + '' + '

' % owner1.auto_id, ) self.assertHTMLEqual( formset.forms[1].as_p(), '

' - '' - '' - '

', + '' + '' + '

', ) self.assertHTMLEqual( formset.forms[2].as_p(), '

' - '' - '' - '

', + '' + '' + '

', ) data = { @@ -1194,8 +1256,8 @@ class ModelFormsetTest(TestCase): self.assertEqual(owner2.name, "Jack Berry") self.assertEqual(owner2.place.name, "Giordanos") - # Ensure a custom primary key that is a ForeignKey or OneToOneField get rendered for the user to choose. - + # A custom primary key that is a ForeignKey or OneToOneField get + # rendered for the user to choose. FormSet = modelformset_factory(OwnerProfile, fields="__all__") formset = FormSet() self.assertHTMLEqual( @@ -1222,9 +1284,10 @@ class ModelFormsetTest(TestCase): self.assertHTMLEqual( formset.forms[0].as_p(), '

' - '' - '

' - % owner1.auto_id, + '' + '

' % owner1.auto_id, ) data = { @@ -1247,9 +1310,10 @@ class ModelFormsetTest(TestCase): self.assertHTMLEqual( formset.forms[0].as_p(), '

' - '' - '

' - % owner1.auto_id, + '' + '

' % owner1.auto_id, ) data = { @@ -1282,11 +1346,15 @@ class ModelFormsetTest(TestCase): self.assertHTMLEqual( formset.forms[0].as_p(), '

' - '

' - '

' - '' - '' - '

', + '

' + '

' + '' + '' + '

', ) def test_foreign_keys_in_parents(self): @@ -1511,13 +1579,16 @@ class ModelFormsetTest(TestCase): '

' '' - '

' '

' - '' - '' - '

' - % person.id, + '' + '' + '

' % person.id, ) # test for validation with callable defaults. Validations rely on hidden fields @@ -1701,12 +1772,14 @@ class ModelFormsetTest(TestCase): self.assertEqual( formset._non_form_errors, [ - "Please correct the duplicate data for price and quantity, which must be unique." + "Please correct the duplicate data for price and quantity, which must " + "be unique." ], ) - # Only the price field is specified, this should skip any unique checks since - # the unique_together is not fulfilled. This will fail with a KeyError if broken. + # Only the price field is specified, this should skip any unique + # checks since the unique_together is not fulfilled. This will fail + # with a KeyError if broken. FormSet = modelformset_factory(Price, fields=("price",), extra=2) data = { "form-TOTAL_FORMS": "2", @@ -1765,7 +1838,8 @@ class ModelFormsetTest(TestCase): self.assertEqual( formset._non_form_errors, [ - "Please correct the duplicate data for title which must be unique for the date in posted." + "Please correct the duplicate data for title which must be unique for " + "the date in posted." ], ) self.assertEqual( @@ -1791,7 +1865,8 @@ class ModelFormsetTest(TestCase): self.assertEqual( formset._non_form_errors, [ - "Please correct the duplicate data for slug which must be unique for the year in posted." + "Please correct the duplicate data for slug which must be unique for " + "the year in posted." ], ) @@ -1813,7 +1888,8 @@ class ModelFormsetTest(TestCase): self.assertEqual( formset._non_form_errors, [ - "Please correct the duplicate data for subtitle which must be unique for the month in posted." + "Please correct the duplicate data for subtitle which must be unique " + "for the month in posted." ], ) @@ -1885,7 +1961,8 @@ class ModelFormsetTest(TestCase): [ { "id": [ - "Select a valid choice. That choice is not one of the available choices." + "Select a valid choice. That choice is not one of the " + "available choices." ] } ], @@ -1906,7 +1983,8 @@ class ModelFormsetTest(TestCase): [ { "id": [ - "Select a valid choice. That choice is not one of the available choices." + "Select a valid choice. That choice is not one of the " + "available choices." ] } ], @@ -1925,7 +2003,8 @@ class TestModelFormsetOverridesTroughFormMeta(TestCase): form = PoetFormSet.form() self.assertHTMLEqual( str(form["name"]), - '', + '", ) def test_inlineformset_factory_widgets(self): @@ -1936,7 +2015,8 @@ class TestModelFormsetOverridesTroughFormMeta(TestCase): form = BookFormSet.form() self.assertHTMLEqual( str(form["title"]), - '', + '', ) def test_modelformset_factory_labels_overrides(self): -- cgit v1.3