diff --git a/.gitignore b/.gitignore index f5fc2ae..898ba80 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,9 @@ *.pyc *.sw? *~ .coverage .eggs/ __pycache__ *.egg-info/ -version.txt \ No newline at end of file +version.txt +/.hypothesis/ diff --git a/debian/control b/debian/control index 5e4d9bf..6a6d5ed 100644 --- a/debian/control +++ b/debian/control @@ -1,25 +1,26 @@ Source: swh-scheduler Maintainer: Software Heritage developers Section: python Priority: optional Build-Depends: debhelper (>= 9), dh-python (>= 2), python3-all, python3-arrow, python3-celery, python3-click, python3-elasticsearch (>= 5.4.0), python3-flask, + python3-hypothesis, python3-kombu, python3-nose, python3-psycopg2, python3-setuptools, python3-swh.core (>= 0.0.38~), python3-vcversioner Standards-Version: 3.9.6 Homepage: https://forge.softwareheritage.org/diffusion/DSCH/ Package: python3-swh.scheduler Architecture: all Depends: python3-swh.core (>= 0.0.38~), ${misc:Depends}, ${python3:Depends} Description: Software Heritage Scheduler diff --git a/requirements.txt b/requirements.txt index 1af0cad..0bb53f8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,12 +1,13 @@ # Add here external Python modules dependencies, one per line. Module names # should match https://pypi.python.org/pypi names. For the full spec or # dependency lines, see https://pip.readthedocs.org/en/1.1/requirements.html arrow celery Click elasticsearch>5.4 flask kombu psycopg2 vcversioner +hypothesis diff --git a/swh/scheduler/tests/test_events.py b/swh/scheduler/tests/test_events.py new file mode 100644 index 0000000..f62cbcd --- /dev/null +++ b/swh/scheduler/tests/test_events.py @@ -0,0 +1,54 @@ +# Copyright (C) 2018 The Software Heritage developers +# See the AUTHORS file at the top-level directory of this distribution +# License: GNU General Public License version 3, or any later version +# See top-level LICENSE file for more information + +import unittest + +from nose.tools import istest + +from swh.scheduler.updater.events import SWHEvent, LISTENED_EVENTS +from hypothesis import given +from hypothesis.strategies import one_of, text, just, sampled_from + + +def event_values_ko(): + return { + 'repos', 'org_members', 'teamadd', 'geo_cache', + 'follow', 'issue_comments', 'followers', 'forks', 'pagebuild', + 'pullrequest', 'pull_requests', 'commit_comments', 'watch', 'fork', + 'forkapply', 'commits', 'release', 'gollum', 'membership', 'watchers', + 'pullrequestreviewcomment', 'deployment', 'issuecomment', 'status', + 'repo_labels', 'issue_events', 'commitcomment', 'issues', 'member', + 'users', 'download', 'repo_collaborators', 'repository', + 'deploymentstatus', 'pull_request_comments', 'gist' + } + + +class EventTest(unittest.TestCase): + def _make_event(self, event_name): + return { + 'evt': event_name, + 'url': 'something' + } + + @istest + @given(sampled_from(LISTENED_EVENTS)) + def check_ok(self, event_name): + evt = self._make_event(event_name) + self.assertTrue(SWHEvent(evt).check()) + + @istest + @given(text()) + def check_with_noisy_event_should_be_ko(self, event_name): + if event_name in LISTENED_EVENTS: + # just in generation generates a real and correct name, skip it + return + evt = self._make_event(event_name) + self.assertFalse(SWHEvent(evt).check()) + + @istest + @given(one_of(map(just, event_values_ko()))) + def check_ko(self, event_name): + evt = self._make_event(event_name) + self.assertFalse(SWHEvent(evt).check()) diff --git a/swh/scheduler/updater/events.py b/swh/scheduler/updater/events.py new file mode 100644 index 0000000..3e660bf --- /dev/null +++ b/swh/scheduler/updater/events.py @@ -0,0 +1,39 @@ +# Copyright (C) 2018 The Software Heritage developers +# See the AUTHORS file at the top-level directory of this distribution +# License: GNU General Public License version 3, or any later version +# See top-level LICENSE file for more information + + +LISTENED_EVENTS = [ + 'create', + 'delete', + 'public', + 'push' +] + + +class SWHEvent: + """SWH's interesting event (resulting in an origin update) + + """ + def __init__(self, evt): + self.event = evt + + def check(self): + return 'evt' in self.event and self.event['evt'] in LISTENED_EVENTS + + def __str__(self): + return { + 'evt': self.event['evt'], + 'url': self.event['url'] + } + + +class SWHPublisher: + def process(self): + pass + + +class SWHSubscriber: + def process(self): + pass