Getting the unit tests passing again / fixing requirements.txt python-gitlab
authorJude N <juden@pwan.org>
Thu, 29 Aug 2019 10:59:45 +0000 (06:59 -0400)
committerJude N <juden@pwan.org>
Thu, 29 Aug 2019 10:59:45 +0000 (06:59 -0400)
README.md
plugins/marge.py
requirements.txt
setup.cfg
tests/test_marge.py

index 38dd0c1..198ce9a 100644 (file)
--- 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
index 0dbbffe..7be6ea6 100755 (executable)
@@ -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"
index 6e00525..f1fe52a 100644 (file)
@@ -3,5 +3,3 @@ python-gitlab
 python-dateutil
 errbot
 sleekxmpp
-slackclient
-irc
index 5b1003c..a6f8e14 100644 (file)
--- 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
index 9ab5d90..6875007 100644 (file)
@@ -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