예제 #1
0
 def test_list_plans(self, stdout, Request, urlopen):
     request = mock.Mock()
     Request.return_value = request
     result = mock.Mock()
     result.getcode.return_value = 200
     result.read.return_value = """[
         {"name":"small","description":"small vm","config":{"serviceofferingid":"abcdef-123"}},
         {"name":"medium","description":"medium vm","config":{"serviceofferingid":"abcdef-126"}}
     ]"""
     urlopen.return_value = result
     admin_plugin.list_plans(["-s", self.service_name])
     Request.assert_called_with(self.target +
                                "services/proxy/service/rpaas?" +
                                "callback=/admin/plans")
     request.add_header.assert_called_with("Authorization",
                                           "bearer " + self.token)
     self.assertEqual("GET", request.get_method())
     urlopen.assert_called_with(request)
     expected_calls = [
         mock.call(
             "List of available plans (use show-plan for details):\n\n"),
         mock.call("small\t\tsmall vm\n"),
         mock.call("medium\t\tmedium vm\n"),
     ]
     self.assertEqual(expected_calls, stdout.write.call_args_list)
예제 #2
0
 def test_list_plans_failure(self, stderr, Request, urlopen):
     request = mock.Mock()
     Request.return_value = request
     result = mock.Mock()
     result.getcode.return_value = 400
     result.read.return_value = "Something went wrong"
     urlopen.return_value = result
     with self.assertRaises(SystemExit) as cm:
         admin_plugin.list_plans(["-s", self.service_name])
     exc = cm.exception
     self.assertEqual(1, exc.code)
     Request.assert_called_with(self.target + "services/proxy/service/rpaas?" + "callback=/admin/plans")
     request.add_header.assert_called_with("Authorization", "bearer " + self.token)
     self.assertEqual("GET", request.get_method())
     urlopen.assert_called_with(request)
     stderr.write.assert_called_with("ERROR: Something went wrong\n")
예제 #3
0
 def test_list_plans_failure(self, stderr, Request, urlopen):
     request = mock.Mock()
     Request.return_value = request
     result = mock.Mock()
     result.getcode.return_value = 400
     result.read.return_value = "Something went wrong"
     urlopen.return_value = result
     with self.assertRaises(SystemExit) as cm:
         admin_plugin.list_plans(["-s", self.service_name])
     exc = cm.exception
     self.assertEqual(1, exc.code)
     Request.assert_called_with(self.target +
                                "services/proxy/service/rpaas?" +
                                "callback=/admin/plans")
     request.add_header.assert_called_with("Authorization",
                                           "bearer " + self.token)
     self.assertEqual("GET", request.get_method())
     urlopen.assert_called_with(request)
     stderr.write.assert_called_with("ERROR: Something went wrong\n")
예제 #4
0
 def test_list_plans(self, stdout, Request, urlopen):
     request = mock.Mock()
     Request.return_value = request
     result = mock.Mock()
     result.getcode.return_value = 200
     result.read.return_value = """[
         {"name":"small","description":"small vm","config":{"serviceofferingid":"abcdef-123"}},
         {"name":"medium","description":"medium vm","config":{"serviceofferingid":"abcdef-126"}}
     ]"""
     urlopen.return_value = result
     admin_plugin.list_plans(["-s", self.service_name])
     Request.assert_called_with(self.target + "services/proxy/service/rpaas?" + "callback=/admin/plans")
     request.add_header.assert_called_with("Authorization", "bearer " + self.token)
     self.assertEqual("GET", request.get_method())
     urlopen.assert_called_with(request)
     expected_calls = [
         mock.call("List of available plans (use show-plan for details):\n\n"),
         mock.call("small\t\tsmall vm\n"),
         mock.call("medium\t\tmedium vm\n"),
     ]
     self.assertEqual(expected_calls, stdout.write.call_args_list)