import ssl from sync_client import SyncClientThread def test_ssl_context_uses_bundled_ca_certificates(): context = SyncClientThread._create_ssl_context() assert context.verify_mode == ssl.CERT_REQUIRED assert context.check_hostname is True assert context.cert_store_stats()["x509_ca"] > 0 def test_certificate_error_finds_nested_verification_error(): certificate_error = ssl.SSLCertVerificationError(1, "certificate has expired") try: raise RuntimeError("connection failed") from certificate_error except RuntimeError as error: assert SyncClientThread._certificate_error(error) is certificate_error def test_non_certificate_error_is_ignored(): assert SyncClientThread._certificate_error(ConnectionError("offline")) is None def test_ready_check_event_dispatch(qtbot): client = SyncClientThread() message = {'type': 'ready_check', 'active': True, 'id': 'check'} with qtbot.waitSignal(client.ready_check_updated) as signal: client._handle_message(message) assert signal.args == [message] def test_fight_event_dispatch_and_nonfatal_feedback(qtbot): client = SyncClientThread() for event_type, signal in (('reaction', client.fight_reaction), ('fight_poll', client.fight_poll_updated)): message = {'type': event_type, 'kind': 'ko'} with qtbot.waitSignal(signal) as event: client._handle_message(message) assert event.args == [message] with qtbot.waitSignal(client.system_message) as event: client._handle_message({'type': 'reaction_error', 'message': 'Cooldown'}) assert event.args == ['Cooldown']