1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Refs #33476 -- Refactored code to strictly match 88 characters line length.

This commit is contained in:
Mariusz Felisiak
2022-02-04 08:08:27 +01:00
parent 9c19aff7c7
commit 7119f40c98
404 changed files with 5944 additions and 2842 deletions

View File

@@ -145,83 +145,111 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
# Dump the current contents of the database as a JSON fixture
self._dumpdata_assert(
["fixtures"],
'[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": '
'"News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place '
'on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}]',
'[{"pk": 1, "model": "fixtures.category", "fields": '
'{"description": "Latest news stories", "title": "News Stories"}}, '
'{"pk": 2, "model": "fixtures.article", "fields": '
'{"headline": "Poker has no place on ESPN", '
'"pub_date": "2006-06-16T12:00:00"}}, '
'{"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Time to reform copyright", '
'"pub_date": "2006-06-16T13:00:00"}}]',
)
# Try just dumping the contents of fixtures.Category
self._dumpdata_assert(
["fixtures.Category"],
'[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", '
'"title": "News Stories"}}]',
'[{"pk": 1, "model": "fixtures.category", "fields": '
'{"description": "Latest news stories", "title": "News Stories"}}]',
)
# ...and just fixtures.Article
self._dumpdata_assert(
["fixtures.Article"],
'[{"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", '
'"pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": '
'"Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}]',
'[{"pk": 2, "model": "fixtures.article", "fields": '
'{"headline": "Poker has no place on ESPN", '
'"pub_date": "2006-06-16T12:00:00"}}, '
'{"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Time to reform copyright", '
'"pub_date": "2006-06-16T13:00:00"}}]',
)
# ...and both
self._dumpdata_assert(
["fixtures.Category", "fixtures.Article"],
'[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", '
'"title": "News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has '
'no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", '
'"fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}]',
'[{"pk": 1, "model": "fixtures.category", "fields": '
'{"description": "Latest news stories", "title": "News Stories"}}, '
'{"pk": 2, "model": "fixtures.article", "fields": '
'{"headline": "Poker has no place on ESPN", '
'"pub_date": "2006-06-16T12:00:00"}}, '
'{"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Time to reform copyright", '
'"pub_date": "2006-06-16T13:00:00"}}]',
)
# Specify a specific model twice
self._dumpdata_assert(
["fixtures.Article", "fixtures.Article"],
(
'[{"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", '
'"pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": '
'"Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}]'
'[{"pk": 2, "model": "fixtures.article", "fields": '
'{"headline": "Poker has no place on ESPN", '
'"pub_date": "2006-06-16T12:00:00"}}, '
'{"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Time to reform copyright", '
'"pub_date": "2006-06-16T13:00:00"}}]'
),
)
# Specify a dump that specifies Article both explicitly and implicitly
self._dumpdata_assert(
["fixtures.Article", "fixtures"],
'[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": '
'"News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place '
'on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}]',
'[{"pk": 1, "model": "fixtures.category", "fields": '
'{"description": "Latest news stories", "title": "News Stories"}}, '
'{"pk": 2, "model": "fixtures.article", "fields": '
'{"headline": "Poker has no place on ESPN", '
'"pub_date": "2006-06-16T12:00:00"}}, '
'{"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Time to reform copyright", '
'"pub_date": "2006-06-16T13:00:00"}}]',
)
# Specify a dump that specifies Article both explicitly and implicitly,
# but lists the app first (#22025).
self._dumpdata_assert(
["fixtures", "fixtures.Article"],
'[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": '
'"News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place '
'on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}]',
'[{"pk": 1, "model": "fixtures.category", "fields": '
'{"description": "Latest news stories", "title": "News Stories"}}, '
'{"pk": 2, "model": "fixtures.article", "fields": '
'{"headline": "Poker has no place on ESPN", '
'"pub_date": "2006-06-16T12:00:00"}}, '
'{"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Time to reform copyright", '
'"pub_date": "2006-06-16T13:00:00"}}]',
)
# Same again, but specify in the reverse order
self._dumpdata_assert(
["fixtures"],
'[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": '
'"News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no '
'place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields":'
' {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}]',
'[{"pk": 1, "model": "fixtures.category", "fields": '
'{"description": "Latest news stories", "title": "News Stories"}}, '
'{"pk": 2, "model": "fixtures.article", "fields": '
'{"headline": "Poker has no place on ESPN", '
'"pub_date": "2006-06-16T12:00:00"}}, '
'{"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Time to reform copyright", '
'"pub_date": "2006-06-16T13:00:00"}}]',
)
# Specify one model from one application, and an entire other application.
self._dumpdata_assert(
["fixtures.Category", "sites"],
'[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": '
'"News Stories"}}, {"pk": 1, "model": "sites.site", "fields": {"domain": "example.com", "name": '
'"example.com"}}]',
'[{"pk": 1, "model": "fixtures.category", "fields": '
'{"description": "Latest news stories", "title": "News Stories"}}, '
'{"pk": 1, "model": "sites.site", "fields": '
'{"domain": "example.com", "name": "example.com"}}]',
)
# Load fixture 2. JSON file imported by default. Overwrites some existing objects
# Load fixture 2. JSON file imported by default. Overwrites some
# existing objects.
management.call_command("loaddata", "fixture2.json", verbosity=0)
self.assertSequenceEqual(
Article.objects.values_list("headline", flat=True),
@@ -275,7 +303,8 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
self.assertQuerysetEqual(
Visa.objects.all(),
[
"<Visa: Django Reinhardt Can add user, Can change user, Can delete user>",
"<Visa: Django Reinhardt Can add user, Can change user, Can delete "
"user>",
"<Visa: Stephane Grappelli Can add user>",
"<Visa: Prince >",
],
@@ -288,7 +317,8 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
self.assertQuerysetEqual(
Visa.objects.all(),
[
"<Visa: Django Reinhardt Can add user, Can change user, Can delete user>",
"<Visa: Django Reinhardt Can add user, Can change user, Can delete "
"user>",
"<Visa: Stephane Grappelli Can add user, Can delete user>",
'<Visa: Artist formerly known as "Prince" Can change user>',
],
@@ -310,102 +340,176 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
# By default, you get raw keys on dumpdata
self._dumpdata_assert(
["fixtures.book"],
'[{"pk": 1, "model": "fixtures.book", "fields": {"name": "Music for all ages", "authors": [3, 1]}}]',
'[{"pk": 1, "model": "fixtures.book", "fields": '
'{"name": "Music for all ages", "authors": [3, 1]}}]',
)
# But you can get natural keys if you ask for them and they are available
self._dumpdata_assert(
["fixtures.book"],
'[{"pk": 1, "model": "fixtures.book", "fields": {"name": "Music for all ages", "authors": [["Artist '
'formerly known as \\"Prince\\""], ["Django Reinhardt"]]}}]',
'[{"pk": 1, "model": "fixtures.book", "fields": '
'{"name": "Music for all ages", "authors": '
'[["Artist formerly known as \\"Prince\\""], ["Django Reinhardt"]]}}]',
natural_foreign_keys=True,
)
# You can also omit the primary keys for models that we can get later with natural keys.
# You can also omit the primary keys for models that we can get later
# with natural keys.
self._dumpdata_assert(
["fixtures.person"],
'[{"fields": {"name": "Django Reinhardt"}, "model": "fixtures.person"}, {"fields": {"name": "Stephane '
'Grappelli"}, "model": "fixtures.person"}, {"fields": {"name": "Artist formerly known as '
'\\"Prince\\""}, "model": "fixtures.person"}]',
'[{"fields": {"name": "Django Reinhardt"}, "model": "fixtures.person"}, '
'{"fields": {"name": "Stephane Grappelli"}, "model": "fixtures.person"}, '
'{"fields": {"name": "Artist formerly known as \\"Prince\\""}, '
'"model": "fixtures.person"}]',
natural_primary_keys=True,
)
# Dump the current contents of the database as a JSON fixture
self._dumpdata_assert(
["fixtures"],
'[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": '
'"News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker on TV is '
'great!", "pub_date": "2006-06-16T11:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Copyright is fine the way it is", "pub_date": "2006-06-16T14:00:00"}}, {"pk": 4, '
'"model": "fixtures.article", "fields": {"headline": "Django conquers world!", "pub_date": '
'"2006-06-16T15:00:00"}}, {"pk": 5, "model": "fixtures.article", "fields": {"headline": "XML '
'identified as leading cause of cancer", "pub_date": "2006-06-16T16:00:00"}}, {"pk": 1, "model": '
'"fixtures.tag", "fields": {"tagged_type": ["fixtures", "article"], "name": "copyright", "tagged_id": '
'3}}, {"pk": 2, "model": "fixtures.tag", "fields": {"tagged_type": ["fixtures", "article"], "name": '
'"legal", "tagged_id": 3}}, {"pk": 3, "model": "fixtures.tag", "fields": {"tagged_type": ["fixtures", '
'"article"], "name": "django", "tagged_id": 4}}, {"pk": 4, "model": "fixtures.tag", "fields": '
'{"tagged_type": ["fixtures", "article"], "name": "world domination", "tagged_id": 4}}, {"pk": 1, '
'"model": "fixtures.person", "fields": {"name": "Django Reinhardt"}}, {"pk": 2, "model": '
'"fixtures.person", "fields": {"name": "Stephane Grappelli"}}, {"pk": 3, "model": "fixtures.person", '
'"fields": {"name": "Artist formerly known as \\"Prince\\""}}, {"pk": 1, "model": "fixtures.visa", '
'"fields": {"person": ["Django Reinhardt"], "permissions": [["add_user", "auth", "user"], '
'["change_user", "auth", "user"], ["delete_user", "auth", "user"]]}}, {"pk": 2, "model": '
'"fixtures.visa", "fields": {"person": ["Stephane Grappelli"], "permissions": [["add_user", "auth", '
'"user"], ["delete_user", "auth", "user"]]}}, {"pk": 3, "model": "fixtures.visa", "fields": {"person":'
' ["Artist formerly known as \\"Prince\\""], "permissions": [["change_user", "auth", "user"]]}}, '
'{"pk": 1, "model": "fixtures.book", "fields": {"name": "Music for all ages", "authors": [["Artist '
'formerly known as \\"Prince\\""], ["Django Reinhardt"]]}}]',
'[{"pk": 1, "model": "fixtures.category", "fields": '
'{"description": "Latest news stories", "title": "News Stories"}}, '
'{"pk": 2, "model": "fixtures.article", "fields": '
'{"headline": "Poker on TV is great!", '
'"pub_date": "2006-06-16T11:00:00"}}, '
'{"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Copyright is fine the way it is", '
'"pub_date": "2006-06-16T14:00:00"}}, '
'{"pk": 4, "model": "fixtures.article", "fields": '
'{"headline": "Django conquers world!", '
'"pub_date": "2006-06-16T15:00:00"}}, '
'{"pk": 5, "model": "fixtures.article", "fields": '
'{"headline": "XML identified as leading cause of cancer", '
'"pub_date": "2006-06-16T16:00:00"}}, '
'{"pk": 1, "model": "fixtures.tag", "fields": '
'{"tagged_type": ["fixtures", "article"], "name": "copyright", '
'"tagged_id": 3}}, '
'{"pk": 2, "model": "fixtures.tag", "fields": '
'{"tagged_type": ["fixtures", "article"], "name": "legal", '
'"tagged_id": 3}}, '
'{"pk": 3, "model": "fixtures.tag", "fields": '
'{"tagged_type": ["fixtures", "article"], "name": "django", '
'"tagged_id": 4}}, '
'{"pk": 4, "model": "fixtures.tag", "fields": '
'{"tagged_type": ["fixtures", "article"], "name": "world domination", '
'"tagged_id": 4}}, '
'{"pk": 1, "model": "fixtures.person", '
'"fields": {"name": "Django Reinhardt"}}, '
'{"pk": 2, "model": "fixtures.person", '
'"fields": {"name": "Stephane Grappelli"}}, '
'{"pk": 3, "model": "fixtures.person", '
'"fields": {"name": "Artist formerly known as \\"Prince\\""}}, '
'{"pk": 1, "model": "fixtures.visa", '
'"fields": {"person": ["Django Reinhardt"], "permissions": '
'[["add_user", "auth", "user"], ["change_user", "auth", "user"], '
'["delete_user", "auth", "user"]]}}, '
'{"pk": 2, "model": "fixtures.visa", "fields": '
'{"person": ["Stephane Grappelli"], "permissions": '
'[["add_user", "auth", "user"], ["delete_user", "auth", "user"]]}}, '
'{"pk": 3, "model": "fixtures.visa", "fields": '
'{"person": ["Artist formerly known as \\"Prince\\""], "permissions": '
'[["change_user", "auth", "user"]]}}, '
'{"pk": 1, "model": "fixtures.book", "fields": '
'{"name": "Music for all ages", "authors": '
'[["Artist formerly known as \\"Prince\\""], ["Django Reinhardt"]]}}]',
natural_foreign_keys=True,
)
# Dump the current contents of the database as an XML fixture
self._dumpdata_assert(
["fixtures"],
'<?xml version="1.0" encoding="utf-8"?><django-objects version="1.0"><object pk="1" '
'model="fixtures.category"><field type="CharField" name="title">News Stories</field><field '
'type="TextField" name="description">Latest news stories</field></object><object pk="2" '
'model="fixtures.article"><field type="CharField" name="headline">Poker on TV is great!</field><field '
'type="DateTimeField" name="pub_date">2006-06-16T11:00:00</field></object><object pk="3" '
'model="fixtures.article"><field type="CharField" name="headline">Copyright is fine the way it '
'is</field><field type="DateTimeField" name="pub_date">2006-06-16T14:00:00</field></object><object '
'pk="4" model="fixtures.article"><field type="CharField" name="headline">Django conquers world!'
'</field><field type="DateTimeField" name="pub_date">2006-06-16T15:00:00</field></object><object '
'pk="5" model="fixtures.article"><field type="CharField" name="headline">XML identified as leading '
'cause of cancer</field><field type="DateTimeField" name="pub_date">2006-06-16T16:00:00</field>'
'</object><object pk="1" model="fixtures.tag"><field type="CharField" name="name">copyright</field>'
'<field to="contenttypes.contenttype" name="tagged_type" rel="ManyToOneRel"><natural>fixtures'
'</natural><natural>article</natural></field><field type="PositiveIntegerField" name="tagged_id">3'
'</field></object><object pk="2" model="fixtures.tag"><field type="CharField" name="name">legal'
'</field><field to="contenttypes.contenttype" name="tagged_type" rel="ManyToOneRel"><natural>'
'fixtures</natural><natural>article</natural></field><field type="PositiveIntegerField" '
'name="tagged_id">3</field></object><object pk="3" model="fixtures.tag"><field type="CharField" '
'name="name">django</field><field to="contenttypes.contenttype" name="tagged_type" '
'rel="ManyToOneRel"><natural>fixtures</natural><natural>article</natural></field><field '
'type="PositiveIntegerField" name="tagged_id">4</field></object><object pk="4" model="fixtures.tag">'
'<field type="CharField" name="name">world domination</field><field to="contenttypes.contenttype" '
'name="tagged_type" rel="ManyToOneRel"><natural>fixtures</natural><natural>article</natural></field>'
'<field type="PositiveIntegerField" name="tagged_id">4</field></object><object pk="1" '
'model="fixtures.person"><field type="CharField" name="name">Django Reinhardt</field></object>'
'<object pk="2" model="fixtures.person"><field type="CharField" name="name">Stephane Grappelli'
'</field></object><object pk="3" model="fixtures.person"><field type="CharField" name="name">'
'Artist formerly known as "Prince"</field></object><object pk="1" model="fixtures.visa"><field '
'to="fixtures.person" name="person" rel="ManyToOneRel"><natural>Django Reinhardt</natural></field>'
'<field to="auth.permission" name="permissions" rel="ManyToManyRel"><object><natural>add_user'
"</natural><natural>auth</natural><natural>user</natural></object><object><natural>change_user"
"</natural><natural>auth</natural><natural>user</natural></object><object><natural>delete_user"
'</natural><natural>auth</natural><natural>user</natural></object></field></object><object pk="2" '
'model="fixtures.visa"><field to="fixtures.person" name="person" rel="ManyToOneRel"><natural>Stephane'
' Grappelli</natural></field><field to="auth.permission" name="permissions" rel="ManyToManyRel">'
"<object><natural>add_user</natural><natural>auth</natural><natural>user</natural></object><object>"
"<natural>delete_user</natural><natural>auth</natural><natural>user</natural></object></field>"
'</object><object pk="3" model="fixtures.visa"><field to="fixtures.person" name="person" '
'rel="ManyToOneRel"><natural>Artist formerly known as "Prince"</natural></field><field '
'to="auth.permission" name="permissions" rel="ManyToManyRel"><object><natural>change_user</natural>'
'<natural>auth</natural><natural>user</natural></object></field></object><object pk="1" '
'model="fixtures.book"><field type="CharField" name="name">Music for all ages</field><field '
'to="fixtures.person" name="authors" rel="ManyToManyRel"><object><natural>Artist formerly known as '
'"Prince"</natural></object><object><natural>Django Reinhardt</natural></object></field></object>'
"</django-objects>",
'<?xml version="1.0" encoding="utf-8"?><django-objects version="1.0">'
'<object pk="1" model="fixtures.category">'
'<field type="CharField" name="title">News Stories</field>'
'<field type="TextField" name="description">Latest news stories</field>'
"</object>"
'<object pk="2" model="fixtures.article">'
'<field type="CharField" name="headline">Poker on TV is great!</field>'
'<field type="DateTimeField" name="pub_date">2006-06-16T11:00:00</field>'
"</object>"
'<object pk="3" model="fixtures.article">'
'<field type="CharField" name="headline">Copyright is fine the way it is'
"</field>"
'<field type="DateTimeField" name="pub_date">2006-06-16T14:00:00</field>'
"</object>"
'<object pk="4" model="fixtures.article">'
'<field type="CharField" name="headline">Django conquers world!</field>'
'<field type="DateTimeField" name="pub_date">2006-06-16T15:00:00</field>'
"</object>"
'<object pk="5" model="fixtures.article">'
'<field type="CharField" name="headline">'
"XML identified as leading cause of cancer</field>"
'<field type="DateTimeField" name="pub_date">2006-06-16T16:00:00</field>'
"</object>"
'<object pk="1" model="fixtures.tag">'
'<field type="CharField" name="name">copyright</field>'
'<field to="contenttypes.contenttype" name="tagged_type" '
'rel="ManyToOneRel"><natural>fixtures</natural><natural>article</natural>'
"</field>"
'<field type="PositiveIntegerField" name="tagged_id">3</field>'
"</object>"
'<object pk="2" model="fixtures.tag">'
'<field type="CharField" name="name">legal</field>'
'<field to="contenttypes.contenttype" name="tagged_type" '
'rel="ManyToOneRel"><natural>fixtures</natural><natural>article</natural>'
"</field>"
'<field type="PositiveIntegerField" name="tagged_id">3</field></object>'
'<object pk="3" model="fixtures.tag">'
'<field type="CharField" name="name">django</field>'
'<field to="contenttypes.contenttype" name="tagged_type" '
'rel="ManyToOneRel"><natural>fixtures</natural><natural>article</natural>'
"</field>"
'<field type="PositiveIntegerField" name="tagged_id">4</field>'
"</object>"
'<object pk="4" model="fixtures.tag">'
'<field type="CharField" name="name">world domination</field>'
'<field to="contenttypes.contenttype" name="tagged_type" '
'rel="ManyToOneRel"><natural>fixtures</natural><natural>article</natural>'
"</field>"
'<field type="PositiveIntegerField" name="tagged_id">4</field>'
"</object>"
'<object pk="1" model="fixtures.person">'
'<field type="CharField" name="name">Django Reinhardt</field>'
"</object>"
'<object pk="2" model="fixtures.person">'
'<field type="CharField" name="name">Stephane Grappelli</field>'
"</object>"
'<object pk="3" model="fixtures.person">'
'<field type="CharField" name="name">Artist formerly known as "Prince"'
"</field>"
"</object>"
'<object pk="1" model="fixtures.visa">'
'<field to="fixtures.person" name="person" rel="ManyToOneRel">'
"<natural>Django Reinhardt</natural></field>"
'<field to="auth.permission" name="permissions" rel="ManyToManyRel">'
"<object><natural>add_user</natural><natural>auth</natural>"
"<natural>user</natural></object><object><natural>change_user</natural>"
"<natural>auth</natural><natural>user</natural></object>"
"<object><natural>delete_user</natural><natural>auth</natural>"
"<natural>user</natural></object></field>"
"</object>"
'<object pk="2" model="fixtures.visa">'
'<field to="fixtures.person" name="person" rel="ManyToOneRel">'
"<natural>Stephane Grappelli</natural></field>"
'<field to="auth.permission" name="permissions" rel="ManyToManyRel">'
"<object><natural>add_user</natural><natural>auth</natural>"
"<natural>user</natural></object>"
"<object><natural>delete_user</natural><natural>auth</natural>"
"<natural>user</natural></object></field>"
"</object>"
'<object pk="3" model="fixtures.visa">'
'<field to="fixtures.person" name="person" rel="ManyToOneRel">'
'<natural>Artist formerly known as "Prince"</natural></field>'
'<field to="auth.permission" name="permissions" rel="ManyToManyRel">'
"<object><natural>change_user</natural><natural>auth</natural>"
"<natural>user</natural></object></field>"
"</object>"
'<object pk="1" model="fixtures.book">'
'<field type="CharField" name="name">Music for all ages</field>'
'<field to="fixtures.person" name="authors" rel="ManyToManyRel">'
'<object><natural>Artist formerly known as "Prince"</natural></object>'
"<object><natural>Django Reinhardt</natural></object></field>"
"</object></django-objects>",
format="xml",
natural_foreign_keys=True,
)
@@ -418,33 +522,37 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
# Excluding fixtures app should only leave sites
self._dumpdata_assert(
["sites", "fixtures"],
'[{"pk": 1, "model": "sites.site", "fields": {"domain": "example.com", "name": "example.com"}}]',
'[{"pk": 1, "model": "sites.site", "fields": '
'{"domain": "example.com", "name": "example.com"}}]',
exclude_list=["fixtures"],
)
# Excluding fixtures.Article/Book should leave fixtures.Category
self._dumpdata_assert(
["sites", "fixtures"],
'[{"pk": 1, "model": "sites.site", "fields": {"domain": "example.com", "name": "example.com"}}, '
'{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": '
'"News Stories"}}]',
'[{"pk": 1, "model": "sites.site", '
'"fields": {"domain": "example.com", "name": "example.com"}}, '
'{"pk": 1, "model": "fixtures.category", "fields": '
'{"description": "Latest news stories", "title": "News Stories"}}]',
exclude_list=["fixtures.Article", "fixtures.Book"],
)
# Excluding fixtures and fixtures.Article/Book should be a no-op
self._dumpdata_assert(
["sites", "fixtures"],
'[{"pk": 1, "model": "sites.site", "fields": {"domain": "example.com", "name": "example.com"}}, '
'{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": '
'"News Stories"}}]',
'[{"pk": 1, "model": "sites.site", '
'"fields": {"domain": "example.com", "name": "example.com"}}, '
'{"pk": 1, "model": "fixtures.category", '
'"fields": {"description": "Latest news stories", '
'"title": "News Stories"}}]',
exclude_list=["fixtures.Article", "fixtures.Book"],
)
# Excluding sites and fixtures.Article/Book should only leave fixtures.Category
self._dumpdata_assert(
["sites", "fixtures"],
'[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": '
'"News Stories"}}]',
'[{"pk": 1, "model": "fixtures.category", "fields": '
'{"description": "Latest news stories", "title": "News Stories"}}]',
exclude_list=["fixtures.Article", "fixtures.Book", "sites"],
)
@@ -486,8 +594,9 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
# even those normally filtered by the manager
self._dumpdata_assert(
["fixtures.Spy"],
'[{"pk": %d, "model": "fixtures.spy", "fields": {"cover_blown": true}}, {"pk": %d, "model": '
'"fixtures.spy", "fields": {"cover_blown": false}}]' % (spy2.pk, spy1.pk),
'[{"pk": %d, "model": "fixtures.spy", "fields": {"cover_blown": true}}, '
'{"pk": %d, "model": "fixtures.spy", "fields": {"cover_blown": false}}]'
% (spy2.pk, spy1.pk),
use_base_manager=True,
)
@@ -496,15 +605,19 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
management.call_command("loaddata", "fixture2.json", verbosity=0)
self._dumpdata_assert(
["fixtures.Article"],
'[{"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", '
'"pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": '
'"Copyright is fine the way it is", "pub_date": "2006-06-16T14:00:00"}}]',
'[{"pk": 2, "model": "fixtures.article", '
'"fields": {"headline": "Poker has no place on ESPN", '
'"pub_date": "2006-06-16T12:00:00"}}, '
'{"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Copyright is fine the way it is", '
'"pub_date": "2006-06-16T14:00:00"}}]',
primary_keys="2,3",
)
self._dumpdata_assert(
["fixtures.Article"],
'[{"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", '
'[{"pk": 2, "model": "fixtures.article", '
'"fields": {"headline": "Poker has no place on ESPN", '
'"pub_date": "2006-06-16T12:00:00"}}]',
primary_keys="2",
)
@@ -514,9 +627,12 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
):
self._dumpdata_assert(
["fixtures"],
'[{"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", '
'"pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Copyright is fine the way it is", "pub_date": "2006-06-16T14:00:00"}}]',
'[{"pk": 2, "model": "fixtures.article", "fields": '
'{"headline": "Poker has no place on ESPN", '
'"pub_date": "2006-06-16T12:00:00"}}, '
'{"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Copyright is fine the way it is", '
'"pub_date": "2006-06-16T14:00:00"}}]',
primary_keys="2,3",
)
@@ -525,9 +641,12 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
):
self._dumpdata_assert(
"",
'[{"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", '
'"pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Copyright is fine the way it is", "pub_date": "2006-06-16T14:00:00"}}]',
'[{"pk": 2, "model": "fixtures.article", "fields": '
'{"headline": "Poker has no place on ESPN", '
'"pub_date": "2006-06-16T12:00:00"}}, '
'{"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Copyright is fine the way it is", '
'"pub_date": "2006-06-16T14:00:00"}}]',
primary_keys="2,3",
)
@@ -536,9 +655,12 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
):
self._dumpdata_assert(
["fixtures.Article", "fixtures.category"],
'[{"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", '
'"pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Copyright is fine the way it is", "pub_date": "2006-06-16T14:00:00"}}]',
'[{"pk": 2, "model": "fixtures.article", "fields": '
'{"headline": "Poker has no place on ESPN", '
'"pub_date": "2006-06-16T12:00:00"}}, '
'{"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Copyright is fine the way it is", '
'"pub_date": "2006-06-16T14:00:00"}}]',
primary_keys="2,3",
)
@@ -561,10 +683,14 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
management.call_command("loaddata", "fixture1.json", verbosity=0)
self._dumpdata_assert(
["fixtures"],
'[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": '
'"News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place '
'on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}]',
'[{"pk": 1, "model": "fixtures.category", "fields": '
'{"description": "Latest news stories", "title": "News Stories"}}, '
'{"pk": 2, "model": "fixtures.article", "fields": '
'{"headline": "Poker has no place on ESPN", '
'"pub_date": "2006-06-16T12:00:00"}}, '
'{"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Time to reform copyright", '
'"pub_date": "2006-06-16T13:00:00"}}]',
filename="dumpdata.json",
)
@@ -572,10 +698,14 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
management.call_command("loaddata", "fixture1.json", verbosity=0)
self._dumpdata_assert(
["fixtures"],
'[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": '
'"News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place '
'on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}]',
'[{"pk": 1, "model": "fixtures.category", "fields": '
'{"description": "Latest news stories", "title": "News Stories"}}, '
'{"pk": 2, "model": "fixtures.article", "fields": '
'{"headline": "Poker has no place on ESPN", '
'"pub_date": "2006-06-16T12:00:00"}}, '
'{"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Time to reform copyright", '
'"pub_date": "2006-06-16T13:00:00"}}]',
filename="dumpdata.json.gz",
)
@@ -584,10 +714,14 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
management.call_command("loaddata", "fixture1.json", verbosity=0)
self._dumpdata_assert(
["fixtures"],
'[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": '
'"News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place '
'on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}]',
'[{"pk": 1, "model": "fixtures.category", "fields": '
'{"description": "Latest news stories", "title": "News Stories"}}, '
'{"pk": 2, "model": "fixtures.article", "fields": '
'{"headline": "Poker has no place on ESPN", '
'"pub_date": "2006-06-16T12:00:00"}}, '
'{"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Time to reform copyright", '
'"pub_date": "2006-06-16T13:00:00"}}]',
filename="dumpdata.json.bz2",
)
@@ -596,10 +730,14 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
management.call_command("loaddata", "fixture1.json", verbosity=0)
self._dumpdata_assert(
["fixtures"],
'[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": '
'"News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place '
'on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}]',
'[{"pk": 1, "model": "fixtures.category", "fields": '
'{"description": "Latest news stories", "title": "News Stories"}}, '
'{"pk": 2, "model": "fixtures.article", "fields": '
'{"headline": "Poker has no place on ESPN", '
'"pub_date": "2006-06-16T12:00:00"}}, '
'{"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Time to reform copyright", '
'"pub_date": "2006-06-16T13:00:00"}}]',
filename="dumpdata.json.lzma",
)
@@ -608,10 +746,14 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
management.call_command("loaddata", "fixture1.json", verbosity=0)
self._dumpdata_assert(
["fixtures"],
'[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": '
'"News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place '
'on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}]',
'[{"pk": 1, "model": "fixtures.category", "fields": '
'{"description": "Latest news stories", "title": "News Stories"}}, '
'{"pk": 2, "model": "fixtures.article", "fields": '
'{"headline": "Poker has no place on ESPN", '
'"pub_date": "2006-06-16T12:00:00"}}, '
'{"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Time to reform copyright", '
'"pub_date": "2006-06-16T13:00:00"}}]',
filename="dumpdata.json.xz",
)
@@ -621,10 +763,14 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
with self.assertWarnsMessage(RuntimeWarning, msg):
self._dumpdata_assert(
["fixtures"],
'[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": '
'"News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place '
'on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}]',
'[{"pk": 1, "model": "fixtures.category", "fields": '
'{"description": "Latest news stories", "title": "News Stories"}}, '
'{"pk": 2, "model": "fixtures.article", "fields": '
'{"headline": "Poker has no place on ESPN", '
'"pub_date": "2006-06-16T12:00:00"}}, '
'{"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Time to reform copyright", '
'"pub_date": "2006-06-16T13:00:00"}}]',
filename="dumpdata.json.zip",
)
@@ -679,8 +825,8 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
warnings.simplefilter("always")
self._dumpdata_assert(
["fixtures.ProxySpy", "fixtures.Spy"],
'[{"pk": %d, "model": "fixtures.spy", "fields": {"cover_blown": false}}]'
% spy.pk,
'[{"pk": %d, "model": "fixtures.spy", '
'"fields": {"cover_blown": false}}]' % spy.pk,
)
self.assertEqual(len(warning_list), 0)
@@ -743,7 +889,8 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
management.call_command("loaddata", "fixture5", verbosity=0)
def test_db_loading(self):
# Load db fixtures 1 and 2. These will load using the 'default' database identifier implicitly
# Load db fixtures 1 and 2. These will load using the 'default'
# database identifier implicitly.
management.call_command("loaddata", "db_fixture_1", verbosity=0)
management.call_command("loaddata", "db_fixture_2", verbosity=0)
self.assertSequenceEqual(
@@ -809,7 +956,8 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
)
def test_loading_using(self):
# Load db fixtures 1 and 2. These will load using the 'default' database identifier explicitly
# Load fixtures 1 and 2. These will load using the 'default' database
# identifier explicitly.
management.call_command(
"loaddata", "db_fixture_1", verbosity=0, database="default"
)
@@ -825,7 +973,8 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
)
def test_unmatched_identifier_loading(self):
# Try to load db fixture 3. This won't load because the database identifier doesn't match
# Db fixture 3 won't load because the database identifier doesn't
# match.
with self.assertRaisesMessage(
CommandError, "No fixture named 'db_fixture_3' found."
):
@@ -857,14 +1006,23 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
# Dump the current contents of the database as a JSON fixture
self._dumpdata_assert(
["fixtures"],
'[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": '
'"News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place '
'on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}, {"pk": 1, "model": '
'"fixtures.tag", "fields": {"tagged_type": ["fixtures", "article"], "name": "copyright", "tagged_id": '
'3}}, {"pk": 2, "model": "fixtures.tag", "fields": {"tagged_type": ["fixtures", "article"], "name": '
'"law", "tagged_id": 3}}, {"pk": 1, "model": "fixtures.person", "fields": {"name": "Django '
'Reinhardt"}}, {"pk": 2, "model": "fixtures.person", "fields": {"name": "Stephane Grappelli"}}, '
'[{"pk": 1, "model": "fixtures.category", "fields": '
'{"description": "Latest news stories", "title": "News Stories"}}, '
'{"pk": 2, "model": "fixtures.article", "fields": '
'{"headline": "Poker has no place on ESPN", '
'"pub_date": "2006-06-16T12:00:00"}}, '
'{"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Time to reform copyright", '
'"pub_date": "2006-06-16T13:00:00"}}, '
'{"pk": 1, "model": "fixtures.tag", "fields": '
'{"tagged_type": ["fixtures", "article"], "name": "copyright", '
'"tagged_id": 3}}, '
'{"pk": 2, "model": "fixtures.tag", "fields": '
'{"tagged_type": ["fixtures", "article"], "name": "law", "tagged_id": 3}}, '
'{"pk": 1, "model": "fixtures.person", "fields": '
'{"name": "Django Reinhardt"}}, '
'{"pk": 2, "model": "fixtures.person", "fields": '
'{"name": "Stephane Grappelli"}}, '
'{"pk": 3, "model": "fixtures.person", "fields": {"name": "Prince"}}]',
natural_foreign_keys=True,
)
@@ -872,23 +1030,42 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
# Dump the current contents of the database as an XML fixture
self._dumpdata_assert(
["fixtures"],
'<?xml version="1.0" encoding="utf-8"?><django-objects version="1.0"><object pk="1" '
'model="fixtures.category"><field type="CharField" name="title">News Stories</field><field '
'type="TextField" name="description">Latest news stories</field></object><object pk="2" '
'model="fixtures.article"><field type="CharField" name="headline">Poker has no place on ESPN</field>'
'<field type="DateTimeField" name="pub_date">2006-06-16T12:00:00</field></object><object pk="3" '
'model="fixtures.article"><field type="CharField" name="headline">Time to reform copyright</field>'
'<field type="DateTimeField" name="pub_date">2006-06-16T13:00:00</field></object><object pk="1" '
'model="fixtures.tag"><field type="CharField" name="name">copyright</field><field '
'to="contenttypes.contenttype" name="tagged_type" rel="ManyToOneRel"><natural>fixtures</natural>'
'<natural>article</natural></field><field type="PositiveIntegerField" name="tagged_id">3</field>'
'</object><object pk="2" model="fixtures.tag"><field type="CharField" name="name">law</field><field '
'to="contenttypes.contenttype" name="tagged_type" rel="ManyToOneRel"><natural>fixtures</natural>'
'<natural>article</natural></field><field type="PositiveIntegerField" name="tagged_id">3</field>'
'</object><object pk="1" model="fixtures.person"><field type="CharField" name="name">Django Reinhardt'
'</field></object><object pk="2" model="fixtures.person"><field type="CharField" name="name">Stephane '
'Grappelli</field></object><object pk="3" model="fixtures.person"><field type="CharField" name="name">'
"Prince</field></object></django-objects>",
'<?xml version="1.0" encoding="utf-8"?><django-objects version="1.0">'
'<object pk="1" model="fixtures.category">'
'<field type="CharField" name="title">News Stories</field>'
'<field type="TextField" name="description">Latest news stories</field>'
"</object>"
'<object pk="2" model="fixtures.article">'
'<field type="CharField" name="headline">Poker has no place on ESPN</field>'
'<field type="DateTimeField" name="pub_date">2006-06-16T12:00:00</field>'
"</object>"
'<object pk="3" model="fixtures.article">'
'<field type="CharField" name="headline">Time to reform copyright</field>'
'<field type="DateTimeField" name="pub_date">2006-06-16T13:00:00</field>'
"</object>"
'<object pk="1" model="fixtures.tag">'
'<field type="CharField" name="name">copyright</field>'
'<field to="contenttypes.contenttype" name="tagged_type" '
'rel="ManyToOneRel"><natural>fixtures</natural>'
"<natural>article</natural></field>"
'<field type="PositiveIntegerField" name="tagged_id">3</field>'
"</object>"
'<object pk="2" model="fixtures.tag">'
'<field type="CharField" name="name">law</field>'
'<field to="contenttypes.contenttype" name="tagged_type" '
'rel="ManyToOneRel"><natural>fixtures</natural>'
"<natural>article</natural></field>"
'<field type="PositiveIntegerField" name="tagged_id">3</field>'
"</object>"
'<object pk="1" model="fixtures.person">'
'<field type="CharField" name="name">Django Reinhardt</field>'
"</object>"
'<object pk="2" model="fixtures.person">'
'<field type="CharField" name="name">Stephane Grappelli</field>'
"</object>"
'<object pk="3" model="fixtures.person">'
'<field type="CharField" name="name">Prince</field>'
"</object></django-objects>",
format="xml",
natural_foreign_keys=True,
)
@@ -1024,10 +1201,14 @@ class FixtureTransactionTests(DumpDataAssertMixin, TransactionTestCase):
# Dump the current contents of the database as a JSON fixture
self._dumpdata_assert(
["fixtures"],
'[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": '
'"News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place '
'on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}]',
'[{"pk": 1, "model": "fixtures.category", "fields": '
'{"description": "Latest news stories", "title": "News Stories"}}, '
'{"pk": 2, "model": "fixtures.article", "fields": '
'{"headline": "Poker has no place on ESPN", '
'"pub_date": "2006-06-16T12:00:00"}}, '
'{"pk": 3, "model": "fixtures.article", "fields": '
'{"headline": "Time to reform copyright", '
'"pub_date": "2006-06-16T13:00:00"}}]',
)
# Load fixture 4 (compressed), using format discovery
@@ -1108,7 +1289,8 @@ class ForwardReferenceTests(DumpDataAssertMixin, TestCase):
self._dumpdata_assert(
["fixtures"],
'[{"model": "fixtures.naturalkeything", '
'"fields": {"key": "t1", "other_thing": null, "other_things": [["t2"], ["t3"]]}}, '
'"fields": {"key": "t1", "other_thing": null, '
'"other_things": [["t2"], ["t3"]]}}, '
'{"model": "fixtures.naturalkeything", '
'"fields": {"key": "t2", "other_thing": null, "other_things": []}}, '
'{"model": "fixtures.naturalkeything", '