These are chat archives for django/django

15th
Feb 2016
Peter Bittner
@bittner
Feb 15 2016 09:27
I'm trying to provide initial data for a (BDD) test, not via fixtures but via the ORM. It's a comprehensive integration test that's why the initial data takes a while (couple of seconds) to load. Hence, I'd love to do this only once for all the tests; the initial state of the database should be with inital data. -- There seem to be two solution paths, (ab)using the post-migrate signal, and adding a migration just for the initial data. -- Anyone done this before?
Initial data in migrations seems odd though, considering the changing nature of initial data. (Also, you can't opt out as a user, e.g. for "sample data" in a CMS.) -- Is there a sensible way to use the post-migrate signal?
Matthew Schinckel
@schinckel
Feb 15 2016 10:27
bittner: Have you thought about using something like factory_boy for doing generating your test data.
Peter Bittner
@bittner
Feb 15 2016 10:29
schinkel: How would you do that with factory_boy in a BDD test setting? I'm practically mimicking the whole setup of a website project (generating the code, initializing the database, loading sample data, then check whether it all works as advertised in the documentation).
Matthew Schinckel
@schinckel
Feb 15 2016 10:30
bittner: I'm not 100% sure. The word "fixtures" triggers my factory-boy response ;)
factory boy just enables you make more instances (possibly with reduction in boilerplate) more easily.
(I also use it for random-ish generation too)
Peter Bittner
@bittner
Feb 15 2016 10:33
Exactly, and I'm not using fixtures. :smirk: You are talking about a unit test setting, correct? Do you have some good sample code?
friendOfOurs
@friendOfOurs
Feb 15 2016 12:32
is it possible to have a foreign key in model that refers to a superclass of two subclasses, and is it possible to distinct the subclasses later when used? smth like this:
Filip Figiel
@megapctr
Feb 15 2016 22:15
@friendOfOurs yes