def test_delete_network(self):
        nb_db = Mock()

        handler, params = SelectingHandler.get_response_handler(
            responses(), DELETE,
            NETWORK_ENTITY.format(network_id=NETWORK_ID01).split('/'))
        handler(nb_db, NOT_RELEVANT, params)

        nb_db.delete_network.assert_called_once_with(str(NETWORK_ID01))
    def test_show_network(self):
        nb_db = Mock()
        nb_db.get_network.return_value = {
            NetworkMapper.REST_NETWORK_ID: str(NETWORK_ID01),
            NetworkMapper.REST_NETWORK_NAME: NETWORK_NAME1,
        }
        handler, params = SelectingHandler.get_response_handler(
            responses(), GET, NETWORK_ENTITY.split('/'))

        response = handler(nb_db, NOT_RELEVANT, {NETWORK_ID: NETWORK_ID01})

        response_json = json.loads(response.body)
        assert response_json['network']['id'] == str(NETWORK_ID01)
        assert response_json['network']['name'] == NETWORK_NAME1
    def _test_invalid_content(self, content):
        for path in [NETWORKS, PORTS, SUBNETS]:
            handler, params = SelectingHandler.get_response_handler(
                responses(), POST, path.split('/'))
            with pytest.raises(BadRequestError):
                handler(NOT_RELEVANT, content, NOT_RELEVANT)

        for path in [
                NETWORK_ENTITY.format(network_id=7),
                PORT_ENTITY.format(port_id=7),
                SUBNET_ENTITY.format(subnet_id=7)
        ]:
            handler, params = SelectingHandler.get_response_handler(
                responses(), PUT, path.split('/'))
            with pytest.raises(BadRequestError):
                handler(NOT_RELEVANT, content, NOT_RELEVANT)
Example #4
0
    def test_check_neutron_responses_required_by_engine_are_present(self):
        for method in [GET, POST]:
            for path in [NETWORKS, PORTS, SUBNETS, ROUTERS]:
                handler, params = SelectingHandler.get_response_handler(
                    responses(), method, path.split('/'))
                assert handler is not None
                assert params is not None
                assert not params

        for method in [GET, PUT, DELETE]:
            for path in [
                    NETWORK_ENTITY.format(network_id=7),
                    PORT_ENTITY.format(port_id=7),
                    SUBNET_ENTITY.format(subnet_id=7),
                    ROUTER_ENTITY.format(router_id=7)
            ]:
                handler, params = SelectingHandler.get_response_handler(
                    responses(), method, path.split('/'))
                assert handler is not None
                assert params is not None
                assert params.values()[0] == '7'

        for path in [
                ADD_ROUTER_INTERFACE.format(router_id=7),
                DELETE_ROUTER_INTERFACE.format(router_id=7)
        ]:
            handler, params = SelectingHandler.get_response_handler(
                responses(), PUT, path.split('/'))
            assert handler is not None
            assert params is not None
            assert params['router_id'] == '7'

        for path in [FLOATINGIPS, SECURITY_GROUPS]:
            handler, params = SelectingHandler.get_response_handler(
                responses(), GET, path.split('/'))
            assert handler is not None

        # This is a test call engine makes to check if provider is alive
        handler, params = SelectingHandler.get_response_handler(
            responses(), GET, ''.split('/'))
        assert handler is not None