def test_subsystem_update(self):
        with XRDSSTTest() as app:
            with mock.patch('xrdsst.api.clients_api.ClientsApi.find_clients',
                            return_value=[
                                Client(id='DEV:GOV:9876:SUB1',
                                       instance_id='DEV',
                                       member_class='GOV',
                                       member_code='9876',
                                       subsystem_code='SUB1',
                                       connection_type=ConnectionType.HTTP,
                                       status=ClientStatus.REGISTERED,
                                       owner=True,
                                       has_valid_local_sign_cert=True)
                            ]):
                with mock.patch(
                        'xrdsst.api.clients_api.ClientsApi.update_client',
                        return_value=[
                            Client(id='DEV:GOV:9876:SUB1',
                                   instance_id='DEV',
                                   member_class='GOV',
                                   member_code='9876',
                                   subsystem_code='SUB1',
                                   connection_type=ConnectionType.HTTPS,
                                   status=ClientStatus.REGISTERED,
                                   owner=True,
                                   has_valid_local_sign_cert=True)
                        ]):
                    client_controller = ClientController()
                    client_controller.app = app
                    client_controller.load_config = (lambda: self.ss_config)
                    client_controller.get_server_status = (
                        lambda x, y: StatusTestData.
                        server_status_essentials_complete)
                    client_controller.update()

                    out, err = self.capsys.readouterr()
                    assert out.count("Updated client") > 0

                    with self.capsys.disabled():
                        sys.stdout.write(out)
                        sys.stderr.write(err)
    def test_registration_disabled_at_management_services_provider(self):
        class ServerProxyHasServiceDisabledResponse:
            status = 500
            data = '{"status":500,"error":{"code":"core.Server.ServerProxy.ServiceDisabled","metadata":["Service SERVICE:DEV/GOV/9876/MANAGEMENT/clientReg is disabled: BOFH"]}}'
            reason = ''

            def getheaders(self):
                headers = HTTPHeaderDict()
                headers.add('x-road-ui-correlation-id', 'ddddaaaa0011ffff')
                headers.add('Content-Type', 'application/json')

                return headers

            @staticmethod
            def as_extended_exception():
                api_ex = ApiException(
                    http_resp=ServerProxyHasServiceDisabledResponse())
                api_ex.api_call = {
                    'method': 'PUT',
                    'resource_path': '/clients/{id}/register',
                    'path_params': 'GOV:9876:SUB1',
                    'query_params': '',
                    'header_params': '',
                    'controller_func': 'client.py#remote_register_client',
                    'module_func': 'clients_api.py#register_client'
                }

                return api_ex

        with XRDSSTTest() as app:
            with mock.patch(
                    'xrdsst.api.clients_api.ClientsApi.register_client',
                    side_effect=ServerProxyHasServiceDisabledResponse.
                    as_extended_exception()):
                client_controller = ClientController()
                client_controller.app = app
                client_controller.load_config = (lambda: self.ss_config)
                client_controller.get_server_status = (
                    lambda x, y: StatusTestData.
                    server_status_essentials_complete)
                client_controller.register()

                out, err = self.capsys.readouterr()
                assert err.count("FAILED") > 0
                assert err.count(
                    "PUT /clients/{id}/register @ clients_api.py#register_client <- client.py#remote_register_client"
                ) == 2
                assert err.count("INTERNAL_SERVER_ERROR (500)") == 2
                assert err.count(
                    "error_code 'core.Server.ServerProxy.ServiceDisabled'"
                ) == 2
                assert err.count(
                    "Service SERVICE:DEV/GOV/9876/MANAGEMENT/clientReg is disabled: BOFH"
                ) == 2
                assert err.count(
                    server_error_map.get(
                        'core.Server.ServerProxy.ServiceDisabled')) == 2

                assert err.count(ascii_art['message_flow'][2]) == 2
                assert err.count(ascii_art['message_flow'][3]) == 2
                assert err.count(ascii_art['message_flow'][4]) == 2