From 2e0f04507b17362239ba49830d26fec504d46978 Mon Sep 17 00:00:00 2001 From: Paolo Melchiorre Date: Thu, 7 May 2020 15:57:37 +0200 Subject: [PATCH] Added tests for loaddata with gzip/bzip2 compressed fixtures. Co-authored-by: Adam Johnson --- AUTHORS | 1 + tests/fixtures/fixtures/fixture5.json.bz2 | Bin 0 -> 166 bytes tests/fixtures/tests.py | 19 +++++++++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 tests/fixtures/fixtures/fixture5.json.bz2 diff --git a/AUTHORS b/AUTHORS index 3b91851ae6..79676cb559 100644 --- a/AUTHORS +++ b/AUTHORS @@ -695,6 +695,7 @@ answer newbie questions, and generally made Django that much better: Owen Griffiths Pablo Martín Panos Laganakos + Paolo Melchiorre Pascal Hartig Pascal Varet Patrik Sletmo diff --git a/tests/fixtures/fixtures/fixture5.json.bz2 b/tests/fixtures/fixtures/fixture5.json.bz2 new file mode 100644 index 0000000000000000000000000000000000000000..046bfa5820d833854fb6d4f486c316823a79a227 GIT binary patch literal 166 zcmV;X09pS+T4*^jL0KkKS!B2$KmY(YTYyARPzQ040E)kF-pU{VlnqRiQ_~7<9Jq^4k`jDni#5%eNr z>3}mN1InrIJz_k1y=rAIZ`e>?+S%=ZJS2i$m{*X#F=M+oX{SB`sl}-gfO>OUl)d52 U@R*M7_FV09aW^tpET3 literal 0 HcmV?d00001 diff --git a/tests/fixtures/tests.py b/tests/fixtures/tests.py index 1e723a7b66..cac3ccabc4 100644 --- a/tests/fixtures/tests.py +++ b/tests/fixtures/tests.py @@ -21,6 +21,12 @@ from .models import ( PrimaryKeyUUIDModel, ProxySpy, Spy, Tag, Visa, ) +try: + import bz2 # NOQA + HAS_BZ2 = True +except ImportError: + HAS_BZ2 = False + class TestCaseFixtureLoadingTests(TestCase): fixtures = ['fixture1.json', 'fixture2.json'] @@ -540,6 +546,19 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase): '', ]) + def test_compressed_loading_gzip(self): + management.call_command('loaddata', 'fixture5.json.gz', verbosity=0) + self.assertQuerysetEqual(Article.objects.all(), [ + '', + ]) + + @unittest.skipUnless(HAS_BZ2, 'No bz2 library detected.') + def test_compressed_loading_bz2(self): + management.call_command('loaddata', 'fixture5.json.bz2', verbosity=0) + self.assertQuerysetEqual(Article.objects.all(), [ + '', + ]) + def test_ambiguous_compressed_fixture(self): # The name "fixture5" is ambiguous, so loading raises an error. msg = "Multiple fixtures named 'fixture5'"