예제 #1
0
 def test_scale_invalid_quantity(self, stderr):
     with self.assertRaises(SystemExit) as cm:
         plugin.scale(["-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)
예제 #2
0
 def test_scale_invalid_quantity(self, stderr):
     with self.assertRaises(SystemExit) as cm:
         plugin.scale(["-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)
예제 #3
0
 def test_scale_missing_quantity(self, stderr):
     with self.assertRaises(SystemExit) as cm:
         plugin.scale(["-i", "abc"])
     exc = cm.exception
     self.assertEqual(2, exc.code)
     expected_msg = "usage: scale [-h] [-i INSTANCE] [-n QUANTITY]\n"
     stderr.write.assert_called_with(expected_msg)
예제 #4
0
 def test_scale_missing_quantity(self, stderr):
     with self.assertRaises(SystemExit) as cm:
         plugin.scale(["-i", "abc"])
     exc = cm.exception
     self.assertEqual(2, exc.code)
     expected_msg = "usage: scale [-h] [-i INSTANCE] [-n QUANTITY]\n"
     stderr.write.assert_called_with(expected_msg)
예제 #5
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(["-i", "myinstance", "-n", "10"])
     exc = cm.exception
     self.assertEqual(2, exc.code)
     stderr.write.assert_called_with("ERROR: missing TSURU_TOKEN\n")
예제 #6
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(["-i", "myinstance", "-n", "10"])
     exc = cm.exception
     self.assertEqual(2, exc.code)
     stderr.write.assert_called_with("ERROR: missing TSURU_TOKEN\n")
예제 #7
0
 def test_scale_singular(self, stdout, Request, urlopen):
     request = mock.Mock()
     Request.return_value = request
     self.set_envs()
     self.addCleanup(self.delete_envs)
     result = mock.Mock()
     result.getcode.return_value = 201
     urlopen.return_value = result
     plugin.scale(["-i", "myinstance", "-n", "1"])
     Request.assert_called_with(self.target +
                                "services/proxy/myinstance?" +
                                "callback=/resources/myinstance/scale")
     request.add_header.assert_called_with("Authorization",
                                           "bearer " + self.token)
     request.add_data.assert_called_with("quantity=1")
     urlopen.assert_called_with(request)
     stdout.write.assert_called_with("Instance successfully scaled to 1 unit\n")
예제 #8
0
 def test_scale_singular(self, stdout, Request, urlopen):
     request = mock.Mock()
     Request.return_value = request
     self.set_envs()
     self.addCleanup(self.delete_envs)
     result = mock.Mock()
     result.getcode.return_value = 201
     urlopen.return_value = result
     plugin.scale(["-i", "myinstance", "-n", "1"])
     Request.assert_called_with(self.target + "services/proxy/myinstance?" +
                                "callback=/resources/myinstance/scale")
     request.add_header.assert_called_with("Authorization",
                                           "bearer " + self.token)
     request.add_data.assert_called_with("quantity=1")
     urlopen.assert_called_with(request)
     stdout.write.assert_called_with(
         "Instance successfully scaled to 1 unit\n")
예제 #9
0
 def test_scale_failure(self, stderr, Request, urlopen):
     request = mock.Mock()
     Request.return_value = request
     self.set_envs()
     self.addCleanup(self.delete_envs)
     result = mock.Mock()
     result.getcode.return_value = 400
     result.read.return_value = "Invalid quantity"
     urlopen.return_value = result
     with self.assertRaises(SystemExit) as cm:
         plugin.scale(["-i", "myinstance", "-n", "10"])
     exc = cm.exception
     self.assertEqual(1, exc.code)
     Request.assert_called_with(self.target + "services/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")
예제 #10
0
 def test_scale_failure(self, stderr, Request, urlopen):
     request = mock.Mock()
     Request.return_value = request
     self.set_envs()
     self.addCleanup(self.delete_envs)
     result = mock.Mock()
     result.getcode.return_value = 400
     result.read.return_value = "Invalid quantity"
     urlopen.return_value = result
     with self.assertRaises(SystemExit) as cm:
         plugin.scale(["-i", "myinstance", "-n", "10"])
     exc = cm.exception
     self.assertEqual(1, exc.code)
     Request.assert_called_with(self.target +
                                "services/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")
예제 #11
0
 def test_scale_no_target(self, stderr):
     with self.assertRaises(SystemExit) as cm:
         plugin.scale(["-i", "myinstance", "-n", "10"])
     exc = cm.exception
     self.assertEqual(2, exc.code)
     stderr.write.assert_called_with("ERROR: missing TSURU_TARGET\n")
예제 #12
0
 def test_scale_no_target(self, stderr):
     with self.assertRaises(SystemExit) as cm:
         plugin.scale(["-i", "myinstance", "-n", "10"])
     exc = cm.exception
     self.assertEqual(2, exc.code)
     stderr.write.assert_called_with("ERROR: missing TSURU_TARGET\n")