From bc2ace726c74dbc01c481990a8f1cd8d2b58441f Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 28 Nov 2012 17:09:11 -0500 Subject: [PATCH] Fix bad Django test suite interaction with get_client default. authenticated_api_view and authenticated_json_view call update_user_activity with a client generated using @has_request_variables with a default of e.g. get_client("website"). Because that get_client call only happens once on importing the module, if those client objects didn't exist previously in the fixtures, then the first test will generate objects with ids 2 and 3, and then the second test will dump the database, restore from the fixtures, and then eventually generate client objects with ids 4 and 5. But since the default values were only computed at module load, we'll still end calling add_user_activity with client objects with ids 2 and 3, which don't exist in the newly restored database. Fix this madness by just making sure those two client objects exist in the database. (imported from commit d940e129d077a560d9a0f96ec3daa2e16ce21c8b) --- zephyr/management/commands/populate_db.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/zephyr/management/commands/populate_db.py b/zephyr/management/commands/populate_db.py index 05ab6f8fe5..5a7a675fc0 100644 --- a/zephyr/management/commands/populate_db.py +++ b/zephyr/management/commands/populate_db.py @@ -208,6 +208,12 @@ class Command(BaseCommand): ] create_users(realms, internal_humbug_users_nosubs) + # Create the "website" and "API" clients; if we don't, the + # default values in zephyr/decorators.py will not work + # with the Django test suite. + get_client("website") + get_client("API") + self.stdout.write("Successfully populated test database.\n") if options["replay_old_messages"]: restore_saved_messages()