summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2013-12-05 22:55:33 +0100
committerClaude Paroz <claude@2xlibre.net>2013-12-07 10:48:34 +0100
commit45c0d2e1ce0fe024e4a80c9dde8263f5ff59d577 (patch)
tree5019c6d7d46ec27877288b600221a1fc607a22d6 /tests
parent34c4b93c84e86665d66d0b31da8e30fd581d5b5f (diff)
[1.6.x] 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. Backport of 41ebc4838d from master.
Diffstat (limited to 'tests')
-rw-r--r--tests/fixtures_regress/fixtures_1/inner/absolute.json9
-rw-r--r--tests/fixtures_regress/tests.py17
2 files changed, 19 insertions, 7 deletions
diff --git a/tests/fixtures_regress/fixtures_1/inner/absolute.json b/tests/fixtures_regress/fixtures_1/inner/absolute.json
new file mode 100644
index 0000000000..d62ac03fff
--- /dev/null
+++ b/tests/fixtures_regress/fixtures_1/inner/absolute.json
@@ -0,0 +1,9 @@
+[
+ {
+ "pk": "1",
+ "model": "fixtures_regress.absolute",
+ "fields": {
+ "name": "Load Absolute Path Test"
+ }
+ }
+]
diff --git a/tests/fixtures_regress/tests.py b/tests/fixtures_regress/tests.py
index 9ce0337e67..571fd859ef 100644
--- a/tests/fixtures_regress/tests.py
+++ b/tests/fixtures_regress/tests.py
@@ -2,6 +2,7 @@
# Unittests for fixtures.
from __future__ import absolute_import, unicode_literals
+import json
import os
import re
import warnings
@@ -19,12 +20,13 @@ from django.utils.encoding import force_text
from django.utils._os import upath
from django.utils import six
from django.utils.six import PY3, StringIO
-import json
from .models import (Animal, Stuff, Absolute, Parent, Child, Article, Widget,
Store, Person, Book, NKChild, RefToNKChild, Circle1, Circle2, Circle3,
ExternalDependency, Thingy)
+_cur_dir = os.path.dirname(os.path.abspath(upath(__file__)))
+
class TestFixtures(TestCase):
@@ -150,12 +152,11 @@ class TestFixtures(TestCase):
)
self.assertEqual(Absolute.objects.count(), 1)
- def test_relative_path(self):
- directory = os.path.dirname(upath(__file__))
- relative_path = os.path.join('fixtures', 'absolute.json')
+ def test_relative_path(self, path=['fixtures', 'absolute.json']):
+ relative_path = os.path.join(*path)
cwd = os.getcwd()
try:
- os.chdir(directory)
+ os.chdir(_cur_dir)
management.call_command(
'loaddata',
relative_path,
@@ -165,6 +166,10 @@ class TestFixtures(TestCase):
os.chdir(cwd)
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):
management.call_command(
'loaddata',
@@ -412,8 +417,6 @@ class TestFixtures(TestCase):
verbosity=0,
)
- _cur_dir = os.path.dirname(os.path.abspath(upath(__file__)))
-
@override_settings(FIXTURE_DIRS=[os.path.join(_cur_dir, 'fixtures_1'),
os.path.join(_cur_dir, 'fixtures_2')])
def test_loaddata_forward_refs_split_fixtures(self):