populate_db: Fix cache flushing when rebuilding test database.

This fixes a similar problem to the last commit; we don't use
memcached with the test database, so we don't need to flush memcached
when rebuilding it.

(And if we try, we'll get exceptions trying to access the relevant
settings).
This commit is contained in:
Tim Abbott 2020-01-13 18:22:34 -08:00
parent 571ce2f5cb
commit 0dc7542363
1 changed files with 10 additions and 4 deletions

View File

@ -50,10 +50,16 @@ def clear_database() -> None:
# Hacky function only for use inside populate_db. Designed to # Hacky function only for use inside populate_db. Designed to
# allow running populate_db repeatedly in series to work without # allow running populate_db repeatedly in series to work without
# flushing memcached or clearing the database manually. # flushing memcached or clearing the database manually.
pylibmc.Client(
[default_cache['LOCATION']], # With `zproject.test_settings`, we aren't using real memcached
behaviors=default_cache["OPTIONS"] # type: ignore # settings not typed properly # and; we only need to flush memcached if we're populating a
).flush_all() # database that would be used with it (i.e. zproject.dev_settings).
if default_cache['BACKEND'] == 'django_pylibmc.memcached.PyLibMCCache':
pylibmc.Client(
[default_cache['LOCATION']],
behaviors=default_cache["OPTIONS"] # type: ignore # settings not typed properly
).flush_all()
model = None # type: Any # Hack because mypy doesn't know these are model classes model = None # type: Any # Hack because mypy doesn't know these are model classes
for model in [Message, Stream, UserProfile, Recipient, for model in [Message, Stream, UserProfile, Recipient,
Realm, Subscription, Huddle, UserMessage, Client, Realm, Subscription, Huddle, UserMessage, Client,