Skip to content

Commit

Permalink
test: Update tests for new queue name and exception message
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Oct 20, 2021
1 parent c56241e commit 5787b77
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions tests/extensions/test_kingfisher_process_api2.py
Expand Up @@ -49,8 +49,11 @@ def json(self):


@pytest.mark.skipif(not rabbit_url and not os.getenv('CI'), reason='RABBIT_URL must be set')
@pytest.mark.parametrize('url,boolean', [(rabbit_url, True), ('', False)])
def test_from_crawler(url, boolean):
@pytest.mark.parametrize('url,expected,boolean', [
(rabbit_url, f'{rabbit_url}?blocked_connection_timeout=1800&heartbeat=0', True),
('', None, False),
])
def test_from_crawler(url, expected, boolean):
spider = spider_with_crawler(settings={
'KINGFISHER_API2_URL': 'http://httpbin.org/anything/',
'RABBIT_URL': url,
Expand All @@ -61,7 +64,7 @@ def test_from_crawler(url, boolean):

extension = KingfisherProcessAPI2.from_crawler(spider.crawler)

assert extension.rabbit_url == url
assert extension.rabbit_url == expected
assert extension.exchange == 'kingfisher_process_test_1.0'
assert extension.queue == 'kingfisher_process_test_1.0_api_loader'
assert extension.routing_key == 'kingfisher_process_test_1.0_api'
Expand Down Expand Up @@ -249,9 +252,9 @@ def test_item_scraped(initializer, filename, kwargs, status_code, levelname, mes
def test_item_scraped_rabbit(initializer, filename, kwargs, raises, infix, tmpdir, caplog):
spider = spider_with_files_store(tmpdir, settings={
'RABBIT_URL': rabbit_url,
'RABBIT_EXCHANGE_NAME': 'kingfisher_collect_test_1.0',
'RABBIT_EXCHANGE_NAME': 'kingfisher_process_test_1.0',
'RABBIT_QUEUE_NAME': 'kingfisher_process_test_1.0_api_loader',
'RABBIT_ROUTING_KEY': 'kingfisher_collect_test_1.0_api',
'RABBIT_ROUTING_KEY': 'kingfisher_process_test_1.0_api',
})

extension = KingfisherProcessAPI2.from_crawler(spider.crawler)
Expand Down Expand Up @@ -294,9 +297,9 @@ def test_item_scraped_rabbit(initializer, filename, kwargs, raises, infix, tmpdi
assert len(caplog.records) == 1
assert caplog.records[0].name == 'test'
assert caplog.records[0].levelname == 'ERROR'
assert caplog.records[0].message == 'Failed to publish message to RabbitMQ: message'
assert caplog.records[0].message == 'Failed to publish message to RabbitMQ (ExpectedError): message'
else:
method_frame, header_frame, body = extension.channel.basic_get('kingfisher_collect_test_1.0_api')
method_frame, header_frame, body = extension.channel.basic_get('kingfisher_process_test_1.0_api_loader')
extension.channel.basic_ack(method_frame.delivery_tag)

assert len(caplog.records) == 0
Expand Down

0 comments on commit 5787b77

Please sign in to comment.