Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #20933 -- Allowed loaddata to load fixtures from relative paths.

  • Loading branch information...
commit 96346ed5adf90849ac5ebd10d74377ed2e0c061c 1 parent 859e678
Florian Apolloner authored August 20, 2013
2  django/core/management/commands/loaddata.py
@@ -183,7 +183,7 @@ def _find_fixtures(self, fixture_label):
183 183
         if self.verbosity >= 2:
184 184
             self.stdout.write("Loading '%s' fixtures..." % fixture_name)
185 185
 
186  
-        if os.path.isabs(fixture_name):
  186
+        if os.path.sep in fixture_name:
187 187
             fixture_dirs = [os.path.dirname(fixture_name)]
188 188
             fixture_name = os.path.basename(fixture_name)
189 189
         else:
4  docs/howto/initial-data.txt
@@ -90,8 +90,8 @@ fixtures. You can set the :setting:`FIXTURE_DIRS` setting to a list of
90 90
 additional directories where Django should look.
91 91
 
92 92
 When running :djadmin:`manage.py loaddata <loaddata>`, you can also
93  
-specify an absolute path to a fixture file, which overrides searching
94  
-the usual directories.
  93
+specify a path to a fixture file, which overrides searching the usual
  94
+directories.
95 95
 
96 96
 .. seealso::
97 97
 
6  tests/fixtures_regress/models.py
@@ -39,12 +39,6 @@ def __str__(self):
39 39
 class Absolute(models.Model):
40 40
     name = models.CharField(max_length=40)
41 41
 
42  
-    load_count = 0
43  
-
44  
-    def __init__(self, *args, **kwargs):
45  
-        super(Absolute, self).__init__(*args, **kwargs)
46  
-        Absolute.load_count += 1
47  
-
48 42
 
49 43
 class Parent(models.Model):
50 44
     name = models.CharField(max_length=10)
17  tests/fixtures_regress/tests.py
@@ -148,7 +148,22 @@ def test_absolute_path(self):
148 148
             load_absolute_path,
149 149
             verbosity=0,
150 150
         )
151  
-        self.assertEqual(Absolute.load_count, 1)
  151
+        self.assertEqual(Absolute.objects.count(), 1)
  152
+
  153
+    def test_relative_path(self):
  154
+        directory = os.path.dirname(upath(__file__))
  155
+        relative_path = os.path.join('fixtures', 'absolute.json')
  156
+        cwd = os.getcwd()
  157
+        try:
  158
+            os.chdir(directory)
  159
+            management.call_command(
  160
+                'loaddata',
  161
+                relative_path,
  162
+                verbosity=0,
  163
+            )
  164
+        finally:
  165
+            os.chdir(cwd)
  166
+        self.assertEqual(Absolute.objects.count(), 1)
152 167
 
153 168
     def test_unknown_format(self):
154 169
         """

0 notes on commit 96346ed

Please sign in to comment.
Something went wrong with that request. Please try again.