def assert_logs(log_action, node_key, index=(-1)):
 def outer_wrapper(func):
  @functools.wraps(func)
  def wrapper(self, *args, **kwargs):
   node = getattr(self, node_key)
   last_log = node.logs.latest()
   func(self, *args, **kwargs)
   node.reload()
   new_log = node.logs.order_by('-date')[((- index) - 1)]
   assert_not_equal(last_log._id, new_log._id)
   assert_equal(new_log.action, log_action)
   node.save()
  return wrapper
 return outer_wrapper

def assert_logs ( log_action , node_key , index = ( - 1 ) ) : def outer_wrapper ( func ) : @ functools . wraps ( func ) def wrapper ( self , * args , ** kwargs ) : node = getattr ( self , node_key ) last_log = node . logs . latest ( ) func ( self , * args , ** kwargs ) node . reload ( ) new_log = node . logs . order_by ( '-date' ) [ ( ( - index ) - 1 ) ] assert_not_equal ( last_log . _id , new_log . _id ) assert_equal ( new_log . action , log_action ) node . save ( ) return wrapper return outer_wrapper
a decorator to ensure a log is added during a unit test .