Example #1
0
 def test_create_plan(self, stdout, Request, urlopen):
     request = mock.Mock()
     Request.return_value = request
     result = mock.Mock()
     result.getcode.return_value = 201
     urlopen.return_value = result
     admin_plugin.create_plan(
         [
             "-s",
             self.service_name,
             "-n",
             "small",
             "-d",
             "smalll vms",
             "-c",
             "SERVICE=abcdef-123 NAME=\"something nice\" DATA=go go go DATE='2015'",
         ]
     )
     Request.assert_called_with(self.target + "services/proxy/service/rpaas?" + "callback=/admin/plans")
     request.add_header.assert_any_call("Authorization", "bearer " + self.token)
     request.add_header.assert_any_call("Content-Type", "application/x-www-form-urlencoded")
     params = {
         "name": "small",
         "description": "smalll vms",
         "config": json.dumps(
             {"SERVICE": "abcdef-123", "NAME": "something nice", "DATA": "go go go", "DATE": "2015"}
         ),
     }
     request.add_data.assert_called_with(urllib.urlencode(params))
     self.assertEqual("POST", request.get_method())
     stdout.write.assert_called_with("Plan successfully created\n")
Example #2
0
 def test_create_plan(self, stdout, Request, urlopen):
     request = mock.Mock()
     Request.return_value = request
     result = mock.Mock()
     result.getcode.return_value = 201
     urlopen.return_value = result
     admin_plugin.create_plan(["-s", self.service_name, "-n", "small", "-d", "smalll vms", "-c",
                               'SERVICE=abcdef-123 NAME="something nice" DATA="go go go" DATE=\'2015\''])
     Request.assert_called_with(self.target +
                                "services/proxy/service/rpaas?" +
                                "callback=/admin/plans")
     request.add_header.assert_any_call("Authorization", "bearer " + self.token)
     request.add_header.assert_any_call("Content-Type",
                                        "application/x-www-form-urlencoded")
     params = {
         "name": "small",
         "description": "smalll vms",
         "config": json.dumps({"SERVICE": "abcdef-123",
                               "NAME": "something nice",
                               "DATA": "go go go",
                               "DATE": "2015"}),
     }
     request.add_data.assert_called_with(urllib.urlencode(params))
     self.assertEqual("POST", request.get_method())
     stdout.write.assert_called_with("Plan successfully created\n")
Example #3
0
 def test_create_plan_invalid_config(self, stderr):
     with self.assertRaises(SystemExit) as cm:
         admin_plugin.create_plan(["-s", self.service_name, "-n", "small", "-d", "smalll vms", "-c",
                                   "SERVICE"])
     exc = cm.exception
     self.assertEqual(2, exc.code)
     stderr.write.assert_called_with(
         "ERROR: Invalid config format, supported format is KEY=VALUE\n")
Example #4
0
 def test_create_plan_invalid_config(self, stderr):
     with self.assertRaises(SystemExit) as cm:
         admin_plugin.create_plan(["-s", self.service_name, "-n", "small", "-d", "smalll vms", "-c",
                                   "SERVICE"])
     exc = cm.exception
     self.assertEqual(2, exc.code)
     stderr.write.assert_called_with(
         "ERROR: Invalid config format, supported format is KEY=VALUE\n")
Example #5
0
 def test_create_plan_failure(self, stderr, Request, urlopen):
     request = mock.Mock()
     Request.return_value = request
     result = mock.Mock()
     result.getcode.return_value = 409
     result.read.return_value = "Plan already exists\n"
     urlopen.return_value = result
     with self.assertRaises(SystemExit) as cm:
         admin_plugin.create_plan(
             ["-s", self.service_name, "-n", "small", "-d", "smalll vms", "-c", "SERVICE=abcdef-123"]
         )
     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_any_call("Authorization", "bearer " + self.token)
     request.add_header.assert_any_call("Content-Type", "application/x-www-form-urlencoded")
     self.assertEqual("POST", request.get_method())
     stderr.write.assert_called_with("ERROR: Plan already exists\n")
Example #6
0
 def test_create_plan_failure(self, stderr, Request, urlopen):
     request = mock.Mock()
     Request.return_value = request
     result = mock.Mock()
     result.getcode.return_value = 409
     result.read.return_value = "Plan already exists\n"
     urlopen.return_value = result
     with self.assertRaises(SystemExit) as cm:
         admin_plugin.create_plan(["-s", self.service_name, "-n", "small", "-d", "smalll vms", "-c",
                                   "SERVICE=abcdef-123"])
     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_any_call("Authorization", "bearer " + self.token)
     request.add_header.assert_any_call("Content-Type",
                                        "application/x-www-form-urlencoded")
     self.assertEqual("POST", request.get_method())
     stderr.write.assert_called_with("ERROR: Plan already exists\n")