diff options
| author | Claude Paroz <claude@2xlibre.net> | 2015-07-21 23:24:32 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2015-07-24 18:37:55 +0200 |
| commit | c296e55dc6a697c7e4d4be92b954633cda4a79b1 (patch) | |
| tree | e6c242384036dd8cf4360a3ff66241e2f6762fb9 /tests/fixtures/tests.py | |
| parent | 03aec35a12ea522ab9a60d6229b53e3ec3a871a3 (diff) | |
Fixed #22258 -- Added progress status for dumpdata when outputting to file
Thanks Gwildor Sok for the report and Tim Graham for the review.
Diffstat (limited to 'tests/fixtures/tests.py')
| -rw-r--r-- | tests/fixtures/tests.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/fixtures/tests.py b/tests/fixtures/tests.py index ab86bb7b79..4c0c9ee88f 100644 --- a/tests/fixtures/tests.py +++ b/tests/fixtures/tests.py @@ -9,6 +9,7 @@ import warnings from django.apps import apps from django.contrib.sites.models import Site from django.core import management +from django.core.serializers.base import ProgressBar from django.db import IntegrityError, connection from django.test import ( TestCase, TransactionTestCase, ignore_warnings, skipUnlessDBFeature, @@ -286,6 +287,31 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase): 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"}}]', filename='dumpdata.json') + def test_dumpdata_progressbar(self): + """ + Dumpdata shows a progress bar on the command line when --output is set, + stdout is a tty, and verbosity > 0. + """ + management.call_command('loaddata', 'fixture1.json', verbosity=0) + new_io = six.StringIO() + new_io.isatty = lambda: True + _, filename = tempfile.mkstemp() + options = { + 'format': 'json', + 'stdout': new_io, + 'stderr': new_io, + 'output': filename, + } + management.call_command('dumpdata', 'fixtures', **options) + self.assertTrue(new_io.getvalue().endswith('[' + '.' * ProgressBar.progress_width + ']\n')) + + # Test no progress bar when verbosity = 0 + options['verbosity'] = 0 + new_io = six.StringIO() + new_io.isatty = lambda: True + management.call_command('dumpdata', 'fixtures', **options) + self.assertEqual(new_io.getvalue(), '') + def test_compress_format_loading(self): # Load fixture 4 (compressed), using format specification management.call_command('loaddata', 'fixture4.json', verbosity=0) |
