def test_memcache_invalidates_when_the_request_ends(self): translation.activate("de") gettext("Hello World!") # Generates the cache # Wait for any background threads to finish while translations_loading(): pass # Set the invalidation key key = _language_invalidation_key("de") cache.set(key, datetime.datetime.utcnow()) # This shouldn't make a query, the invalidation hasn't applied yet with sleuth.watch("google.appengine.api.datastore.Query.Run") as query: trans = gettext("Goodbye World!") self.assertEqual(trans, "Auf Wiedersehen Welt!") self.assertFalse(query.called) # Run the finished signal invalidate_caches_if_necessary(None) # This should now cause a query with sleuth.watch("google.appengine.api.datastore.Query.Run") as query: trans = gettext("Goodbye World!") self.assertEqual(trans, "Auf Wiedersehen Welt!") self.assertTrue(query.called)
def test_languages_cached(self): # This should make a query, because the translations were invalidated translation.activate("de") with sleuth.watch("google.appengine.api.datastore.Query.Run") as query: trans = gettext("Hello World!") self.assertEqual(trans, "Hallo Welt!") self.assertTrue(query.called) # Wait for any background threads to finish while translations_loading(): pass # This shouldn't make a query with sleuth.watch("google.appengine.api.datastore.Query.Run") as query: trans = gettext("Goodbye World!") self.assertEqual(trans, "Auf Wiedersehen Welt!") self.assertFalse(query.called)