mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Fixed #21551 -- Reenabled loading fixtures from subdirectory
This was a regression in Django 1.6 that was only partially
restored in 839940f27f
.
Thanks Jonas Haag for the report.
This commit is contained in:
parent
8a9c8bb907
commit
41ebc4838d
@ -178,11 +178,15 @@ class Command(BaseCommand):
|
|||||||
if self.verbosity >= 2:
|
if self.verbosity >= 2:
|
||||||
self.stdout.write("Loading '%s' fixtures..." % fixture_name)
|
self.stdout.write("Loading '%s' fixtures..." % fixture_name)
|
||||||
|
|
||||||
if os.path.sep in fixture_name:
|
if os.path.isabs(fixture_name):
|
||||||
fixture_dirs = [os.path.dirname(fixture_name)]
|
fixture_dirs = [os.path.dirname(fixture_name)]
|
||||||
fixture_name = os.path.basename(fixture_name)
|
fixture_name = os.path.basename(fixture_name)
|
||||||
else:
|
else:
|
||||||
fixture_dirs = self.fixture_dirs
|
fixture_dirs = self.fixture_dirs
|
||||||
|
if os.path.sep in fixture_name:
|
||||||
|
fixture_dirs = [os.path.join(dir_, os.path.dirname(fixture_name))
|
||||||
|
for dir_ in fixture_dirs]
|
||||||
|
fixture_name = os.path.basename(fixture_name)
|
||||||
|
|
||||||
suffixes = ('.'.join(ext for ext in combo if ext)
|
suffixes = ('.'.join(ext for ext in combo if ext)
|
||||||
for combo in product(databases, ser_fmts, cmp_fmts))
|
for combo in product(databases, ser_fmts, cmp_fmts))
|
||||||
|
@ -28,7 +28,8 @@ Bug fixes
|
|||||||
* Fixed ``django.contrib.humanize`` translations where the unicode sequence
|
* Fixed ``django.contrib.humanize`` translations where the unicode sequence
|
||||||
for the non-breaking space was returned verbatim (#21415).
|
for the non-breaking space was returned verbatim (#21415).
|
||||||
* Fixed :djadmin:`loaddata` error when fixture file name contained any dots
|
* Fixed :djadmin:`loaddata` error when fixture file name contained any dots
|
||||||
non related to file extensions (#21457).
|
non related to file extensions (#21457) or when fixture path was relative
|
||||||
|
but located in a subdirectory (#21551).
|
||||||
* Fixed display of inline instances in formsets when parent has 0 for primary
|
* Fixed display of inline instances in formsets when parent has 0 for primary
|
||||||
key (#21472).
|
key (#21472).
|
||||||
* Fixed a regression where custom querysets for foreign keys were overwritten
|
* Fixed a regression where custom querysets for foreign keys were overwritten
|
||||||
|
9
tests/fixtures_regress/fixtures_1/inner/absolute.json
Normal file
9
tests/fixtures_regress/fixtures_1/inner/absolute.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"pk": "1",
|
||||||
|
"model": "fixtures_regress.absolute",
|
||||||
|
"fields": {
|
||||||
|
"name": "Load Absolute Path Test"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
@ -2,6 +2,7 @@
|
|||||||
# Unittests for fixtures.
|
# Unittests for fixtures.
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import warnings
|
import warnings
|
||||||
@ -19,12 +20,13 @@ from django.utils.encoding import force_text
|
|||||||
from django.utils._os import upath
|
from django.utils._os import upath
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
from django.utils.six import PY3, StringIO
|
from django.utils.six import PY3, StringIO
|
||||||
import json
|
|
||||||
|
|
||||||
from .models import (Animal, Stuff, Absolute, Parent, Child, Article, Widget,
|
from .models import (Animal, Stuff, Absolute, Parent, Child, Article, Widget,
|
||||||
Store, Person, Book, NKChild, RefToNKChild, Circle1, Circle2, Circle3,
|
Store, Person, Book, NKChild, RefToNKChild, Circle1, Circle2, Circle3,
|
||||||
ExternalDependency, Thingy)
|
ExternalDependency, Thingy)
|
||||||
|
|
||||||
|
_cur_dir = os.path.dirname(os.path.abspath(upath(__file__)))
|
||||||
|
|
||||||
|
|
||||||
class TestFixtures(TestCase):
|
class TestFixtures(TestCase):
|
||||||
|
|
||||||
@ -150,12 +152,11 @@ class TestFixtures(TestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(Absolute.objects.count(), 1)
|
self.assertEqual(Absolute.objects.count(), 1)
|
||||||
|
|
||||||
def test_relative_path(self):
|
def test_relative_path(self, path=['fixtures', 'absolute.json']):
|
||||||
directory = os.path.dirname(upath(__file__))
|
relative_path = os.path.join(*path)
|
||||||
relative_path = os.path.join('fixtures', 'absolute.json')
|
|
||||||
cwd = os.getcwd()
|
cwd = os.getcwd()
|
||||||
try:
|
try:
|
||||||
os.chdir(directory)
|
os.chdir(_cur_dir)
|
||||||
management.call_command(
|
management.call_command(
|
||||||
'loaddata',
|
'loaddata',
|
||||||
relative_path,
|
relative_path,
|
||||||
@ -165,6 +166,10 @@ class TestFixtures(TestCase):
|
|||||||
os.chdir(cwd)
|
os.chdir(cwd)
|
||||||
self.assertEqual(Absolute.objects.count(), 1)
|
self.assertEqual(Absolute.objects.count(), 1)
|
||||||
|
|
||||||
|
@override_settings(FIXTURE_DIRS=[os.path.join(_cur_dir, 'fixtures_1')])
|
||||||
|
def test_relative_path_in_fixture_dirs(self):
|
||||||
|
self.test_relative_path(path=['inner', 'absolute.json'])
|
||||||
|
|
||||||
def test_path_containing_dots(self):
|
def test_path_containing_dots(self):
|
||||||
management.call_command(
|
management.call_command(
|
||||||
'loaddata',
|
'loaddata',
|
||||||
@ -424,8 +429,6 @@ class TestFixtures(TestCase):
|
|||||||
verbosity=0,
|
verbosity=0,
|
||||||
)
|
)
|
||||||
|
|
||||||
_cur_dir = os.path.dirname(os.path.abspath(upath(__file__)))
|
|
||||||
|
|
||||||
@override_settings(FIXTURE_DIRS=[os.path.join(_cur_dir, 'fixtures_1'),
|
@override_settings(FIXTURE_DIRS=[os.path.join(_cur_dir, 'fixtures_1'),
|
||||||
os.path.join(_cur_dir, 'fixtures_2')])
|
os.path.join(_cur_dir, 'fixtures_2')])
|
||||||
def test_loaddata_forward_refs_split_fixtures(self):
|
def test_loaddata_forward_refs_split_fixtures(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user