File: test_vsts_git_url_info.py

package info (click to toggle)
azure-devops-cli-extension 1.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,384 kB
  • sloc: python: 160,782; xml: 198; makefile: 56; sh: 51
file content (74 lines) | stat: -rw-r--r-- 4,664 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import unittest
try:
    # Attempt to load mock (works on Python 3.3 and above)
    from unittest.mock import patch
except ImportError:
    # Attempt to load mock (works on Python version below 3.3)
    from mock import patch
from azext_devops.dev.common.vsts_git_url_info import VstsGitUrlInfo


class Test_VstsGitUrlInfo_Methods(unittest.TestCase):

    def test_get_vsts_info_old_url_format_with_new_ssh_format(self):
        with patch('azext_devops.devops_sdk.v5_0.git.git_client.GitClient.get_vsts_info_by_remote_url') as mock_get_vsts_info:
            with patch('azext_devops.dev.common.services._get_credentials') as mock_get_creds:
                VstsGitUrlInfo.get_vsts_info('organization@vs-ssh.visualstudio.com:v3/organization/project/repository')
                # Asserts            
                mock_get_vsts_info.assert_called_once()
                mock_get_creds.assert_called_once()
                get_vsts_info_url_param = mock_get_vsts_info.call_args_list[0][0]
                self.assertEqual(
                    'https://organization.visualstudio.com/project/_git/repository'.lower(), get_vsts_info_url_param[0])
                    

    def test_get_vsts_info_old_url_format_with_https(self):
        with patch('azext_devops.devops_sdk.v5_0.git.git_client.GitClient.get_vsts_info_by_remote_url') as mock_get_vsts_info:
            with patch('azext_devops.dev.common.services._get_credentials') as mock_get_creds:
                VstsGitUrlInfo.get_vsts_info('https://organization.visualstudio.com/project/_git/repository')
                # Asserts            
                mock_get_vsts_info.assert_called_once()
                mock_get_creds.assert_called_once()
                get_vsts_info_url_param = mock_get_vsts_info.call_args_list[0][0]
                self.assertEqual(
                    'https://organization.visualstudio.com/project/_git/repository'.lower(), get_vsts_info_url_param[0])
                    

    def test_get_vsts_info_old_url_format_with_old_ssh_format(self):
        with patch('azext_devops.devops_sdk.v5_0.git.git_client.GitClient.get_vsts_info_by_remote_url') as mock_get_vsts_info:
            with patch('azext_devops.dev.common.services._get_credentials') as mock_get_creds:
                VstsGitUrlInfo.get_vsts_info('ssh://organization@vs-ssh.visualstudio.com:22/project/_ssh/repository')
                # Asserts            
                mock_get_vsts_info.assert_called_once()
                mock_get_creds.assert_called_once()
                get_vsts_info_url_param = mock_get_vsts_info.call_args_list[0][0]
                self.assertEqual(
                    'https://organization.visualstudio.com/project/_git/repository'.lower(), get_vsts_info_url_param[0])


    def test_get_vsts_inf_new_url_format_with_ssh(self):
        with patch('azext_devops.devops_sdk.v5_0.git.git_client.GitClient.get_vsts_info_by_remote_url') as mock_get_vsts_info:
            with patch('azext_devops.dev.common.services._get_credentials') as mock_get_creds:
                VstsGitUrlInfo.get_vsts_info('git@ssh.dev.azure.com:v3/organization/project/repository')
                # Asserts            
                mock_get_vsts_info.assert_called_once()
                mock_get_creds.assert_called_once()
                get_vsts_info_url_param = mock_get_vsts_info.call_args_list[0][0]
                self.assertEqual(
                    'https://dev.azure.com/organization/project/_git/repository'.lower(), get_vsts_info_url_param[0])

    def test_get_vsts_inf_new_url_format_with_https(self):
        with patch('azext_devops.devops_sdk.v5_0.git.git_client.GitClient.get_vsts_info_by_remote_url') as mock_get_vsts_info:
            with patch('azext_devops.dev.common.services._get_credentials') as mock_get_creds:
                VstsGitUrlInfo.get_vsts_info('https://organization@dev.azure.com/organization/project/_git/repository')
                # Asserts            
                mock_get_vsts_info.assert_called_once()
                mock_get_creds.assert_called_once()
                get_vsts_info_url_param = mock_get_vsts_info.call_args_list[0][0]
                self.assertEqual(
                    'https://organization@dev.azure.com/organization/project/_git/repository'.lower(), get_vsts_info_url_param[0])