def test_get_project_from_s3_not_found(self, mock_get_conn): mock_bucket = mock_get_conn.return_value.get_bucket.return_value mock_bucket.get_key.return_value = None url = normalize_url('s3://bucket/path/to/key/compose_addons.yml') with pytest.raises(FetchExternalConfigError) as exc_context: get_project_from_s3(url) expected = "Failed to include %s: Not Found" % url.geturl() assert expected in str(exc_context.exconly())
def test_get_project_from_s3_bucket_error(self, mock_get_conn): mock_get_bucket = mock_get_conn.return_value.get_bucket mock_get_bucket.side_effect = boto.exception.S3ResponseError( 404, "Bucket Not Found") url = normalize_url('s3://bucket/path/to/key/fig.yml') with pytest.raises(FetchExternalConfigError) as exc_context: get_project_from_s3(url) expected = ("Failed to include %s: " "S3ResponseError: 404 Bucket Not Found" % url.geturl()) assert expected in str(exc_context.exconly())
def test_get_project_from_s3(self, mock_get_conn): mock_bucket = mock_get_conn.return_value.get_bucket.return_value mock_key = mock_bucket.get_key.return_value mock_key.get_contents_as_string.return_value = 'foo:\n build: .' url = normalize_url('s3://bucket/path/to/key/compose_addons.yml') project = get_project_from_s3(url) assert project == {'foo': {'build': '.'}} mock_get_conn.assert_called_once_with() mock_get_conn.return_value.get_bucket.assert_called_once_with('bucket') mock_bucket.get_key.assert_called_once_with( '/path/to/key/compose_addons.yml')
def test_get_project_from_s3_bucket_error(self, mock_get_conn): mock_get_bucket = mock_get_conn.return_value.get_bucket mock_get_bucket.side_effect = boto.exception.S3ResponseError( 404, "Bucket Not Found") url = normalize_url('s3://bucket/path/to/key/fig.yml') with pytest.raises(FetchExternalConfigError) as exc_context: get_project_from_s3(url) expected = ( "Failed to include %s: " "S3ResponseError: 404 Bucket Not Found" % url.geturl()) assert expected in str(exc_context.exconly())
def test_normalize_url_without_scheme(): url = normalize_url('./path/to/somewhere') assert url.scheme == 'file'
def test_normalize_url_with_scheme(): url = normalize_url('HTTPS://example.com') assert url.scheme == 'https'
def test_fetch_from_file(self, local_config): config = fetch_external_config(normalize_url(str(local_config)), None) assert set(config.keys()) == {'db', 'web'}
def test_unsupported_scheme(self): with pytest.raises(ConfigError) as exc: fetch_external_config(normalize_url("bogus://something"), None) assert 'Unsupported url scheme "bogus"' in str(exc.exconly())
def test_fetch_from_file_absolute_with_scheme(self, local_config): url = 'file://' + str(local_config) with local_config.dirpath().as_cwd(): config = get_project_from_file(normalize_url(url)) assert set(config.keys()) == self.expected
def test_fetch_from_file_relative_with_context(self, local_config): url = './' + local_config.basename with local_config.dirpath().as_cwd(): config = get_project_from_file(normalize_url(url)) assert set(config.keys()) == self.expected
def test_fetch_from_file_absolute_path(self, local_config): config = get_project_from_file(normalize_url(str(local_config))) assert set(config.keys()) == self.expected