Ticket #6436: loaddata_absolute_20080121a.diff

File loaddata_absolute_20080121a.diff, 2.6 KB (added by btoll <btoll@…>, 17 years ago)

Regression test and proposed fix

  • django/core/management/commands/loaddata.py

     
    6565                else:
    6666                    print "Skipping fixture '%s': %s is not a known serialization format" % (fixture_name, format)
    6767
    68             for fixture_dir in app_fixtures + list(settings.FIXTURE_DIRS) + ['']:
     68            if os.path.isabs(fixture_name):
     69                fixture_dirs = [fixture_name]
     70            else:
     71                fixture_dirs = app_fixtures + list(settings.FIXTURE_DIRS) + ['']
     72
     73            for fixture_dir in fixture_dirs:
    6974                if verbosity > 1:
    7075                    print "Checking %s for fixtures..." % humanize(fixture_dir)
    7176
  • tests/regressiontests/fixtures_regress/fixtures/absolute.json

     
     1[
     2    {
     3        "pk": "1",
     4        "model": "fixtures_regress.absolute",
     5        "fields": {
     6            "name": "Load Absolute Path Test"
     7        }
     8    }
     9]
  • tests/regressiontests/fixtures_regress/models.py

     
    11from django.db import models
    22from django.contrib.auth.models import User
    33from django.conf import settings
     4import os
    45
    56class Animal(models.Model):
    67    name = models.CharField(max_length=150)
     
    2829            name = None
    2930        return unicode(name) + u' is owned by ' + unicode(self.owner)
    3031
     32class Absolute(models.Model):
     33
     34    name = models.CharField(max_length=40)
     35
     36    load_count = 0
     37
     38    def __init__(self, *args, **kwargs):
     39        super(Absolute, self).__init__(*args, **kwargs)
     40        Absolute.load_count += 1
     41
     42
    3143__test__ = {'API_TESTS':"""
    3244>>> from django.core import management
    3345
     
    4961>>> Stuff.objects.all()
    5062[<Stuff: None is owned by None>]
    5163
     64###############################################
     65# Regression test for ticket #6436 -- loading fixtures from absolute paths
     66
     67>>> load_absolute_path = os.path.join(os.path.dirname(__file__), 'fixtures', 'absolute.json')
     68>>> management.call_command('loaddata', load_absolute_path, verbosity=0)
     69>>> Absolute.load_count
     701
     71
    5272"""}
Back to Top