def add_couchdb_logging(biscuit_tin:BiscuitTin, logger:Logger): """ Inject CouchDB response time logging into an instantiated BiscuitTin @param biscuit_tin Instantiated BiscuitTin to inject into @param logger Where to log response times to """ inject_logging(biscuit_tin._sofa._db, logger) # Patch in updated decorated function references biscuit_tin._sofa._batch_methods = { Actions.Upsert: biscuit_tin._sofa._db.save_bulk, Actions.Delete: biscuit_tin._sofa._db.delete_bulk }
def test_inject_logging(self): # First check our functions aren't doing any logging... for method in self._methods: logged_fn = getattr(self._db, method) logged_fn() self.assertFalse(self._logger.called) # ...Then inject the logging... inject_logging(self._db, self._logger) # ...Now check that the logging is there for method in self._methods: logged_fn = getattr(self._db, method) logged_fn() log_name, log_args, log_kwargs = self._logger.method_calls[-1] self.assertEqual(log_name, 'record') self.assertEqual(log_args, ('couchdb', 5, {'function': method})) self.assertEqual(log_kwargs, {})