diff --git a/swh/scheduler/tests/test_events.py b/swh/scheduler/tests/test_events.py index 8214c9d..cb77461 100644 --- a/swh/scheduler/tests/test_events.py +++ b/swh/scheduler/tests/test_events.py @@ -1,56 +1,56 @@ # 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 arrow import utcnow from hypothesis import given from hypothesis.strategies import one_of, text, just, sampled_from from nose.tools import istest from swh.scheduler.updater.events import SWHEvent, LISTENED_EVENTS 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 { - 'event': event_name, + 'type': event_name, 'url': 'something', 'last_seen': utcnow(), } @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/tests/test_scheduler_updater.py b/swh/scheduler/tests/test_scheduler_updater.py index e5e20ab..228a7ee 100644 --- a/swh/scheduler/tests/test_scheduler_updater.py +++ b/swh/scheduler/tests/test_scheduler_updater.py @@ -1,67 +1,67 @@ # 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 os import unittest from arrow import utcnow from nose.plugins.attrib import attr from nose.tools import istest from hypothesis import given from hypothesis.strategies import sets, from_regex from swh.core.tests.db_testing import SingleDbTestFixture from swh.scheduler.updater.backend import SchedulerUpdaterBackend from swh.scheduler.updater.events import SWHEvent TEST_DIR = os.path.dirname(os.path.abspath(__file__)) TEST_DATA_DIR = os.path.join(TEST_DIR, '../../../../swh-storage-testdata') @attr('db') class SchedulerUpdaterTest(SingleDbTestFixture, unittest.TestCase): TEST_DB_NAME = 'softwareheritage-scheduler-updater-test' TEST_DB_DUMP = os.path.join(TEST_DATA_DIR, 'dumps/swh-scheduler-updater.dump') def setUp(self): super().setUp() config = { 'scheduling_updater_db': 'dbname=' + self.TEST_DB_NAME, 'time_window': '1 minute', } self.backend = SchedulerUpdaterBackend(**config) def _empty_tables(self): self.cursor.execute( """SELECT table_name FROM information_schema.tables WHERE table_schema = %s""", ('public', )) tables = set(table for (table,) in self.cursor.fetchall()) for table in tables: self.cursor.execute('truncate table %s cascade' % table) self.conn.commit() def tearDown(self): self.backend.close_connection() self._empty_tables() super().tearDown() @istest @given(sets( from_regex( r'^https://somewhere[.]org/[a-z0-9]{5,7}/[a-z0-9]{3,10}$'), min_size=10, max_size=15)) def cache_read(self, urls): def gen_events(urls): for url in urls: yield SWHEvent({ 'url': url, - 'event': 'create' + 'type': 'create' }) self.backend.cache_put(gen_events(urls)) r = self.backend.cache_read(timestamp=utcnow()) self.assertNotEqual(r, []) diff --git a/swh/scheduler/updater/events.py b/swh/scheduler/updater/events.py index cf0c7eb..03bfa1a 100644 --- a/swh/scheduler/updater/events.py +++ b/swh/scheduler/updater/events.py @@ -1,47 +1,38 @@ # 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 'event' in self.event and self.event['event'] in LISTENED_EVENTS + return 'type' in self.event and \ + self.event['type'].lower() in LISTENED_EVENTS def get(self): return { - 'event': self.event['event'], + 'type': self.event['type'], 'url': self.event['url'], 'last_seen': self.event.get('last_seen') } def __str__(self): return { - 'event': self.event['event'], + 'type': self.event['type'], 'url': self.event['url'], 'last_seen': self.event.get('last_seen') } - - -class SWHPublisher: - def process(self): - pass - - -class SWHSubscriber: - def process(self): - pass