Skip to content

Commit 8019bc4

Browse files
authored
Fix trim -> strip (#480)
This backfills tests to ensure that the fix is correct. Closes #478. Closes #479.
1 parent 6cdde61 commit 8019bc4

File tree

3 files changed

+98
-8
lines changed

3 files changed

+98
-8
lines changed

databricks_cli/sdk/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,7 @@ def create_repo(self, url, provider, path=None, headers=None):
11341134
_data = {}
11351135
if url is not None:
11361136
_data['url'] = url
1137-
if provider is None or provider.trim() == "":
1137+
if provider is None or provider.strip() == "":
11381138
provider = self.detect_repo_provider(url)
11391139
if provider is not None:
11401140
_data['provider'] = provider

tests/sdk/test_api_client.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,3 @@ def test_api_client_url_parsing():
124124
# databricks_cli.configure.cli
125125
client = ApiClient(host='http://databricks.com')
126126
assert client.get_url('') == 'http://databricks.com/api/2.0'
127-
128-
129-
def test_repos_provider_detection():
130-
assert ReposService.detect_repo_provider("https://github.com/org/repo.git") == "gitHub"
131-
assert ReposService.detect_repo_provider(
132-
"https://git-codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo") == "awsCodeCommit"
133-
assert ReposService.detect_repo_provider("https://github1.com/org/repo.git") is None

tests/sdk/test_repos_service.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Databricks CLI
2+
# Copyright 2022 Databricks, Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License"), except
5+
# that the use of services to which certain application programming
6+
# interfaces (each, an "API") connect requires that the user first obtain
7+
# a license for the use of the APIs from Databricks, Inc. ("Databricks"),
8+
# by creating an account at www.databricks.com and agreeing to either (a)
9+
# the Community Edition Terms of Service, (b) the Databricks Terms of
10+
# Service, or (c) another written agreement between Licensee and Databricks
11+
# for the use of the APIs.
12+
#
13+
# You may not use this file except in compliance with the License.
14+
# You may obtain a copy of the License at
15+
#
16+
# http://www.apache.org/licenses/LICENSE-2.0
17+
#
18+
# Unless required by applicable law or agreed to in writing, software
19+
# distributed under the License is distributed on an "AS IS" BASIS,
20+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21+
# See the License for the specific language governing permissions and
22+
# limitations under the License.
23+
import pytest
24+
import mock
25+
26+
from databricks_cli.sdk.service import ReposService
27+
from tests.utils import provide_conf
28+
29+
30+
@pytest.fixture()
31+
def repos_service():
32+
with mock.patch('databricks_cli.sdk.ApiClient') as api_client:
33+
yield ReposService(api_client)
34+
35+
36+
def test_provider_inference():
37+
for url, provider in {
38+
"https://github.com/org/repo.git": "gitHub",
39+
"https://git-codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo": "awsCodeCommit",
40+
"https://github1.com/org/repo.git": None,
41+
}.items():
42+
assert provider == ReposService.detect_repo_provider(url)
43+
44+
45+
@provide_conf
46+
def test_list(repos_service):
47+
repos_service.list_repos()
48+
repos_service.client.perform_query.assert_called_with('GET', '/repos', data={}, headers=None)
49+
50+
repos_service.list_repos(path_prefix='foo')
51+
repos_service.client.perform_query.assert_called_with('GET', '/repos', data={'path_prefix': 'foo'}, headers=None)
52+
53+
repos_service.list_repos(next_page_token='token')
54+
repos_service.client.perform_query.assert_called_with('GET', '/repos', data={'next_page_token': 'token'}, headers=None)
55+
56+
57+
@provide_conf
58+
def test_create(repos_service):
59+
url = 'https://github.com/foo/bar.git'
60+
61+
repos_service.create_repo(url, None)
62+
repos_service.client.perform_query.assert_called_with('POST', '/repos', data={'url': url, 'provider': 'gitHub'}, headers=None)
63+
64+
repos_service.create_repo(url, '')
65+
repos_service.client.perform_query.assert_called_with('POST', '/repos', data={'url': url, 'provider': 'gitHub'}, headers=None)
66+
67+
repos_service.create_repo(url, ' ')
68+
repos_service.client.perform_query.assert_called_with('POST', '/repos', data={'url': url, 'provider': 'gitHub'}, headers=None)
69+
70+
repos_service.create_repo(url, 'gitHub')
71+
repos_service.client.perform_query.assert_called_with('POST', '/repos', data={'url': url, 'provider': 'gitHub'}, headers=None)
72+
73+
repos_service.create_repo(url, None, path='/path')
74+
repos_service.client.perform_query.assert_called_with('POST', '/repos', data={'url': url, 'provider': 'gitHub', 'path': '/path'}, headers=None)
75+
76+
77+
@provide_conf
78+
def test_get(repos_service):
79+
repos_service.get_repo('id')
80+
repos_service.client.perform_query.assert_called_with('GET', '/repos/id', data={}, headers=None)
81+
82+
83+
@provide_conf
84+
def test_update(repos_service):
85+
repos_service.update_repo('id')
86+
repos_service.client.perform_query.assert_called_with('PATCH', '/repos/id', data={}, headers=None)
87+
88+
repos_service.update_repo('id', branch='branch')
89+
repos_service.client.perform_query.assert_called_with('PATCH', '/repos/id', data={'branch': 'branch'}, headers=None)
90+
91+
repos_service.update_repo('id', tag='tag')
92+
repos_service.client.perform_query.assert_called_with('PATCH', '/repos/id', data={'tag': 'tag'}, headers=None)
93+
94+
@provide_conf
95+
def test_delete(repos_service):
96+
repos_service.delete_repo('id')
97+
repos_service.client.perform_query.assert_called_with('DELETE', '/repos/id', data={}, headers=None)

0 commit comments

Comments
 (0)