def test_return_installation_count_v2(self): bundles_endpoint_reply = """ [{ "bundleId": "a101449418187d92c789d1adc240b6d6", "bundleInstallations": [{ "uniqueAddress": { "address": "akka.tcp://[email protected]:9004", "uid": 1288758867 }, "bundleFile": "file:///tmp/79e700212ddff716622b39ceace28fc2f51c4a05cfd993ebb50833ea8b772edf.zip" }] }] """ http_method = self.respond_with(text=bundles_endpoint_reply) with patch('requests.get', http_method): bundle_id = 'a101449418187d92c789d1adc240b6d6' args = { 'ip': '127.0.0.1', 'port': '9005', 'api_version': '2' } result = bundle_installation.count_installations(bundle_id, MagicMock(**args)) self.assertEqual(1, result) http_method.assert_called_with('http://127.0.0.1:9005/v2/bundles')
def test_return_installation_count_v2(self): request_headers_mock = MagicMock(return_value=self.mock_headers) bundles_endpoint_reply = """ [{ "bundleId": "a101449418187d92c789d1adc240b6d6", "bundleInstallations": [{ "uniqueAddress": { "address": "akka.tcp://[email protected]:9004", "uid": 1288758867 }, "bundleFile": "file:///tmp/79e700212ddff716622b39ceace28fc2f51c4a05cfd993ebb50833ea8b772edf.zip" }] }] """ http_method = self.respond_with(text=bundles_endpoint_reply) bundle_id = 'a101449418187d92c789d1adc240b6d6' args = {'ip': '127.0.0.1', 'port': '9005', 'api_version': '2'} input_args = MagicMock(**args) with patch('requests.get', http_method), \ patch('conductr_cli.conduct_url.request_headers', request_headers_mock): result = bundle_installation.count_installations( bundle_id, input_args) self.assertEqual(1, result) request_headers_mock.assert_called_with(input_args) http_method.assert_called_with('http://127.0.0.1:9005/v2/bundles', headers=self.mock_headers)
def test_return_installation_count_v2(self): bundles_endpoint_reply = """ [{ "bundleId": "a101449418187d92c789d1adc240b6d6", "bundleInstallations": [{ "uniqueAddress": { "address": "akka.tcp://[email protected]:9004", "uid": 1288758867 }, "bundleFile": "file:///tmp/79e700212ddff716622b39ceace28fc2f51c4a05cfd993ebb50833ea8b772edf.zip" }] }] """ http_method = self.respond_with(text=bundles_endpoint_reply) bundle_id = 'a101449418187d92c789d1adc240b6d6' args = { 'dcos_mode': False, 'scheme': 'http', 'ip': '127.0.0.1', 'port': '9005', 'base_path': '/', 'api_version': '2', 'conductr_auth': self.conductr_auth, 'server_verification_file': self.server_verification_file } input_args = MagicMock(**args) with patch('requests.get', http_method): result = bundle_installation.count_installations(bundle_id, input_args) self.assertEqual(1, result) http_method.assert_called_with('http://127.0.0.1:9005/v2/bundles', auth=self.conductr_auth, verify=self.server_verification_file, headers={'Host': '127.0.0.1'})
def test_return_installation_count_v2(self): bundles_endpoint_reply = """ [{ "bundleId": "a101449418187d92c789d1adc240b6d6", "bundleInstallations": [{ "uniqueAddress": { "address": "akka.tcp://[email protected]:9004", "uid": 1288758867 }, "bundleFile": "file:///tmp/79e700212ddff716622b39ceace28fc2f51c4a05cfd993ebb50833ea8b772edf.zip" }] }] """ http_method = self.respond_with(text=bundles_endpoint_reply) bundle_id = 'a101449418187d92c789d1adc240b6d6' args = { 'dcos_mode': False, 'scheme': 'http', 'ip': '127.0.0.1', 'port': '9005', 'base_path': '/', 'api_version': '2', 'conductr_auth': self.conductr_auth, 'server_verification_file': self.server_verification_file } input_args = MagicMock(**args) with patch('requests.get', http_method): result = bundle_installation.count_installations(bundle_id, input_args) self.assertEqual(1, result) http_method.assert_called_with('http://127.0.0.1:9005/v2/bundles', auth=self.conductr_auth, verify=self.server_verification_file, headers={'Host': '127.0.0.1'})
def test_return_zero_installation_count_v1(self): bundles_endpoint_reply = '[]' http_method = self.respond_with(text=bundles_endpoint_reply) bundle_id = 'a101449418187d92c789d1adc240b6d6' args = { 'dcos_mode': False, 'scheme': 'http', 'ip': '127.0.0.1', 'port': '9005', 'base_path': '/', 'api_version': '1', 'conductr_auth': self.conductr_auth, 'server_verification_file': self.server_verification_file } input_args = MagicMock(**args) with patch('requests.get', http_method): result = bundle_installation.count_installations( bundle_id, input_args) self.assertEqual(0, result) http_method.assert_called_with('http://127.0.0.1:9005/bundles', auth=self.conductr_auth, verify=self.server_verification_file, headers={'Host': '127.0.0.1'})
def test_return_zero_installation_count_v2(self): bundles_endpoint_reply = '[]' http_method = self.respond_with(text=bundles_endpoint_reply) with patch('requests.get', http_method): bundle_id = 'a101449418187d92c789d1adc240b6d6' args = { 'ip': '127.0.0.1', 'port': '9005', 'api_version': '2' } result = bundle_installation.count_installations(bundle_id, MagicMock(**args)) self.assertEqual(0, result) http_method.assert_called_with('http://127.0.0.1:9005/v2/bundles')
def test_return_zero_installation_count_v2(self): request_headers_mock = MagicMock(return_value=self.mock_headers) bundles_endpoint_reply = '[]' http_method = self.respond_with(text=bundles_endpoint_reply) bundle_id = 'a101449418187d92c789d1adc240b6d6' args = {'ip': '127.0.0.1', 'port': '9005', 'api_version': '2'} input_args = MagicMock(**args) with patch('requests.get', http_method), \ patch('conductr_cli.conduct_url.request_headers', request_headers_mock): result = bundle_installation.count_installations( bundle_id, input_args) self.assertEqual(0, result) request_headers_mock.assert_called_with(input_args) http_method.assert_called_with('http://127.0.0.1:9005/v2/bundles', headers=self.mock_headers)
def test_return_zero_installation_count_v1(self): bundles_endpoint_reply = '[]' http_method = self.respond_with(text=bundles_endpoint_reply) bundle_id = 'a101449418187d92c789d1adc240b6d6' args = { 'dcos_mode': False, 'scheme': 'http', 'ip': '127.0.0.1', 'port': '9005', 'base_path': '/', 'api_version': '1', 'conductr_auth': self.conductr_auth, 'server_verification_file': self.server_verification_file } input_args = MagicMock(**args) with patch('requests.get', http_method): result = bundle_installation.count_installations(bundle_id, input_args) self.assertEqual(0, result) http_method.assert_called_with('http://127.0.0.1:9005/bundles', auth=self.conductr_auth, verify=self.server_verification_file, headers={'Host': '127.0.0.1'})