#NEWLINE# def test_loading_and_dumping( self ) : #NEWLINE# #INDENT# Site . objects . all ( ) . delete ( ) #NEWLINE# management . call_command ( 'loaddata' , 'fixture1.json' , verbosity = 0 ) #NEWLINE# self . assertQuerysetEqual ( Article . objects . all ( ) , [ '<Article: Time to reform copyright>' , '<Article: Poker has no place on ESPN>' ] ) #NEWLINE# 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": 10, "model": "fixtures.book", "fields": {"name": "Achieving self-awareness of Python programs", "authors": []}}]' ) #NEWLINE# self . _dumpdata_assert ( [ 'fixtures.Category' ] , '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}]' ) #NEWLINE# 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"}}]' ) #NEWLINE# 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"}}]' ) #NEWLINE# 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"}}]' ) #NEWLINE# 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": 10, "model": "fixtures.book", "fields": {"name": "Achieving self-awareness of Python programs", "authors": []}}]' ) #NEWLINE# 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": 10, "model": "fixtures.book", "fields": {"name": "Achieving self-awareness of Python programs", "authors": []}}]' ) #NEWLINE# 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"}}]' ) #NEWLINE# management . call_command ( 'loaddata' , 'fixture2.json' , verbosity = 0 ) #NEWLINE# self . assertQuerysetEqual ( Article . objects . all ( ) , [ '<Article: Django conquers world!>' , '<Article: Copyright is fine the way it is>' , '<Article: Poker has no place on ESPN>' ] ) #NEWLINE# management . call_command ( 'loaddata' , 'fixture3.xml' , verbosity = 0 ) #NEWLINE# self . assertQuerysetEqual ( Article . objects . all ( ) , [ '<Article: XML identified as leading cause of cancer>' , '<Article: Django conquers world!>' , '<Article: Copyright is fine the way it is>' , '<Article: Poker on TV is great!>' ] ) #NEWLINE# management . call_command ( 'loaddata' , 'fixture6.json' , verbosity = 0 ) #NEWLINE# self . assertQuerysetEqual ( Tag . objects . all ( ) , [ '<Tag: <Article: Copyright is fine the way it is> tagged "copyright">' , '<Tag: <Article: Copyright is fine the way it is> tagged "law">' ] , ordered = False ) #NEWLINE# management . call_command ( 'loaddata' , 'fixture7.xml' , verbosity = 0 ) #NEWLINE# self . assertQuerysetEqual ( Tag . objects . all ( ) , [ '<Tag: <Article: Copyright is fine the way it is> tagged "copyright">' , '<Tag: <Article: Copyright is fine the way it is> tagged "legal">' , '<Tag: <Article: Django conquers world!> tagged "django">' , '<Tag: <Article: Django conquers world!> tagged "world domination">' ] , ordered = False ) #NEWLINE# management . call_command ( 'loaddata' , 'fixture8.json' , verbosity = 0 ) #NEWLINE# self . assertQuerysetEqual ( Visa . objects . all ( ) , [ '<Visa: Django Reinhardt Can add user, Can change user, Can delete user>' , '<Visa: Stephane Grappelli Can add user>' , '<Visa: Prince >' ] , ordered = False ) #NEWLINE# management . call_command ( 'loaddata' , 'fixture9.xml' , verbosity = 0 ) #NEWLINE# self . assertQuerysetEqual ( Visa . objects . all ( ) , [ '<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>' ] , ordered = False ) #NEWLINE# self . assertQuerysetEqual ( Book . objects . all ( ) , [ '<Book: Achieving self-awareness of Python programs>' , '<Book: Music for all ages by Artist formerly known as "Prince" and Django Reinhardt>' ] ) #NEWLINE# with warnings . catch_warnings ( record = True ) as w : #NEWLINE# #INDENT# warnings . simplefilter ( 'always' ) #NEWLINE# management . call_command ( 'loaddata' , 'unknown.json' , verbosity = 0 ) #NEWLINE# #UNINDENT# self . assertEqual ( len ( w ) , 1 ) #NEWLINE# self . assertTrue ( w [ 0 ] . message , "No fixture named 'unknown' found." ) #NEWLINE# with warnings . catch_warnings ( record = True ) as w : #NEWLINE# #INDENT# management . call_command ( 'loaddata' , 'initial_data.json' , verbosity = 0 ) #NEWLINE# #UNINDENT# self . assertEqual ( len ( w ) , 0 ) #NEWLINE# self . assertQuerysetEqual ( Article . objects . all ( ) , [ '<Article: XML identified as leading cause of cancer>' , '<Article: Django conquers world!>' , '<Article: Copyright is fine the way it is>' , '<Article: Poker on TV is great!>' ] ) #NEWLINE# self . _dumpdata_assert ( [ 'fixtures.book' ] , '[{"pk": 1, "model": "fixtures.book", "fields": {"name": "Music for all ages", "authors": [3, 1]}}, {"pk": 10, "model": "fixtures.book", "fields": {"name": "Achieving self-awareness of Python programs", "authors": []}}]' ) #NEWLINE# 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": 10, "model": "fixtures.book", "fields": {"name": "Achieving self-awareness of Python programs", "authors": []}}]' , natural_keys = True ) #NEWLINE# 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": 10, "model": "fixtures.book", "fields": {"name": "Achieving self-awareness of Python programs", "authors": []}}]' , natural_keys = True ) #NEWLINE# self . _dumpdata_assert ( [ 'fixtures' ] , '<?xml version="1.0" encoding="utf-8"?>\n<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><object pk="10" model="fixtures.book"><field type="CharField" name="name">Achieving self-awareness of Python programs</field><field to="fixtures.person" name="authors" rel="ManyToManyRel"></field></object></django-objects>' , format = 'xml' , natural_keys = True )