From 209be8741c76d9f3cdc70dff38bb8982369f4890 Mon Sep 17 00:00:00 2001 From: Jude N Date: Thu, 29 Aug 2019 06:59:45 -0400 Subject: [PATCH] Getting the unit tests passing again / fixing requirements.txt --- README.md | 3 --- plugins/marge.py | 34 ++++++++++++++++------------------ requirements.txt | 2 -- setup.cfg | 1 + tests/test_marge.py | 6 +++--- 5 files changed, 20 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 38dd0c1..198ce9a 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,3 @@ Development Notes: Deployment Notes: Errbot plugs aren't distributed as eggs. Instead copy the contents of the .plugin directory to a 'Marge' directory under your Errnbot plugins directory. - -TODO Notes: -- Port from pyapi-gitlab to python-gitlab diff --git a/plugins/marge.py b/plugins/marge.py index 0dbbffe..7be6ea6 100755 --- a/plugins/marge.py +++ b/plugins/marge.py @@ -186,7 +186,7 @@ class Marge(BotPlugin, CrontabMixin): # Only weed out MRs less than the soak time for the crontab output (where author==None) now = datetime.now(timezone.utc) - creation_time = parser.parse(mr_attrs['created_at'], tzinfos=tzutc) + creation_time = parser.parse(mr_attrs['created_at'], tzinfos=[tzutc()]).astimezone(timezone.utc) if not author: self.log.info("times: {}, {}, {}".format(creation_time, self.soak_delta, now)) if creation_time + self.soak_delta > now: @@ -431,33 +431,31 @@ class Marge(BotPlugin, CrontabMixin): msg = "Couldn't find {} hooks".format(repo) self.log.error("watchrepo: {}".format(msg)) return msg - else: - for a_hook in hooks: - self.log.info('a_hook: {}'.format(a_hook)) - hook_attributes = a_hook.attributes - if hook_attributes['merge_requests_events'] and hook_attributes['url'].startswith(self.webhook_url): - marge_hook = a_hook - break + + for a_hook in hooks: + self.log.info('a_hook: {}'.format(a_hook)) + hook_attributes = a_hook.attributes + if hook_attributes['merge_requests_events'] and hook_attributes['url'].startswith(self.webhook_url): + marge_hook = a_hook + break # If so replace it (or error out ?) url = "{}{}".format(self.webhook_url, rooms) # webhooks_url will end in '/' hook_updated = True if marge_hook: - old_rooms = marge_hook.attributes['url'].split(self.webhook_url, 1)[1] if old_rooms == rooms: msg = "Already reporting {} MRs to the {} room(s)".format(repo, rooms) self.log.info('watchrepo: {}'.format(msg)) return msg - else: - try: - s_action = "update" - marge_hook.attributes['url'] = url - marge_hook.save() - s_watch_msg = "Updating room list for {} MRs from {} to {}".format(repo, old_rooms, rooms) - except Exception as exp: - hook_updated = False - self.log.error("watchrepo; update hook {} raised exception {}".format(repo, exp)) + try: + s_action = "update" + marge_hook.attributes['url'] = url + marge_hook.save() + s_watch_msg = "Updating room list for {} MRs from {} to {}".format(repo, old_rooms, rooms) + except Exception as exp: + hook_updated = False + self.log.error("watchrepo; update hook {} raised exception {}".format(repo, exp)) else: try: s_action = "add" diff --git a/requirements.txt b/requirements.txt index 6e00525..f1fe52a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,5 +3,3 @@ python-gitlab python-dateutil errbot sleekxmpp -slackclient -irc diff --git a/setup.cfg b/setup.cfg index 5b1003c..a6f8e14 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,5 +3,6 @@ test = pytest [tool:pytest] addopts = --cov=plugins --cov-report term-missing --cov-report html --pep8 --pylint --pylint-rcfile=.pylintrc --ff -x +markers = pep8: workaround for https://bitbucket.org/pytest-dev/pytest-pep8/issues/23/ pep8ignore = *.py E501 diff --git a/tests/test_marge.py b/tests/test_marge.py index 9ab5d90..6875007 100644 --- a/tests/test_marge.py +++ b/tests/test_marge.py @@ -15,10 +15,10 @@ import json from queue import Empty from dateutil.relativedelta import relativedelta -import pytest import requests -import errbot from errbot.backends.test import testbot # pylint: disable=unused-import +import errbot +import pytest from httmock import urlmatch, HTTMock from plugins.marge import deltastr @@ -199,7 +199,7 @@ def mock_projects_hooks_list_already_watching(url, request): 'url': 'https://webhook.errbot.com:3142/margebot/room1,room2,room3'}])} -class TestMarge(object): +class TestMarge: """ Margebot Tests -- 2.39.2