Exemplo n.º 1
0
 def test_scale_invalid_quantity(self, stderr):
     with self.assertRaises(SystemExit) as cm:
         plugin.scale(["-s", "myservice", "-i", "abc", "-n", "0"])
     exc = cm.exception
     self.assertEqual(2, exc.code)
     expected_msg = "quantity must be a positive integer\n"
     stderr.write.assert_called_with(expected_msg)
Exemplo n.º 2
0
 def test_scale_missing_service(self, stderr):
     with self.assertRaises(SystemExit) as cm:
         plugin.scale(["-n", "1"])
     exc = cm.exception
     self.assertEqual(2, exc.code)
     expected_msg = "scale: error: argument -s/--service is required\n"
     stderr.write.assert_called_with(expected_msg)
Exemplo n.º 3
0
 def test_scale_missing_quantity(self, stderr):
     with self.assertRaises(SystemExit) as cm:
         plugin.scale(["-s", "myservice", "-i", "abc"])
     exc = cm.exception
     self.assertEqual(2, exc.code)
     expected_msg = "scale: error: argument -n/--quantity is required\n"
     stderr.write.assert_called_with(expected_msg)
Exemplo n.º 4
0
 def test_scale_missing_quantity(self, stderr):
     with self.assertRaises(SystemExit) as cm:
         plugin.scale(["-s", "myservice", "-i", "abc"])
     exc = cm.exception
     self.assertEqual(2, exc.code)
     expected_msg = "scale: error: argument -n/--quantity is required\n"
     stderr.write.assert_called_with(expected_msg)
Exemplo n.º 5
0
 def test_scale_invalid_quantity(self, stderr):
     with self.assertRaises(SystemExit) as cm:
         plugin.scale(["-s", "myservice", "-i", "abc", "-n", "0"])
     exc = cm.exception
     self.assertEqual(2, exc.code)
     expected_msg = "quantity must be a positive integer\n"
     stderr.write.assert_called_with(expected_msg)
Exemplo n.º 6
0
 def test_scale_missing_service(self, stderr):
     with self.assertRaises(SystemExit) as cm:
         plugin.scale(["-n", "1"])
     exc = cm.exception
     self.assertEqual(2, exc.code)
     expected_msg = "scale: error: argument -s/--service is required\n"
     stderr.write.assert_called_with(expected_msg)
Exemplo n.º 7
0
 def test_scale_no_token(self, stderr):
     self.set_envs()
     self.addCleanup(self.delete_envs)
     del os.environ["TSURU_TOKEN"]
     self.addCleanup(self.set_envs)
     with self.assertRaises(SystemExit) as cm:
         plugin.scale(["-s", "myservice", "-i", "myinstance", "-n", "10"])
     exc = cm.exception
     self.assertEqual(2, exc.code)
     stderr.write.assert_called_with("ERROR: missing TSURU_TOKEN\n")
Exemplo n.º 8
0
 def test_scale_no_token(self, stderr):
     self.set_envs()
     self.addCleanup(self.delete_envs)
     del os.environ["TSURU_TOKEN"]
     self.addCleanup(self.set_envs)
     with self.assertRaises(SystemExit) as cm:
         plugin.scale(["-s", "myservice", "-i", "myinstance", "-n", "10"])
     exc = cm.exception
     self.assertEqual(2, exc.code)
     stderr.write.assert_called_with("ERROR: missing TSURU_TOKEN\n")
Exemplo n.º 9
0
 def test_scale(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.scale(["-s", "myservice", "-i", "myinstance", "-n", "10"])
     Request.assert_called_with(self.target +
                                "services/myservice/proxy/myinstance?" +
                                "callback=/resources/myinstance/scale")
     request.add_header.assert_called_with("Authorization",
                                           "bearer " + self.token)
     request.add_data.assert_called_with("quantity=10")
     urlopen.assert_called_with(request)
     stdout.write.assert_called_with("Instance successfully scaled to 10 units\n")
Exemplo n.º 10
0
 def test_scale(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.scale(["-s", "myservice", "-i", "myinstance", "-n", "10"])
     Request.assert_called_with(self.target +
                                "services/myservice/proxy/myinstance?" +
                                "callback=/resources/myinstance/scale")
     request.add_header.assert_called_with("Authorization",
                                           "bearer " + self.token)
     request.add_data.assert_called_with("quantity=10")
     urlopen.assert_called_with(request)
     stdout.write.assert_called_with("Instance successfully scaled to 10 units\n")
Exemplo n.º 11
0
 def test_scale_failure_invalid_value(self, stderr, Request, urlopen):
     request = mock.Mock()
     Request.return_value = request
     self.set_envs()
     self.addCleanup(self.delete_envs)
     urlopen.return_value = HTTPError(None, 400, None, None, StringIO(u"Invalid quantity"))
     with self.assertRaises(SystemExit) as cm:
         plugin.scale(["-s", "myservice", "-i", "myinstance", "-n", "10"])
     exc = cm.exception
     self.assertEqual(1, exc.code)
     Request.assert_called_with(self.target +
                                "services/myservice/proxy/myinstance?" +
                                "callback=/resources/myinstance/scale")
     request.add_header.assert_called_with("Authorization",
                                           "bearer " + self.token)
     request.add_data.assert_called_with("quantity=10")
     urlopen.assert_called_with(request)
     stderr.write.assert_called_with("ERROR: Invalid quantity\n")
Exemplo n.º 12
0
 def test_scale_failure_invalid_value(self, stderr, Request, urlopen):
     request = mock.Mock()
     Request.return_value = request
     self.set_envs()
     self.addCleanup(self.delete_envs)
     urlopen.return_value = HTTPError(None, 400, None, None, StringIO(u"Invalid quantity"))
     with self.assertRaises(SystemExit) as cm:
         plugin.scale(["-s", "myservice", "-i", "myinstance", "-n", "10"])
     exc = cm.exception
     self.assertEqual(1, exc.code)
     Request.assert_called_with(self.target +
                                "services/myservice/proxy/myinstance?" +
                                "callback=/resources/myinstance/scale")
     request.add_header.assert_called_with("Authorization",
                                           "bearer " + self.token)
     request.add_data.assert_called_with("quantity=10")
     urlopen.assert_called_with(request)
     stderr.write.assert_called_with("ERROR: Invalid quantity\n")
Exemplo n.º 13
0
 def test_scale_no_target(self, stderr):
     with self.assertRaises(SystemExit) as cm:
         plugin.scale(["-s", "myservice", "-i", "myinstance", "-n", "10"])
     exc = cm.exception
     self.assertEqual(2, exc.code)
     stderr.write.assert_called_with("ERROR: missing TSURU_TARGET\n")
Exemplo n.º 14
0
 def test_scale_no_target(self, stderr):
     with self.assertRaises(SystemExit) as cm:
         plugin.scale(["-s", "myservice", "-i", "myinstance", "-n", "10"])
     exc = cm.exception
     self.assertEqual(2, exc.code)
     stderr.write.assert_called_with("ERROR: missing TSURU_TARGET\n")