Generic Foreign Keys in fixtures

174 views
Skip to first unread message

LurkingFrog

unread,
Mar 24, 2011, 1:34:51 PM3/24/11
to Django users
Currently, I am writing unit tests for an application that uses
generic foreign keys. Since the contenttypes are regenerated every
test, I was wondering the most effective way to reconcile the existing
test data with the new contenttypes PKs.

My current thinking is to make an explicit fixture the dumpdata from
contenttypes at the same time I generate the other fixtures I plan to
use in my tests. From there, I will add code to manually update the
content types in the database to the ones in the aforementioned
contenttypes fixture and call it from the __init__.py in each
application/tests folder. Since that __init__.py should be called
after the migrations are completed, this should make all the data line
up.

My question is whether this is the most efficient / effective way to
solve this issue.

Thanks,
Dave

Simone Dalla

unread,
Mar 24, 2011, 2:29:23 PM3/24/11
to django...@googlegroups.com


2011/3/24 LurkingFrog <lurki...@gmail.com>


--
Simo

- Registered Linux User #395060

- Software is like sex, it is better when it is free  --> Linus B. Torvalds

Shawn Milochik

unread,
Mar 24, 2011, 2:38:32 PM3/24/11
to django...@googlegroups.com
On Thu, Mar 24, 2011 at 2:29 PM, Simone Dalla <simo...@gmail.com> wrote:
>
> maybe option --natural
> http://docs.djangoproject.com/en/1.3/ref/django-admin/#dumpdata-appname-appname-appname-model
>


Natural keys were introduced in 1.2. How would you do this in 1.1?

Or maybe there's a cleaner answer when the problem is re-stated:

How can you use dumpdata and loaddata to dump and reload fixtures when
you're using generic foreign keys?

(I work with the OP, so I'm not hijacking the thread).

Thanks,
Shawn

Simone Dalla

unread,
Mar 24, 2011, 3:29:17 PM3/24/11
to django...@googlegroups.com


2011/3/24 Shawn Milochik <sh...@milochik.com>

On Thu, Mar 24, 2011 at 2:29 PM, Simone Dalla <simo...@gmail.com> wrote:
>
> maybe option --natural
> http://docs.djangoproject.com/en/1.3/ref/django-admin/#dumpdata-appname-appname-appname-model
>


Natural keys were introduced in 1.2. How would you do this in 1.1?

1.2 

Shawn Milochik

unread,
Mar 24, 2011, 3:31:05 PM3/24/11
to django...@googlegroups.com
On Thu, Mar 24, 2011 at 3:29 PM, Simone Dalla <simo...@gmail.com> wrote:
>> Natural keys were introduced in 1.2. How would you do this in 1.1?
>
> 1.2
> --

You mean 1.3, right? ;o)

Reply all
Reply to author
Forward
0 new messages