def test_get_company_updates_feature_flag_inactive_no_updates(monkeypatch, ): """ Test that when the DNB company updates feature flag is inactive, the task does not proceed. """ mocked_get_company_update_page = mock.Mock() monkeypatch.setattr( 'datahub.dnb_api.tasks.update.get_company_update_page', mocked_get_company_update_page, ) get_company_updates() assert mocked_get_company_update_page.call_count == 0
def test_errors(self, monkeypatch, error, expect_retry): """ Test the get_company_updates task retries server errors. """ mocked_get_company_update_page = mock.Mock(side_effect=error) monkeypatch.setattr( 'datahub.dnb_api.tasks.update.get_company_update_page', mocked_get_company_update_page, ) mock_retry = mock.Mock(side_effect=Retry(exc=error)) monkeypatch.setattr( 'datahub.dnb_api.tasks.get_company_updates.retry', mock_retry, ) expected_exception_class = Retry if expect_retry else DNBServiceError with pytest.raises(expected_exception_class): get_company_updates()
def test_lock(self, monkeypatch, lock_acquired, call_count): """ Test that the task doesn't run if it cannot acquire the advisory_lock. """ mock_advisory_lock = mock.MagicMock() mock_advisory_lock.return_value.__enter__.return_value = lock_acquired monkeypatch.setattr( 'datahub.dnb_api.tasks.update.advisory_lock', mock_advisory_lock, ) mock_get_company_updates = mock.Mock() monkeypatch.setattr( 'datahub.dnb_api.tasks.update._get_company_updates', mock_get_company_updates, ) get_company_updates() assert mock_get_company_updates.call_count == call_count