def test_request_body_sent_to_create_publishers(self): responses.add(responses.POST, self.POSTOFFICE_PUBLISHER_CREATION_URL, status=201, body="", content_type='application/json') configure_publishers() assert len(responses.calls) == 2 assert json.loads(responses.calls[0].request.body) == { 'active': True, 'target': 'http://www.some_url.com', 'topic': 'some_topic', 'type': 'http', 'seconds_timeout': 20, 'seconds_retry': 60, 'from_now': True } assert json.loads(responses.calls[1].request.body) == { 'active': True, 'target': 'http://www.another_url.com', 'topic': 'another_topic', 'type': 'pubsub', 'from_now': True }
def test_try_create_all_publishers_when_some_publisher_fails( self, publisher_with_validation_error, caplog): responses.add(responses.POST, self.POSTOFFICE_PUBLISHER_CREATION_URL, status=400, body=publisher_with_validation_error, content_type='application/json') responses.add(responses.POST, self.POSTOFFICE_PUBLISHER_CREATION_URL, status=201, body="", content_type='application/json') configure_publishers() assert ('postoffice_django.config', logging.ERROR, 'Publisher cannot be created') in caplog.record_tuples assert len(responses.calls) == 2 assert json.loads(responses.calls[0].request.body) == { 'active': True, 'target': 'http://www.some_url.com', 'topic': 'some_topic', 'type': 'http', 'seconds_timeout': 20, 'seconds_retry': 60, 'from_now': True } assert json.loads(responses.calls[1].request.body) == { 'active': True, 'target': 'http://www.another_url.com', 'topic': 'another_topic', 'type': 'pubsub', 'from_now': True }
def test_do_not_raise_exception_when_postoffice_raises_timeout( self, post_mock, caplog): post_mock.side_effect = requests.exceptions.ConnectTimeout() configure_publishers() assert ('postoffice_django.config', logging.ERROR, 'Publisher cannot be created') in caplog.record_tuples
def test_do_not_raise_exception_when_publisher_already_exists( self, publisher_already_exists, caplog): responses.add(responses.POST, self.POSTOFFICE_PUBLISHER_CREATION_URL, status=409, body=publisher_already_exists, content_type='application/json') configure_publishers() assert ('postoffice_django.config', logging.WARNING, 'Existing resource') in caplog.record_tuples
def test_do_not_raise_exception_when_can_not_create_publisher( self, publisher_with_validation_error, caplog): responses.add(responses.POST, self.POSTOFFICE_PUBLISHER_CREATION_URL, status=400, body=publisher_with_validation_error, content_type='application/json') configure_publishers() assert ('postoffice_django.config', logging.ERROR, 'Publisher cannot be created') in caplog.record_tuples