Hi,
I am just getting started with Django (1.2.5) on Fedora. I would like
to create separate test data files to be loaded to the test database
for each test case for the mysite/ app. I have the following code
snippets (based on the Django tutorial):
=== mysite/polls/tests.py ===
from django.test import TestCase
from polls.models import Poll
class SimpleTestCase(TestCase):
fixtures = ['poll.json',]
=== mysite/polls/models.py ===
from django.db import models
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __unicode__(self):
return self.question
def show(self):
string = "show"
return string
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(max_length=200)
votes = models.IntegerField()
def __unicode__(self):
return self.choice
=== mysite/polls/fixtures/poll.json ===
[
{
"model": "polls.poll",
"pk": 1,
"fields": {
"question": "What is your date of birth?",
"pub_date": "2011-03-08 12:30:45"
}
}
]
=== Output ===
$ ./manage.py test polls
Creating test database 'default'...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log
Creating table polls_poll
Creating table polls_choice
Installing index for auth.Permission model
Installing index for auth.Group_permissions model
Installing index for auth.User_user_permissions model
Installing index for auth.User_groups model
Installing index for auth.Message model
Installing index for admin.LogEntry model
Installing index for polls.Choice model
No fixtures found.
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
Destroying test database 'default'...
If I use a file initial_data.json in mysite/polls/fixtures, and
running ./manage.py test polls, it loads the file, even if I specify
'poll.json' in the tests.py file. I have tried using the following in
settings.py to no avail.
FIXTURE_DIRS = ( '/tmp/mysite/polls/fixtures/', )
What could be missing? If you have a working app/ solution for that
above that I can refer, it will be very helpful, or if you suggest any
other methods to load dynamic test data, please let me know.
Thanks!
SK
--
Shakthi Kannan
http://www.shakthimaan.com
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.