(self)
| 134 | |
| 135 | class FixtureLoadingTests(DumpDataAssertMixin, TestCase): |
| 136 | def test_loading_and_dumping(self): |
| 137 | apps.clear_cache() |
| 138 | Site.objects.all().delete() |
| 139 | # Load fixture 1. Single JSON file, with two objects. |
| 140 | management.call_command("loaddata", "fixture1.json", verbosity=0) |
| 141 | self.assertSequenceEqual( |
| 142 | Article.objects.values_list("headline", flat=True), |
| 143 | ["Time to reform copyright", "Poker has no place on ESPN"], |
| 144 | ) |
| 145 | |
| 146 | # Dump the current contents of the database as a JSON fixture |
| 147 | self._dumpdata_assert( |
| 148 | ["fixtures"], |
| 149 | '[{"pk": 1, "model": "fixtures.category", "fields": ' |
| 150 | '{"description": "Latest news stories", "title": "News Stories"}}, ' |
| 151 | '{"pk": 2, "model": "fixtures.article", "fields": ' |
| 152 | '{"headline": "Poker has no place on ESPN", ' |
| 153 | '"pub_date": "2006-06-16T12:00:00"}}, ' |
| 154 | '{"pk": 3, "model": "fixtures.article", "fields": ' |
| 155 | '{"headline": "Time to reform copyright", ' |
| 156 | '"pub_date": "2006-06-16T13:00:00"}}]', |
| 157 | ) |
| 158 | |
| 159 | # Try just dumping the contents of fixtures.Category |
| 160 | self._dumpdata_assert( |
| 161 | ["fixtures.Category"], |
| 162 | '[{"pk": 1, "model": "fixtures.category", "fields": ' |
| 163 | '{"description": "Latest news stories", "title": "News Stories"}}]', |
| 164 | ) |
| 165 | |
| 166 | # ...and just fixtures.Article |
| 167 | self._dumpdata_assert( |
| 168 | ["fixtures.Article"], |
| 169 | '[{"pk": 2, "model": "fixtures.article", "fields": ' |
| 170 | '{"headline": "Poker has no place on ESPN", ' |
| 171 | '"pub_date": "2006-06-16T12:00:00"}}, ' |
| 172 | '{"pk": 3, "model": "fixtures.article", "fields": ' |
| 173 | '{"headline": "Time to reform copyright", ' |
| 174 | '"pub_date": "2006-06-16T13:00:00"}}]', |
| 175 | ) |
| 176 | |
| 177 | # ...and both |
| 178 | self._dumpdata_assert( |
| 179 | ["fixtures.Category", "fixtures.Article"], |
| 180 | '[{"pk": 1, "model": "fixtures.category", "fields": ' |
| 181 | '{"description": "Latest news stories", "title": "News Stories"}}, ' |
| 182 | '{"pk": 2, "model": "fixtures.article", "fields": ' |
| 183 | '{"headline": "Poker has no place on ESPN", ' |
| 184 | '"pub_date": "2006-06-16T12:00:00"}}, ' |
| 185 | '{"pk": 3, "model": "fixtures.article", "fields": ' |
| 186 | '{"headline": "Time to reform copyright", ' |
| 187 | '"pub_date": "2006-06-16T13:00:00"}}]', |
| 188 | ) |
| 189 | |
| 190 | # Specify a specific model twice |
| 191 | self._dumpdata_assert( |
| 192 | ["fixtures.Article", "fixtures.Article"], |
| 193 | ( |
nothing calls this directly
no test coverage detected