summaryrefslogtreecommitdiff
path: root/tests/generic_relations
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2022-02-04 08:08:27 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-02-07 20:37:05 +0100
commit7119f40c9881666b6f9b5cf7df09ee1d21cc8344 (patch)
treefa50869f5614295f462d9bf77fec59365c621609 /tests/generic_relations
parent9c19aff7c7561e3a82978a272ecdaad40dda5c00 (diff)
downloaddjango-7119f40c9881666b6f9b5cf7df09ee1d21cc8344.tar.gz
Refs #33476 -- Refactored code to strictly match 88 characters line length.
Diffstat (limited to 'tests/generic_relations')
-rw-r--r--tests/generic_relations/test_forms.py123
-rw-r--r--tests/generic_relations/tests.py8
2 files changed, 91 insertions, 40 deletions
diff --git a/tests/generic_relations/test_forms.py b/tests/generic_relations/test_forms.py
index 78c146e22a..00df254745 100644
--- a/tests/generic_relations/test_forms.py
+++ b/tests/generic_relations/test_forms.py
@@ -32,26 +32,46 @@ class GenericInlineFormsetTests(TestCase):
formset = GenericFormSet()
self.assertHTMLEqual(
"".join(form.as_p() for form in formset.forms),
- """<p><label for="id_generic_relations-taggeditem-content_type-object_id-0-tag">
-Tag:</label> <input id="id_generic_relations-taggeditem-content_type-object_id-0-tag" type="text"
-name="generic_relations-taggeditem-content_type-object_id-0-tag" maxlength="50"></p>
-<p><label for="id_generic_relations-taggeditem-content_type-object_id-0-DELETE">Delete:</label>
-<input type="checkbox" name="generic_relations-taggeditem-content_type-object_id-0-DELETE"
-id="id_generic_relations-taggeditem-content_type-object_id-0-DELETE">
-<input type="hidden" name="generic_relations-taggeditem-content_type-object_id-0-id"
-id="id_generic_relations-taggeditem-content_type-object_id-0-id"></p>""",
+ """
+ <p><label
+ for="id_generic_relations-taggeditem-content_type-object_id-0-tag">
+ Tag:</label>
+ <input id="id_generic_relations-taggeditem-content_type-object_id-0-tag"
+ type="text"
+ name="generic_relations-taggeditem-content_type-object_id-0-tag"
+ maxlength="50"></p>
+ <p><label
+ for="id_generic_relations-taggeditem-content_type-object_id-0-DELETE">
+ Delete:</label>
+ <input type="checkbox"
+ name="generic_relations-taggeditem-content_type-object_id-0-DELETE"
+ id="id_generic_relations-taggeditem-content_type-object_id-0-DELETE">
+ <input type="hidden"
+ name="generic_relations-taggeditem-content_type-object_id-0-id"
+ id="id_generic_relations-taggeditem-content_type-object_id-0-id"></p>
+ """,
)
formset = GenericFormSet(instance=Animal())
self.assertHTMLEqual(
"".join(form.as_p() for form in formset.forms),
- """<p><label for="id_generic_relations-taggeditem-content_type-object_id-0-tag">
-Tag:</label> <input id="id_generic_relations-taggeditem-content_type-object_id-0-tag"
-type="text" name="generic_relations-taggeditem-content_type-object_id-0-tag" maxlength="50"></p>
-<p><label for="id_generic_relations-taggeditem-content_type-object_id-0-DELETE">Delete:</label>
-<input type="checkbox" name="generic_relations-taggeditem-content_type-object_id-0-DELETE"
-id="id_generic_relations-taggeditem-content_type-object_id-0-DELETE"><input type="hidden"
-name="generic_relations-taggeditem-content_type-object_id-0-id"
-id="id_generic_relations-taggeditem-content_type-object_id-0-id"></p>""",
+ """
+ <p><label
+ for="id_generic_relations-taggeditem-content_type-object_id-0-tag">
+ Tag:</label>
+ <input id="id_generic_relations-taggeditem-content_type-object_id-0-tag"
+ type="text"
+ name="generic_relations-taggeditem-content_type-object_id-0-tag"
+ maxlength="50"></p>
+ <p><label
+ for="id_generic_relations-taggeditem-content_type-object_id-0-DELETE">
+ Delete:</label>
+ <input type="checkbox"
+ name="generic_relations-taggeditem-content_type-object_id-0-DELETE"
+ id="id_generic_relations-taggeditem-content_type-object_id-0-DELETE">
+ <input type="hidden"
+ name="generic_relations-taggeditem-content_type-object_id-0-id"
+ id="id_generic_relations-taggeditem-content_type-object_id-0-id"></p>
+ """,
)
platypus = Animal.objects.create(
common_name="Platypus",
@@ -63,32 +83,54 @@ id="id_generic_relations-taggeditem-content_type-object_id-0-id"></p>""",
tagged_item_id = TaggedItem.objects.get(tag="shiny", object_id=platypus.id).id
self.assertHTMLEqual(
"".join(form.as_p() for form in formset.forms),
- """<p><label for="id_generic_relations-taggeditem-content_type-object_id-0-tag">Tag:</label>
-<input id="id_generic_relations-taggeditem-content_type-object_id-0-tag" type="text"
-name="generic_relations-taggeditem-content_type-object_id-0-tag" value="shiny" maxlength="50"></p>
-<p><label for="id_generic_relations-taggeditem-content_type-object_id-0-DELETE">Delete:</label>
-<input type="checkbox" name="generic_relations-taggeditem-content_type-object_id-0-DELETE"
-id="id_generic_relations-taggeditem-content_type-object_id-0-DELETE">
-<input type="hidden" name="generic_relations-taggeditem-content_type-object_id-0-id"
-value="%s" id="id_generic_relations-taggeditem-content_type-object_id-0-id"></p>
-<p><label for="id_generic_relations-taggeditem-content_type-object_id-1-tag">Tag:</label>
-<input id="id_generic_relations-taggeditem-content_type-object_id-1-tag" type="text"
-name="generic_relations-taggeditem-content_type-object_id-1-tag" maxlength="50"></p>
-<p><label for="id_generic_relations-taggeditem-content_type-object_id-1-DELETE">Delete:</label>
-<input type="checkbox" name="generic_relations-taggeditem-content_type-object_id-1-DELETE"
-id="id_generic_relations-taggeditem-content_type-object_id-1-DELETE">
-<input type="hidden" name="generic_relations-taggeditem-content_type-object_id-1-id"
-id="id_generic_relations-taggeditem-content_type-object_id-1-id"></p>"""
+ """
+ <p><label
+ for="id_generic_relations-taggeditem-content_type-object_id-0-tag">
+ Tag:</label>
+ <input id="id_generic_relations-taggeditem-content_type-object_id-0-tag"
+ type="text"
+ name="generic_relations-taggeditem-content_type-object_id-0-tag"
+ value="shiny" maxlength="50"></p>
+ <p><label
+ for="id_generic_relations-taggeditem-content_type-object_id-0-DELETE">
+ Delete:</label>
+ <input type="checkbox"
+ name="generic_relations-taggeditem-content_type-object_id-0-DELETE"
+ id="id_generic_relations-taggeditem-content_type-object_id-0-DELETE">
+ <input type="hidden"
+ name="generic_relations-taggeditem-content_type-object_id-0-id"
+ value="%s"
+ id="id_generic_relations-taggeditem-content_type-object_id-0-id"></p>
+ <p><label
+ for="id_generic_relations-taggeditem-content_type-object_id-1-tag">
+ Tag:</label>
+ <input id="id_generic_relations-taggeditem-content_type-object_id-1-tag"
+ type="text"
+ name="generic_relations-taggeditem-content_type-object_id-1-tag"
+ maxlength="50"></p>
+ <p><label
+ for="id_generic_relations-taggeditem-content_type-object_id-1-DELETE">
+ Delete:</label>
+ <input type="checkbox"
+ name="generic_relations-taggeditem-content_type-object_id-1-DELETE"
+ id="id_generic_relations-taggeditem-content_type-object_id-1-DELETE">
+ <input type="hidden"
+ name="generic_relations-taggeditem-content_type-object_id-1-id"
+ id="id_generic_relations-taggeditem-content_type-object_id-1-id"></p>
+ """
% tagged_item_id,
)
lion = Animal.objects.create(common_name="Lion", latin_name="Panthera leo")
formset = GenericFormSet(instance=lion, prefix="x")
self.assertHTMLEqual(
"".join(form.as_p() for form in formset.forms),
- """<p><label for="id_x-0-tag">Tag:</label>
-<input id="id_x-0-tag" type="text" name="x-0-tag" maxlength="50"></p>
-<p><label for="id_x-0-DELETE">Delete:</label> <input type="checkbox" name="x-0-DELETE" id="id_x-0-DELETE">
-<input type="hidden" name="x-0-id" id="id_x-0-id"></p>""",
+ """
+ <p><label for="id_x-0-tag">Tag:</label>
+ <input id="id_x-0-tag" type="text" name="x-0-tag" maxlength="50"></p>
+ <p><label for="id_x-0-DELETE">Delete:</label>
+ <input type="checkbox" name="x-0-DELETE" id="id_x-0-DELETE">
+ <input type="hidden" name="x-0-id" id="id_x-0-id"></p>
+ """,
)
def test_options(self):
@@ -108,7 +150,9 @@ id="id_generic_relations-taggeditem-content_type-object_id-1-id"></p>"""
self.assertEqual(len(formset.forms), 5)
self.assertHTMLEqual(
formset.forms[0].as_p(),
- '<input type="hidden" name="generic_relations-taggeditem-content_type-object_id-0-id" value="%s" '
+ '<input type="hidden" '
+ 'name="generic_relations-taggeditem-content_type-object_id-0-id" '
+ 'value="%s" '
'id="id_generic_relations-taggeditem-content_type-object_id-0-id">'
% harmless.pk,
)
@@ -166,7 +210,10 @@ id="id_generic_relations-taggeditem-content_type-object_id-1-id"></p>"""
class BadModel(models.Model):
content_type = models.PositiveIntegerField()
- msg = "fk_name 'generic_relations.BadModel.content_type' is not a ForeignKey to ContentType"
+ msg = (
+ "fk_name 'generic_relations.BadModel.content_type' is not a ForeignKey to "
+ "ContentType"
+ )
with self.assertRaisesMessage(Exception, msg):
generic_inlineformset_factory(BadModel, TaggedItemForm)
diff --git a/tests/generic_relations/tests.py b/tests/generic_relations/tests.py
index 6c6b0d1611..7c49e218dd 100644
--- a/tests/generic_relations/tests.py
+++ b/tests/generic_relations/tests.py
@@ -285,7 +285,10 @@ class GenericRelationsTests(TestCase):
def test_add_rejects_unsaved_objects(self):
t1 = TaggedItem(content_object=self.quartz, tag="shiny")
- msg = "<TaggedItem: shiny> instance isn't saved. Use bulk=False or save the object first."
+ msg = (
+ "<TaggedItem: shiny> instance isn't saved. Use bulk=False or save the "
+ "object first."
+ )
with self.assertRaisesMessage(ValueError, msg):
self.bacon.tags.add(t1)
@@ -443,7 +446,8 @@ class GenericRelationsTests(TestCase):
self.assertEqual(ValuableTaggedItem.objects.count(), 0)
def test_gfk_manager(self):
- # GenericForeignKey should not use the default manager (which may filter objects) #16048
+ # GenericForeignKey should not use the default manager (which may
+ # filter objects).
tailless = Gecko.objects.create(has_tail=False)
tag = TaggedItem.objects.create(content_object=tailless, tag="lizard")
self.assertEqual(tag.content_object, tailless)