From b89d81d74846669de3892de7c235ac7f88c7ee4c Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Fri, 29 Apr 2016 14:41:11 -0400 Subject: [PATCH] test: add missing helpers.py file --- test/helpers.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 test/helpers.py diff --git a/test/helpers.py b/test/helpers.py new file mode 100644 index 000000000..1ebb94fdb --- /dev/null +++ b/test/helpers.py @@ -0,0 +1,21 @@ +from data.database import LogEntryKind, LogEntry + +class assert_action_logged(object): + """ Specialized assertion for ensuring that a log entry of a particular kind was added under the + context of this call. + """ + def __init__(self, log_kind): + self.log_kind = log_kind + self.existing_count = 0 + + def _get_log_count(self): + return LogEntry.select(LogEntry.kind == LogEntryKind.get(name=self.log_kind)).count() + + def __enter__(self): + self.existing_count = self._get_log_count() + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + updated_count = self._get_log_count() + error_msg = 'Missing new log entry of kind %s' % self.log_kind + assert self.existing_count == (updated_count - 1), error_msg