Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raising exception when when create ref action could not complete #1171

Merged
merged 2 commits into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions azure-devops/azext_devops/dev/repos/ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ def create_ref(name, object_id, repository=None, organization=None, project=None
name=resolve_git_refs(name),
new_object_id=object_id,
old_object_id='0000000000000000000000000000000000000000')
return client.update_refs(ref_updates=[ref_update],
repository_id=repository,
project=project)[0]
response = client.update_refs(ref_updates=[ref_update],
repository_id=repository,
project=project)[0]
if response.success is False:
raise CLIError(response.custom_message)
return response


def delete_ref(name, object_id=None, repository=None, organization=None, project=None, detect=None):
Expand Down
24 changes: 23 additions & 1 deletion azure-devops/azext_devops/test/repos/test_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from mock import patch, ANY

from knack.util import CLIError

from msrest.serialization import Model
from azext_devops.devops_sdk.v5_0.git.git_client import GitClient
from azext_devops.dev.common.services import clear_connection_cache
from azext_devops.dev.repos.ref import (list_refs, create_ref, delete_ref, lock_ref, unlock_ref)
Expand All @@ -23,6 +23,11 @@
class MockRef(object):
def __init__(self, object_id):
self.object_id = object_id

class MockRefResponse(Model):
def __init__(self, success, custom_message):
self.success = success
self.custom_message = custom_message

class TestRefMethods(AuthenticatedTests):

Expand Down Expand Up @@ -67,6 +72,23 @@ def test_create_ref(self):
ref_updates=ANY,
repository_id=None)

def test_create_ref2(self):

custom_exception = "Mock exception message"
mockResponse = []
mockResponse.append(MockRefResponse(False,custom_exception))

self.mock_update_refs.return_value = mockResponse

try:
response = create_ref(name='sample_ref',
object_id='1234567890',
organization=TEST_DEVOPS_ORG_URL,
project='sample_project')
self.fail('we should have received an error')
except CLIError as ex:
self.assertEqual(str(ex), custom_exception)

def test_lock_ref(self):

response = lock_ref(name='sample_ref',
Expand Down