def test_update(self, stdout, Request, urlopen): request = Request.return_value self.set_envs() self.addCleanup(self.delete_envs) result = mock.Mock() result.getcode.return_value = 201 urlopen.return_value = result plugin.update(["-s", "myservice", "-i", "myinstance", "-p", "new_plan", "-f", "new_flavor"]) Request.assert_called_with(self.target + "services/myservice/proxy/myinstance?" + "callback=/resources/myinstance") request.add_header.assert_called_with("Authorization", "bearer " + self.token) self.assertEqual(request.get_method(), 'PUT') request.add_data.assert_called_with("plan_name=new_plan&flavor_name=new_flavor") urlopen.assert_called_with(request) stdout.write.assert_called_with("Instance successfully updated\n")
def test_update(self, stdout, Request, urlopen): request = Request.return_value self.set_envs() self.addCleanup(self.delete_envs) result = mock.Mock() result.getcode.return_value = 201 urlopen.return_value = result plugin.update(["-s", "myservice", "-i", "myinstance", "-p", "new_plan"]) Request.assert_called_with(self.target + "services/myservice/proxy/myinstance?" + "callback=/resources/myinstance") request.add_header.assert_called_with("Authorization", "bearer " + self.token) self.assertEqual(request.get_method(), 'PUT') request.add_data.assert_called_with("plan_name=new_plan") urlopen.assert_called_with(request) stdout.write.assert_called_with("Instance successfully updated\n")
def test_update_invalid_plan_name(self, stderr, Request, urlopen): request = mock.Mock() Request.return_value = request self.set_envs() self.addCleanup(self.delete_envs) urlopen.return_value = HTTPError(None, 404, None, None, StringIO(u"Invalid plan name")) with self.assertRaises(SystemExit) as cm: plugin.update(["-s", "myservice", "-i", "myinstance", "-p", "weird_plan"]) exc = cm.exception self.assertEqual(1, exc.code) Request.assert_called_with(self.target + "services/myservice/proxy/myinstance?" + "callback=/resources/myinstance") request.add_header.assert_called_with("Authorization", "bearer " + self.token) self.assertEqual(request.get_method(), 'PUT') request.add_data.assert_called_with("plan_name=weird_plan") urlopen.assert_called_with(request) stderr.write.assert_called_with("ERROR: Invalid plan name\n")
def test_update_invalid_plan_name(self, stderr, Request, urlopen): request = mock.Mock() Request.return_value = request self.set_envs() self.addCleanup(self.delete_envs) urlopen.return_value = HTTPError(None, 404, None, None, StringIO(u"Invalid plan name")) with self.assertRaises(SystemExit) as cm: plugin.update(["-s", "myservice", "-i", "myinstance", "-p", "weird_plan"]) exc = cm.exception self.assertEqual(1, exc.code) Request.assert_called_with(self.target + "services/myservice/proxy/myinstance?" + "callback=/resources/myinstance") request.add_header.assert_called_with("Authorization", "bearer " + self.token) self.assertEqual(request.get_method(), 'PUT') request.add_data.assert_called_with("plan_name=weird_plan") urlopen.assert_called_with(request) stderr.write.assert_called_with("ERROR: Invalid plan name\n")