Exemplo n.º 1
0
    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())
Exemplo n.º 2
0
    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())
Exemplo n.º 3
0
    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())
Exemplo n.º 4
0
    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')
Exemplo n.º 5
0
    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())
Exemplo n.º 6
0
    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')
Exemplo n.º 7
0
def test_normalize_url_without_scheme():
    url = normalize_url('./path/to/somewhere')
    assert url.scheme == 'file'
Exemplo n.º 8
0
def test_normalize_url_with_scheme():
    url = normalize_url('HTTPS://example.com')
    assert url.scheme == 'https'
Exemplo n.º 9
0
 def test_fetch_from_file(self, local_config):
     config = fetch_external_config(normalize_url(str(local_config)), None)
     assert set(config.keys()) == {'db', 'web'}
Exemplo n.º 10
0
 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())
Exemplo n.º 11
0
 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
Exemplo n.º 12
0
 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
Exemplo n.º 13
0
def test_normalize_url_without_scheme():
    url = normalize_url('./path/to/somewhere')
    assert url.scheme == 'file'
Exemplo n.º 14
0
def test_normalize_url_with_scheme():
    url = normalize_url('HTTPS://example.com')
    assert url.scheme == 'https'
Exemplo n.º 15
0
 def test_fetch_from_file(self, local_config):
     config = fetch_external_config(normalize_url(str(local_config)), None)
     assert set(config.keys()) == {'db', 'web'}
Exemplo n.º 16
0
 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())
Exemplo n.º 17
0
 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
Exemplo n.º 18
0
 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
Exemplo n.º 19
0
 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
Exemplo n.º 20
0
 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