def test_certificate(self, stdout, Request, urlopen): request = Request.return_value urlopen.return_value.getcode.return_value = 200 self.set_envs() self.addCleanup(self.delete_envs) with mock.patch("io.open", mock.mock_open()) as open: open.return_value.read.return_value = 'my content' plugin.certificate([ '-s', 'service1', '-i', 'inst1', '-c', 'cert.crt', '-k', 'key.key' ]) open.assert_any_call('cert.crt', 'rb') open.assert_any_call('key.key', 'rb') Request.assert_called_with(self.target + "services/service1/proxy/inst1?" + "callback=/resources/inst1/certificate") request.add_header.assert_any_call("Authorization", "bearer " + self.token) data = request.add_data.call_args[0][0] has_content = re.search(r'cert\.crt.*my content.*key\.key.*my content', data, re.DOTALL) self.assertTrue(has_content) urlopen.assert_called_with(request) stdout.write.assert_called_with("Certificate successfully updated\n")
def test_certificate(self, stdout, Request, urlopen): request = Request.return_value urlopen.return_value.getcode.return_value = 200 self.set_envs() self.addCleanup(self.delete_envs) with mock.patch("io.open", mock.mock_open()) as open: open.return_value.read.return_value = 'my content' plugin.certificate(['-s', 'service1', '-i', 'inst1', '-c', 'cert.crt', '-k', 'key.key']) open.assert_any_call('cert.crt', 'rb') open.assert_any_call('key.key', 'rb') Request.assert_called_with(self.target + "services/service1/proxy/inst1?" + "callback=/resources/inst1/certificate") request.add_header.assert_any_call("Authorization", "bearer " + self.token) data = request.add_data.call_args[0][0] has_content = re.search(r'cert\.crt.*my content.*key\.key.*my content', data, re.DOTALL) self.assertTrue(has_content) urlopen.assert_called_with(request) stdout.write.assert_called_with("Certificate successfully updated\n")