On Mon, Jul 8, 2013 at 12:06 PM, Larry Martell <larry.mart...@gmail.com> wrote:
> Still working on getting my tests to run. I have 2 issues right now:
>
> 1) I want to load data from fixture files. In this case I am trying to
> load auth data to test the logins. I have this in my test code:
>
> from django.test import TestCase
> from django.contrib.auth.models import User, Permission
>
> class MeasDataTest(TestCase):
>
>     fixtures = ['auth_user', 'auth_permission']
>
> The auth_user and auth_permission files are in my apps fixtures dir
> (which is a subdir of where the models.py file is). But when run the
> test, it does not pick these up. What am I doing wrong here?

I figured out what the problem is here. My fixture files did not have
any extension on the file names. Once I renamed them to auth_user.json
they got picked up. But now I'm having a problem loading then. I
changed fixtures to:

fixtures = ['django_content_type', 'auth_user', 'auth_permission''

and it loads django_content_type and auth_user, but it fails on
auth_permission with:

IntegrityError: Could not load auth.Permission(pk=151): (1062,
"Duplicate entry '2-add_group' for key 'content_type_id'")

It appesars it's trying to add a row to django_content_type and it's
already there. I tried not loading the fixture for django_content_type
but I got the same error. These fixture files contain data I dumped
from my real db, so I know it's good. Googling this I found a few
posts with people having the same problem, but they are all a few
years old. People 'solved' this by using an external package
(django-fixture-magic) or excluding the auth tables or hand
re-ordering the records in the fixtures file. None of these seem like
good solutions to me. Is this still a known problem? Shouldn't I be
able to load data generated from a dump?


>
> 2) We have a stand alone program that loads data to the db. It's a
> django program in that it picks up the apps settings and uses the
> models and django API, but it's stand along in that it runs from cron
> and not from a web request. I want to run this from my tests, so I'm
> invoking it from my test class using subprocess.Popen. I would think
> it would use the test's environment and update the test db. But it
> does not do that, but neither does it update the 'real' database. It
> gives all indications of working though. I'm going to set a breakpoint
> in it and see if I can tell more about what it's doing, but should I
> expect an externally invoked script like this to hit the test db?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to