Пример #1
0
def test_check_storage_urls_other_client_error_s3(botomock, settings):
    settings.SYMBOL_URLS = ["https://s3.example.com/private/prefix/"]
    settings.UPLOAD_URL_EXCEPTIONS = {
        "*@peterbe.com": "https://s3.example.com/peterbe-com"
    }

    def mock_api_call(self, operation_name, api_params):
        assert operation_name == "HeadBucket"
        if api_params["Bucket"] == "private":
            response = {"Error": {"Code": "500", "Message": "Other"}}
            raise ClientError(response, operation_name)
        return {}

    with botomock(mock_api_call):
        with pytest.raises(ClientError):
            dockerflow_extra.check_storage_urls(None)
Пример #2
0
def test_check_storage_urls_storageerror(exception, settings):
    fake_bucket = StorageBucket(url=settings.SYMBOL_URLS[0])
    error = StorageError(bucket=fake_bucket, backend_error=exception)
    with patch("tecken.storage.StorageBucket.exists", side_effect=error):
        errors = dockerflow_extra.check_storage_urls(None)
    assert len(errors) == 2
    for error in errors:
        assert str(exception) in error.msg
        assert error.id == "tecken.health.E002"
Пример #3
0
def test_check_storage_urls_missing():
    with patch("tecken.storage.StorageBucket.exists", return_value=False):
        errors = dockerflow_extra.check_storage_urls(None)
    assert len(errors) == 2
    assert "private" in errors[0].msg
    assert "peterbe-com" in errors[1].msg
    for error in errors:
        assert "bucket not found" in error.msg
        assert error.id == "tecken.health.E001"
Пример #4
0
def test_check_storage_urls_client_error(gcsmock, settings):
    def mock_get_bucket(name):
        if name == "private":
            raise google_BadRequest("Never heard of it!")
        return gcsmock.MockBucket()

    gcsmock.get_bucket = mock_get_bucket

    errors = dockerflow_extra.check_storage_urls(None)
    assert errors
    error, = errors
    assert "private" in error.msg
    assert "Never heard of it!" in error.msg
Пример #5
0
def test_check_storage_urls_endpointconnectionerror_s3(botomock, settings):
    settings.SYMBOL_URLS = ["https://s3.example.com/private/prefix/"]
    settings.UPLOAD_URL_EXCEPTIONS = {
        "*@peterbe.com": "https://s3.example.com/peterbe-com"
    }

    def mock_api_call(self, operation_name, api_params):
        assert operation_name == "HeadBucket"
        if api_params["Bucket"] == "private":
            raise EndpointConnectionError(endpoint_url="http://s3.example.com")
        return {}

    with botomock(mock_api_call):
        errors = dockerflow_extra.check_storage_urls(None)
        assert errors
        error, = errors
        assert "private" in error.msg
        assert "EndpointConnectionError" in error.msg
Пример #6
0
def test_check_storage_urls_happy_path_s3(botomock, settings):
    settings.SYMBOL_URLS = [
        "https://s3.example.com/public/prefix/?access=public",
        "https://s3.example.com/private/prefix/",
    ]
    settings.UPLOAD_URL_EXCEPTIONS = {
        "*@peterbe.com": "https://s3.example.com/peterbe-com"
    }

    def mock_api_call(self, operation_name, api_params):
        assert operation_name == "HeadBucket"
        # These come from settings.Test
        fixture_bucket_names = ("private", "mybucket", "peterbe-com")
        assert api_params["Bucket"] in fixture_bucket_names
        return {}

    with botomock(mock_api_call):
        assert not dockerflow_extra.check_storage_urls(None)
Пример #7
0
def test_check_storage_urls_other_error():
    exception = RuntimeError("A different error")
    with patch(
        "tecken.storage.StorageBucket.exists", side_effect=exception
    ), pytest.raises(RuntimeError):
        dockerflow_extra.check_storage_urls(None)
Пример #8
0
def test_check_storage_urls_happy_path():
    with patch("tecken.storage.StorageBucket.exists", return_value=True):
        assert not dockerflow_extra.check_storage_urls(None)
Пример #9
0
def test_check_storage_urls_happy_path(gcsmock, settings):
    mock_bucket = gcsmock.MockBucket()
    gcsmock.get_bucket = lambda name: mock_bucket

    assert not dockerflow_extra.check_storage_urls(None)