<gh_stars>0
# vim: tabstop=4 shiftwidth=4 softtabstop=4

# Copyright 2012 IBM
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from novaclient.v1_1 import services
from tests.v1_1 import fakes
from tests import utils


cs = fakes.FakeClient()


class ServicesTest(utils.TestCase):

    def test_list_services(self):
        svs = cs.services.list()
        cs.assert_called('GET', '/os-services')
        [self.assertTrue(isinstance(s, services.Service)) for s in svs]
        [self.assertEqual(s.binary, 'nova-compute') for s in svs]
        [self.assertEqual(s.host, 'host1') for s in svs]

    def test_list_services_with_hostname(self):
        svs = cs.services.list(host='host2')
        cs.assert_called('GET', '/os-services?host=host2')
        [self.assertTrue(isinstance(s, services.Service)) for s in svs]
        [self.assertEqual(s.binary, 'nova-compute') for s in svs]
        [self.assertEqual(s.host, 'host2') for s in svs]

    def test_list_services_with_service(self):
        svs = cs.services.list(service='nova-cert')
        cs.assert_called('GET', '/os-services?service=nova-cert')
        [self.assertTrue(isinstance(s, services.Service)) for s in svs]
        [self.assertEqual(s.binary, 'nova-cert') for s in svs]
        [self.assertEqual(s.host, 'host1') for s in svs]

    def test_list_services_with_host_service(self):
        svs = cs.services.list('host2', 'nova-cert')
        cs.assert_called('GET', '/os-services?host=host2&service=nova-cert')
        [self.assertTrue(isinstance(s, services.Service)) for s in svs]
        [self.assertEqual(s.binary, 'nova-cert') for s in svs]
        [self.assertEqual(s.host, 'host2') for s in svs]

    def test_services_enable(self):
        service = cs.services.enable('host1', 'nova-cert')
        values = {"host": "host1", 'service': 'nova-cert'}
        cs.assert_called('PUT', '/os-services/enable', values)
        self.assertTrue(isinstance(service, services.Service))
        self.assertFalse(service.disabled)

    def test_services_disable(self):
        service = cs.services.disable('host1', 'nova-cert')
        values = {"host": "host1", 'service': 'nova-cert'}
        cs.assert_called('PUT', '/os-services/disable', values)
        self.assertTrue(isinstance(service, services.Service))
        self.assertTrue(service.disabled)

# vim: tabstop=4 shiftwidth=4 softtabstop=4

# Copyright 2012 IBM
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from novaclient.v1_1 import services
from tests.v1_1 import fakes
from tests import utils


cs = fakes.FakeClient()


class ServicesTest(utils.TestCase):

    def test_list_services(self):
        svs = cs.services.list()
        cs.assert_called('GET', '/os-services')
        [self.assertTrue(isinstance(s, services.Service)) for s in svs]
        [self.assertEqual(s.binary, 'nova-compute') for s in svs]
        [self.assertEqual(s.host, 'host1') for s in svs]

    def test_list_services_with_hostname(self):
        svs = cs.services.list(host='host2')
        cs.assert_called('GET', '/os-services?host=host2')
        [self.assertTrue(isinstance(s, services.Service)) for s in svs]
        [self.assertEqual(s.binary, 'nova-compute') for s in svs]
        [self.assertEqual(s.host, 'host2') for s in svs]

    def test_list_services_with_service(self):
        svs = cs.services.list(service='nova-cert')
        cs.assert_called('GET', '/os-services?service=nova-cert')
        [self.assertTrue(isinstance(s, services.Service)) for s in svs]
        [self.assertEqual(s.binary, 'nova-cert') for s in svs]
        [self.assertEqual(s.host, 'host1') for s in svs]

    def test_list_services_with_host_service(self):
        svs = cs.services.list('host2', 'nova-cert')
        cs.assert_called('GET', '/os-services?host=host2&service=nova-cert')
        [self.assertTrue(isinstance(s, services.Service)) for s in svs]
        [self.assertEqual(s.binary, 'nova-cert') for s in svs]
        [self.assertEqual(s.host, 'host2') for s in svs]

    def test_services_enable(self):
        service = cs.services.enable('host1', 'nova-cert')
        values = {"host": "host1", 'service': 'nova-cert'}
        cs.assert_called('PUT', '/os-services/enable', values)
        self.assertTrue(isinstance(service, services.Service))
        self.assertFalse(service.disabled)

    def test_services_disable(self):
        service = cs.services.disable('host1', 'nova-cert')
        values = {"host": "host1", 'service': 'nova-cert'}
        cs.assert_called('PUT', '/os-services/disable', values)
        self.assertTrue(isinstance(service, services.Service))
        self.assertTrue(service.disabled)
# vim: tabstop=4 shiftwidth=4 softtabstop=4 # Copyright 2012 IBM # All Rights Reserved. # #    Licensed under the Apache License, Version 2.0 (the "License"); you may #    not use this file except in compliance with the License. You may obtain #    a copy of the License at # #         http://www.apache.org/licenses/LICENSE-2.0 # #    Unless required by applicable law or agreed to in writing, software #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the #    License for the specific language governing permissions and limitations #    under the License.