Changeset View
Changeset View
Standalone View
Standalone View
swh/journal/tests/test_publisher.py
Show First 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | ORIGIN_VISITS = [ | ||||
{ | { | ||||
'date': '2013-05-07T04:20:39.369271+00:00', | 'date': '2013-05-07T04:20:39.369271+00:00', | ||||
}, | }, | ||||
{ | { | ||||
'date': '2018-11-27T17:20:39.000000+00:00', | 'date': '2018-11-27T17:20:39.000000+00:00', | ||||
} | } | ||||
] | ] | ||||
TEST_CONFIG = { | |||||
class JournalPublisherTest(JournalPublisher): | |||||
def parse_config_file(self): | |||||
return { | |||||
'brokers': ['localhost'], | 'brokers': ['localhost'], | ||||
'temporary_prefix': 'swh.tmp_journal.new', | 'temporary_prefix': 'swh.tmp_journal.new', | ||||
'final_prefix': 'swh.journal.objects', | 'final_prefix': 'swh.journal.objects', | ||||
'consumer_id': 'swh.journal.test.publisher', | 'consumer_id': 'swh.journal.test.publisher', | ||||
'publisher_id': 'swh.journal.test.publisher', | 'publisher_id': 'swh.journal.test.publisher', | ||||
'object_types': ['content'], | 'object_types': ['content'], | ||||
'max_messages': 3, | 'max_messages': 3, | ||||
} | } | ||||
class JournalPublisherTest(JournalPublisher): | |||||
def _prepare_storage(self, config): | def _prepare_storage(self, config): | ||||
self.storage = Storage() | self.storage = Storage() | ||||
self.storage.content_add({'data': b'42', **c} for c in CONTENTS) | self.storage.content_add({'data': b'42', **c} for c in CONTENTS) | ||||
self.storage.revision_add(REVISIONS) | self.storage.revision_add(REVISIONS) | ||||
self.storage.release_add(RELEASES) | self.storage.release_add(RELEASES) | ||||
origins = self.storage.origin_add(ORIGINS) | origins = self.storage.origin_add(ORIGINS) | ||||
origin_visits = [] | origin_visits = [] | ||||
for i, ov in enumerate(ORIGIN_VISITS): | for i, ov in enumerate(ORIGIN_VISITS): | ||||
origin_id = origins[i]['id'] | origin_id = origins[i]['id'] | ||||
ov = self.storage.origin_visit_add(origin_id, ov['date']) | ov = self.storage.origin_visit_add(origin_id, ov['date']) | ||||
origin_visits.append(ov) | origin_visits.append(ov) | ||||
self.origins = origins | self.origins = origins | ||||
self.origin_visits = origin_visits | self.origin_visits = origin_visits | ||||
print("publisher.origin-visits", self.origin_visits) | print("publisher.origin-visits", self.origin_visits) | ||||
class JournalPublisherNoKafkaInMemoryStorage(JournalPublisherTest): | |||||
"""A journal publisher with: | |||||
- no kafka dependency | |||||
- in-memory storage | |||||
""" | |||||
def _prepare_journal(self, config): | def _prepare_journal(self, config): | ||||
"""No journal for now | """No journal for now | ||||
""" | """ | ||||
pass | pass | ||||
class TestPublisher(unittest.TestCase): | class TestPublisher(unittest.TestCase): | ||||
def setUp(self): | def setUp(self): | ||||
self.publisher = JournalPublisherTest() | self.publisher = JournalPublisherNoKafkaInMemoryStorage(TEST_CONFIG) | ||||
ardumont: That will be reworked in D1239. | |||||
self.contents = [{b'sha1': c['sha1']} for c in CONTENTS] | self.contents = [{b'sha1': c['sha1']} for c in CONTENTS] | ||||
self.revisions = [{b'id': c['id']} for c in REVISIONS] | self.revisions = [{b'id': c['id']} for c in REVISIONS] | ||||
self.releases = [{b'id': c['id']} for c in RELEASES] | self.releases = [{b'id': c['id']} for c in RELEASES] | ||||
# those needs id generation from the storage | # those needs id generation from the storage | ||||
# so initialization is different than other entities | # so initialization is different than other entities | ||||
self.origins = [{b'url': o['url'], | self.origins = [{b'url': o['url'], | ||||
b'type': o['type']} | b'type': o['type']} | ||||
for o in self.publisher.origins] | for o in self.publisher.origins] | ||||
▲ Show 20 Lines • Show All 67 Lines • Show Last 20 Lines |
That will be reworked in D1239.