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 | |
| 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')
| -rw-r--r-- | tests/fixtures/tests.py | 26 | ||||
| -rw-r--r-- | tests/serializers/tests.py | 11 |
2 files changed, 37 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) diff --git a/tests/serializers/tests.py b/tests/serializers/tests.py index 4703d59c0d..f6ebcba23a 100644 --- a/tests/serializers/tests.py +++ b/tests/serializers/tests.py @@ -9,6 +9,7 @@ from datetime import datetime from xml.dom import minidom from django.core import management, serializers +from django.core.serializers.base import ProgressBar from django.db import connection, transaction from django.test import ( SimpleTestCase, TestCase, TransactionTestCase, mock, override_settings, @@ -188,6 +189,16 @@ class SerializersTestBase(object): mv_obj = obj_list[0].object self.assertEqual(mv_obj.title, movie_title) + def test_serialize_progressbar(self): + fake_stdout = StringIO() + serializers.serialize( + self.serializer_name, Article.objects.all(), + progress_output=fake_stdout, object_count=Article.objects.count() + ) + self.assertTrue( + fake_stdout.getvalue().endswith('[' + '.' * ProgressBar.progress_width + ']\n') + ) + def test_serialize_superfluous_queries(self): """Ensure no superfluous queries are made when serializing ForeignKeys |
