Re: Generic relations and unit tests.

2009-04-16 Thread Stavros

Is there some way I can empty the contenttypes table before the
fixtures are loaded and have django load them normally? That would
take care of this problem, as it would mean that the proper
contenttypes would get loaded from the fixture. Unfortunately, I have
not been able to find a way to run code between creating the tables
and loading the fixture, in which I assume I need to do something like
ContentType.objects.delete().

Thanks for your help,
Poromenos

On Apr 11, 3:47 am, Russell Keith-Magee 
wrote:
> On Sat, Apr 11, 2009 at 5:53 AM,Poromenos wrote:
>
> > Hello,
> > I created a model that has a ForeignKey to ContentType, but now I
> > can't use my test fixtures, since the IDs they point to are random
> > every time the test database is created. I can't dump the contenttypes
> > data because then I get many duplicate inserts, since Django rebuilds
> > them every time it sets up the test DB. Is there any way for me to use
> > both ContentType and unit tests?
>
> The IDs won't be completely random, but they certainly will be fragile
> and subject to change.
>
> You have discovered ticket #7052; unfortunately, there isn't any easy
> fix at the moment.
>
> 1) Don't use fixtures - create your test objects in the setUp() method
> of your test using normal Python code.
>
> 2) Use the fixture to define the basic data in your objects, and then
> use the setUp() method to modify the contenttypes at runtime, based on
> the current values in the database. This means you don't serialize the
> contenttype objects themselves in your fixture, and you use and
> foreignkey reference to a contenttype as a temporary placeholder for
> the real value that will be inserted at runtime.
>
> Obviously, neither of these are ideal solutions. This bug is something
> I want to look at for Django v1.2.
>
> Yours
> Russ Magee %-)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Generic relations and unit tests.

2009-04-11 Thread Stavros

I agree with you on this, but it is often impractical due to the
volume of the data required. I have this data already in my database,
I shouldn't have to spend a few days moving it to the tests file...
Fixtures are a quick way to import your data to the test DB without
having to recreate everything... I'd really like a better solution to
this, as I can use either tests or contenttype at the moment and I'd
like to use both...

Thanks,
Stavros

On Apr 11, 3:54 am, Malcolm Tredinnick 
wrote:
> On Sat, 2009-04-11 at 08:47 +0800, Russell Keith-Magee wrote:
> > On Sat, Apr 11, 2009 at 5:53 AM, Poromenos  wrote:
>
> > > Hello,
> > > I created a model that has a ForeignKey to ContentType, but now I
> > > can't use my test fixtures, since the IDs they point to are random
> > > every time the test database is created. I can't dump the contenttypes
> > > data because then I get many duplicate inserts, since Django rebuilds
> > > them every time it sets up the test DB. Is there any way for me to use
> > > both ContentType and unit tests?
>
> > The IDs won't be completely random, but they certainly will be fragile
> > and subject to change.
>
> > You have discovered ticket #7052; unfortunately, there isn't any easy
> > fix at the moment.
>
> > 1) Don't use fixtures - create your test objects in the setUp() method
> > of your test using normal Python code.
>
> > 2) Use the fixture to define the basic data in your objects, and then
> > use the setUp() method to modify the contenttypes at runtime, based on
> > the current values in the database. This means you don't serialize the
> > contenttype objects themselves in your fixture, and you use and
> > foreignkey reference to a contenttype as a temporary placeholder for
> > the real value that will be inserted at runtime.
>
> > Obviously, neither of these are ideal solutions. This bug is something
> > I want to look at for Django v1.2.
>
> Well, I'd argue (1) is the ideal solution. Creating objects
> programmatically is robust, self-documenting and encourages testers to
> think about the minimum requirements needed for a self-contained
> unittest. It's also fairly easy. Tends to be my normal practice.
>
> So opinions clearly differ there. Which doesn't invalidate Russell's
> opinion, but I wouldn't want people to think it's all horrible when
> there's already a perfectly standard and supported way of doing this
> (the setUp() method exists to set things up for unittests).
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Generic relations and unit tests.

2009-04-10 Thread Malcolm Tredinnick

On Sat, 2009-04-11 at 08:47 +0800, Russell Keith-Magee wrote:
> On Sat, Apr 11, 2009 at 5:53 AM, Poromenos  wrote:
> >
> > Hello,
> > I created a model that has a ForeignKey to ContentType, but now I
> > can't use my test fixtures, since the IDs they point to are random
> > every time the test database is created. I can't dump the contenttypes
> > data because then I get many duplicate inserts, since Django rebuilds
> > them every time it sets up the test DB. Is there any way for me to use
> > both ContentType and unit tests?
> 
> The IDs won't be completely random, but they certainly will be fragile
> and subject to change.
> 
> You have discovered ticket #7052; unfortunately, there isn't any easy
> fix at the moment.
> 
> 1) Don't use fixtures - create your test objects in the setUp() method
> of your test using normal Python code.
> 
> 2) Use the fixture to define the basic data in your objects, and then
> use the setUp() method to modify the contenttypes at runtime, based on
> the current values in the database. This means you don't serialize the
> contenttype objects themselves in your fixture, and you use and
> foreignkey reference to a contenttype as a temporary placeholder for
> the real value that will be inserted at runtime.
> 
> Obviously, neither of these are ideal solutions. This bug is something
> I want to look at for Django v1.2.

Well, I'd argue (1) is the ideal solution. Creating objects
programmatically is robust, self-documenting and encourages testers to
think about the minimum requirements needed for a self-contained
unittest. It's also fairly easy. Tends to be my normal practice.

So opinions clearly differ there. Which doesn't invalidate Russell's
opinion, but I wouldn't want people to think it's all horrible when
there's already a perfectly standard and supported way of doing this
(the setUp() method exists to set things up for unittests).

Regards,
Malcolm


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Generic relations and unit tests.

2009-04-10 Thread Russell Keith-Magee

On Sat, Apr 11, 2009 at 5:53 AM, Poromenos  wrote:
>
> Hello,
> I created a model that has a ForeignKey to ContentType, but now I
> can't use my test fixtures, since the IDs they point to are random
> every time the test database is created. I can't dump the contenttypes
> data because then I get many duplicate inserts, since Django rebuilds
> them every time it sets up the test DB. Is there any way for me to use
> both ContentType and unit tests?

The IDs won't be completely random, but they certainly will be fragile
and subject to change.

You have discovered ticket #7052; unfortunately, there isn't any easy
fix at the moment.

1) Don't use fixtures - create your test objects in the setUp() method
of your test using normal Python code.

2) Use the fixture to define the basic data in your objects, and then
use the setUp() method to modify the contenttypes at runtime, based on
the current values in the database. This means you don't serialize the
contenttype objects themselves in your fixture, and you use and
foreignkey reference to a contenttype as a temporary placeholder for
the real value that will be inserted at runtime.

Obviously, neither of these are ideal solutions. This bug is something
I want to look at for Django v1.2.

Yours
Russ Magee %-)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Generic relations and unit tests.

2009-04-10 Thread Poromenos

Hello,
I created a model that has a ForeignKey to ContentType, but now I
can't use my test fixtures, since the IDs they point to are random
every time the test database is created. I can't dump the contenttypes
data because then I get many duplicate inserts, since Django rebuilds
them every time it sets up the test DB. Is there any way for me to use
both ContentType and unit tests?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---