Code

Ticket #6961: model_folder_fixture_load_test.patch

File model_folder_fixture_load_test.patch, 1.6 KB (added by zhaoz, 6 years ago)

needs init.py file in loaddata folder. Tests fixture loading with models folder as opposed to models.py

  • new file tests/regressiontests/loaddata/fixtures/relative.json

    diff --git tests/regressiontests/loaddata/__init__.py tests/regressiontests/loaddata/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git tests/regressiontests/loaddata/fixtures/relative.json tests/regressiontests/loaddata/fixtures/relative.json
    new file mode 100644
    index 0000000..0a626d9
    - +  
     1[ 
     2    { 
     3        "pk": "1",  
     4        "model": "loaddata.relative",  
     5        "fields": { 
     6            "name": "Load Relative Path Test" 
     7        } 
     8    } 
     9] 
  • new file tests/regressiontests/loaddata/models/__init__.py

    diff --git tests/regressiontests/loaddata/models/__init__.py tests/regressiontests/loaddata/models/__init__.py
    new file mode 100644
    index 0000000..0cd8b48
    - +  
     1from django.db import models 
     2from django.contrib.auth.models import User 
     3from django.conf import settings 
     4import os 
     5 
     6class Relative(models.Model): 
     7    name = models.CharField(max_length=40) 
     8 
     9    load_count = 0 
     10 
     11    def __init__(self, *args, **kwargs): 
     12        super(Relative, self).__init__(*args, **kwargs) 
     13        Relative.load_count += 1 
     14 
     15# Models to regresison check #7572 
     16class Channel(models.Model): 
     17    name = models.CharField(max_length=255) 
     18 
     19class Article(models.Model): 
     20    title = models.CharField(max_length=255) 
     21    channels = models.ManyToManyField(Channel) 
     22     
     23    class Meta: 
     24        ordering = ('id',) 
     25 
     26__test__ = {'API_TESTS':""" 
     27>>> from django.core import management 
     28 
     29>>> management.call_command('loaddata', 'relative', verbosity=0) 
     30>>> Relative.load_count 
     311 
     32 
     33"""}