|
9 | 9 | from fabric_cli.core import fab_constant |
10 | 10 | from fabric_cli.core.fab_exceptions import FabricCLIError |
11 | 11 | from fabric_cli.errors import ErrorMessages |
12 | | -from fabric_cli.utils.fab_cmd_mkdir_utils import find_mpe_connection |
| 12 | +from fabric_cli.utils.fab_cmd_mkdir_utils import ( |
| 13 | + find_mpe_connection, |
| 14 | + get_connection_config_from_params, |
| 15 | +) |
| 16 | + |
| 17 | + |
| 18 | +def test_fabric_data_pipelines_workspace_identity_no_params_success(): |
| 19 | + """Test FabricDataPipelines with WorkspaceIdentity credential type when no parameters are required.""" |
| 20 | + # Arrange |
| 21 | + payload = { |
| 22 | + "description": "Created by fab", |
| 23 | + "displayName": "test-connection", |
| 24 | + "connectivityType": "ShareableCloud" |
| 25 | + } |
| 26 | + |
| 27 | + con_type = "FabricDataPipelines" |
| 28 | + con_type_def = { |
| 29 | + "type": "FabricDataPipelines", |
| 30 | + "creationMethods": [ |
| 31 | + { |
| 32 | + "name": "FabricDataPipelines.Actions", |
| 33 | + "parameters": [] # No parameters required for this creation method |
| 34 | + } |
| 35 | + ], |
| 36 | + "supportedCredentialTypes": ["WorkspaceIdentity"] |
| 37 | + } |
| 38 | + |
| 39 | + params = { |
| 40 | + "connectiondetails": { |
| 41 | + "type": "FabricDataPipelines", |
| 42 | + "creationmethod": "FabricDataPipelines.Actions" |
| 43 | + # No parameters provided since none are required |
| 44 | + }, |
| 45 | + "credentialdetails": { |
| 46 | + "type": "WorkspaceIdentity" |
| 47 | + # No credential parameters provided since WorkspaceIdentity doesn't require any |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + result = get_connection_config_from_params(payload, con_type, con_type_def, params) |
| 52 | + |
| 53 | + # Assert |
| 54 | + assert result["privacyLevel"] == "None" |
| 55 | + assert result["connectionDetails"]["type"] == "FabricDataPipelines" |
| 56 | + assert result["connectionDetails"]["creationMethod"] == "FabricDataPipelines.Actions" |
| 57 | + assert "parameters" not in result["connectionDetails"] |
| 58 | + assert result["credentialDetails"]["credentials"]["credentialType"] == "WorkspaceIdentity" |
| 59 | + assert len(result["credentialDetails"]["credentials"].keys()) == 1 |
| 60 | + |
| 61 | + |
| 62 | +def test_connection_with_required_params_missing_failure(): |
| 63 | + """Test that connection creation fails when required parameters are missing.""" |
| 64 | + # Arrange |
| 65 | + payload = { |
| 66 | + "description": "Created by fab", |
| 67 | + "displayName": "test-connection", |
| 68 | + "connectivityType": "ShareableCloud" |
| 69 | + } |
| 70 | + |
| 71 | + con_type = "SQL" |
| 72 | + con_type_def = { |
| 73 | + "type": "SQL", |
| 74 | + "creationMethods": [ |
| 75 | + { |
| 76 | + "name": "SQL", |
| 77 | + "parameters": [ |
| 78 | + {"name": "server", "required": True, "dataType": "Text"}, |
| 79 | + {"name": "database", "required": True, "dataType": "Text"} |
| 80 | + ] |
| 81 | + } |
| 82 | + ], |
| 83 | + "supportedCredentialTypes": ["Basic"] |
| 84 | + } |
| 85 | + |
| 86 | + params = { |
| 87 | + "connectiondetails": { |
| 88 | + "type": "SQL", |
| 89 | + "creationmethod": "SQL" |
| 90 | + # No parameters provided, but they are required |
| 91 | + }, |
| 92 | + "credentialdetails": { |
| 93 | + "type": "Basic", |
| 94 | + "username": "testuser", |
| 95 | + "password": "testpass" |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + with pytest.raises(FabricCLIError) as exc_info: |
| 100 | + get_connection_config_from_params(payload, con_type, con_type_def, params) |
| 101 | + |
| 102 | + assert "Parameters are required for the connection creation method" in str(exc_info.value.message) |
| 103 | + assert "server, database" in str(exc_info.value.message) |
| 104 | + |
| 105 | + |
| 106 | +def test_workspace_identity_with_unsupported_params_ignored_success(): |
| 107 | + """Test that WorkspaceIdentity ignores unsupported credential parameters with warning.""" |
| 108 | + # Arrange |
| 109 | + payload = { |
| 110 | + "description": "Created by fab", |
| 111 | + "displayName": "test-connection", |
| 112 | + "connectivityType": "ShareableCloud" |
| 113 | + } |
| 114 | + |
| 115 | + con_type = "FabricDataPipelines" |
| 116 | + con_type_def = { |
| 117 | + "type": "FabricDataPipelines", |
| 118 | + "creationMethods": [ |
| 119 | + { |
| 120 | + "name": "FabricDataPipelines.Actions", |
| 121 | + "parameters": [] |
| 122 | + } |
| 123 | + ], |
| 124 | + "supportedCredentialTypes": ["WorkspaceIdentity"] |
| 125 | + } |
| 126 | + |
| 127 | + params = { |
| 128 | + "connectiondetails": { |
| 129 | + "type": "FabricDataPipelines", |
| 130 | + "creationmethod": "FabricDataPipelines.Actions" |
| 131 | + }, |
| 132 | + "credentialdetails": { |
| 133 | + "type": "WorkspaceIdentity", |
| 134 | + "username": "should_be_ignored", # This should be ignored for WorkspaceIdentity |
| 135 | + "password": "should_be_ignored" # This should be ignored for WorkspaceIdentity |
| 136 | + } |
| 137 | + } |
| 138 | + |
| 139 | + # Act |
| 140 | + with patch('fabric_cli.utils.fab_ui.print_warning') as mock_warning: |
| 141 | + result = get_connection_config_from_params(payload, con_type, con_type_def, params) |
| 142 | + |
| 143 | + mock_warning.assert_called_once() |
| 144 | + assert "username" in str(mock_warning.call_args) |
| 145 | + assert "password" in str(mock_warning.call_args) |
| 146 | + |
| 147 | + assert result["credentialDetails"]["credentials"]["credentialType"] == "WorkspaceIdentity" |
13 | 148 |
|
14 | 149 |
|
15 | 150 | class TestFindMpeConnection: |
|
0 commit comments