def test_helm_push(self, mock_requests_get, mock_get_access_credentials): cmd = mock.MagicMock() cmd.cli_ctx = DummyCli() response = mock.MagicMock() response.headers = {} response.status_code = 200 mock_requests_get.return_value = response mock_get_access_credentials.return_value = 'testregistry.azurecr.io', EMPTY_GUID, 'password' builtins_open = '__builtin__.open' if sys.version_info[0] < 3 else 'builtins.open' # Push a chart with mock.patch(builtins_open) as mock_open: mock_open.return_value = mock.MagicMock() acr_helm_push(cmd, 'testregistry', './charts/mychart1-0.2.1.tgz', repository='testrepository') mock_requests_get.assert_called_with( method='put', url='https://testregistry.azurecr.io/helm/v1/testrepository/_blobs/mychart1-0.2.1.tgz', headers=get_authorization_header(EMPTY_GUID, 'password'), params=None, data=mock_open.return_value.__enter__.return_value, verify=mock.ANY) # Push a prov file with mock.patch(builtins_open) as mock_open: mock_open.return_value = mock.MagicMock() acr_helm_push(cmd, 'testregistry', 'mychart1-0.2.1.tgz.prov', repository='testrepository') mock_requests_get.assert_called_with( method='put', url='https://testregistry.azurecr.io/helm/v1/testrepository/_blobs/mychart1-0.2.1.tgz.prov', headers=get_authorization_header(EMPTY_GUID, 'password'), params=None, data=mock_open.return_value.__enter__.return_value, verify=mock.ANY) # Force push a chart with mock.patch(builtins_open) as mock_open: mock_open.return_value = mock.MagicMock() acr_helm_push(cmd, 'testregistry', './charts/mychart1-0.2.1.tgz', repository='testrepository', force=True) mock_requests_get.assert_called_with( method='patch', url='https://testregistry.azurecr.io/helm/v1/testrepository/_blobs/mychart1-0.2.1.tgz', headers=get_authorization_header(EMPTY_GUID, 'password'), params=None, data=mock_open.return_value.__enter__.return_value, verify=mock.ANY)
def test_helm_push(self, mock_requests_get, mock_get_access_credentials): cmd = self._setup_cmd() response = mock.MagicMock() response.headers = {} response.status_code = 200 mock_requests_get.return_value = response mock_get_access_credentials.return_value = 'testregistry.azurecr.io', EMPTY_GUID, 'password' builtins_open = '__builtin__.open' if sys.version_info[0] < 3 else 'builtins.open' # Push a chart with mock.patch(builtins_open) as mock_open: mock_open.return_value = mock.MagicMock() acr_helm_push(cmd, 'testregistry', './charts/mychart1-0.2.1.tgz', repository='testrepository') mock_requests_get.assert_called_with( method='put', url='https://testregistry.azurecr.io/helm/v1/testrepository/_blobs/mychart1-0.2.1.tgz', headers=get_authorization_header(EMPTY_GUID, 'password'), params=None, data=mock_open.return_value.__enter__.return_value, verify=mock.ANY) # Push a prov file with mock.patch(builtins_open) as mock_open: mock_open.return_value = mock.MagicMock() acr_helm_push(cmd, 'testregistry', 'mychart1-0.2.1.tgz.prov', repository='testrepository') mock_requests_get.assert_called_with( method='put', url='https://testregistry.azurecr.io/helm/v1/testrepository/_blobs/mychart1-0.2.1.tgz.prov', headers=get_authorization_header(EMPTY_GUID, 'password'), params=None, data=mock_open.return_value.__enter__.return_value, verify=mock.ANY) # Force push a chart with mock.patch(builtins_open) as mock_open: mock_open.return_value = mock.MagicMock() acr_helm_push(cmd, 'testregistry', './charts/mychart1-0.2.1.tgz', repository='testrepository', force=True) mock_requests_get.assert_called_with( method='patch', url='https://testregistry.azurecr.io/helm/v1/testrepository/_blobs/mychart1-0.2.1.tgz', headers=get_authorization_header(EMPTY_GUID, 'password'), params=None, data=mock_open.return_value.__enter__.return_value, verify=mock.ANY)