Hi David,

On 11/10/2014 08:14 AM, dpalao.pyt...@gmail.com wrote:
> Probably I was not clear in my original post. My problem is precisely
> how to switch managed to True just before the tests and put it back to
> False afterwards to avoid creating of tables by hand during the tests.
> That is precisely the trick described in the link I included in my first
> post: subclass the DiscoverRunner class. But I don't know how to achieve it.

Fred posted about how to trick the ORM into creating these tables for
you. For what it's worth, if I were in this situation I would not try to
flip `managed` to `True` during testing for these tables. In production
these tables have a fixed known schema, they are not created by the
Django ORM. I'd prefer to replicate that situation in testing as well,
so that my tests would catch a mis-match between my ORM models for the
legacy tables and the actual schema of the tables.

So the approach I'd take instead would be to bypass the ORM entirely
when creating these tables. Instead create a SQL file with the DDL for
the exact schema of the real legacy tables, and then hook into the test
runner to run that SQL file directly against your test database.
Specifically, I think in a subclass of DiscoverRunner you could override
the `setup_databases` method and run your SQL immediately after that.

(Note that I haven't actually done this, so there may be caveats I
haven't anticipated. If you want a battle-tested solution, you might
prefer Fred's. But if I was in your situation, I would first try to get
a solution working that doesn't have the ORM create these tables for
testing.)

Carl

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5460FCAC.9090309%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.

Reply via email to