def test_pool_update(self):
        """Test delete"""

        api = mock.create_autospec(BatchAppsApi)
        pool = Pool(api)
        api.get_pool.return_value = mock.create_autospec(Response)
        api.get_pool.return_value.success = True
        api.get_pool.return_value.result = {
            'targetDedicated':'5',
            'currentDedicated':'4',
            'state':'active',
            'allocationState':'test',
            }

        self.assertEqual(pool.target_size, 0)
        self.assertEqual(pool.current_size, 0)
        self.assertEqual(pool.state, None)
        self.assertEqual(pool.allocation_state, None)
        self.assertEqual(pool.resize_error, '')
        pool.update()
        api.get_pool.assert_called_with(pool_id=None)
        self.assertEqual(pool.target_size, 5)
        self.assertEqual(pool.current_size, 4)
        self.assertEqual(pool.state, 'active')
        self.assertEqual(pool.allocation_state, 'test')
        self.assertEqual(pool.resize_error, '')

        api.get_pool.return_value.success = False
        api.get_pool.return_value.result = RestCallException(None, "Test", None)

        with self.assertRaises(RestCallException):
            pool.update()
    def test_pool_delete(self):
        """Test delete"""

        api = mock.create_autospec(BatchAppsApi)
        api.delete_pool.return_value = mock.create_autospec(Response)
        api.delete_pool.return_value.success = True
        pool = Pool(api)

        pool.delete()
        api.delete_pool.assert_called_with(None)
        api.delete_pool.return_value.success = False
        api.delete_pool.return_value.result = RestCallException(None, "Test", None)

        with self.assertRaises(RestCallException):
            pool.delete()
Exemple #3
0
    def test_pool_update(self):
        """Test delete"""

        api = mock.create_autospec(BatchAppsApi)
        pool = Pool(api)
        api.get_pool.return_value = mock.create_autospec(Response)
        api.get_pool.return_value.success = True
        api.get_pool.return_value.result = {
            'targetDedicated': '5',
            'currentDedicated': '4',
            'state': 'active',
            'allocationState': 'test',
        }

        self.assertEqual(pool.target_size, 0)
        self.assertEqual(pool.current_size, 0)
        self.assertEqual(pool.state, None)
        self.assertEqual(pool.allocation_state, None)
        self.assertEqual(pool.resize_error, '')
        pool.update()
        api.get_pool.assert_called_with(pool_id=None)
        self.assertEqual(pool.target_size, 5)
        self.assertEqual(pool.current_size, 4)
        self.assertEqual(pool.state, 'active')
        self.assertEqual(pool.allocation_state, 'test')
        self.assertEqual(pool.resize_error, '')

        api.get_pool.return_value.success = False
        api.get_pool.return_value.result = RestCallException(
            None, "Test", None)

        with self.assertRaises(RestCallException):
            pool.update()
Exemple #4
0
    def test_pool_create(self):
        """Test Pool object"""

        api = mock.create_autospec(BatchAppsApi)
        pool = Pool(api)
        self.assertIsNone(pool.id)
        self.assertIsNone(pool.created)
        self.assertEqual(pool.target_size, 0)

        pool_spec = {
            'id': 'abc',
            'creationTime': '',
            'targetDedicated': '5',
            'state': 'active',
            'communication': True
        }

        pool = Pool(api, **pool_spec)
        self.assertEqual(pool.id, 'abc')
        self.assertEqual(pool.created, '')
        self.assertEqual(pool.target_size, 5)
        self.assertEqual(pool.communication, True)
Exemple #5
0
    def test_pool_resize(self, mock_update):
        """Test resize"""

        api = mock.create_autospec(BatchAppsApi)
        api.resize_pool.return_value = mock.create_autospec(Response)
        api.resize_pool.return_value.success = True
        pool = Pool(api)

        pool.resize(5)
        api.resize_pool.assert_called_with(None, 5)
        mock_update.assert_called_with()

        with self.assertRaises(ValueError):
            pool.resize("test")

        api.resize_pool.return_value.success = False
        api.resize_pool.return_value.result = RestCallException(
            None, "Test", None)

        mock_update.called = False
        with self.assertRaises(RestCallException):
            pool.resize(1)
        self.assertFalse(mock_update.called)
Exemple #6
0
    def test_pool_delete(self):
        """Test delete"""

        api = mock.create_autospec(BatchAppsApi)
        api.delete_pool.return_value = mock.create_autospec(Response)
        api.delete_pool.return_value.success = True
        pool = Pool(api)

        pool.delete()
        api.delete_pool.assert_called_with(None)
        api.delete_pool.return_value.success = False
        api.delete_pool.return_value.result = RestCallException(
            None, "Test", None)

        with self.assertRaises(RestCallException):
            pool.delete()
    def test_pool_resize(self, mock_update):
        """Test resize"""

        api = mock.create_autospec(BatchAppsApi)
        api.resize_pool.return_value = mock.create_autospec(Response)
        api.resize_pool.return_value.success = True
        pool = Pool(api)

        pool.resize(5)
        api.resize_pool.assert_called_with(None, 5)
        mock_update.assert_called_with()

        with self.assertRaises(ValueError):
            pool.resize("test")

        api.resize_pool.return_value.success = False
        api.resize_pool.return_value.result = RestCallException(None, "Test", None)

        mock_update.called = False
        with self.assertRaises(RestCallException):
            pool.resize(1)
        self.assertFalse(mock_update.called)