"""Запуск: cd scripts && ./venv/bin/python -m unittest discover -s tests"""
import os
import sys
import unittest
from unittest import mock

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

import config  # noqa: E402


class CallbackVerifyTest(unittest.TestCase):
    def test_default_verifies_ssl(self):
        with mock.patch.object(config, "LARAVEL_VERIFY_SSL", True):
            self.assertTrue(config.callback_verify_ssl())

    def test_can_disable_for_self_signed_local(self):
        with mock.patch.object(config, "LARAVEL_VERIFY_SSL", False):
            self.assertFalse(config.callback_verify_ssl())


class SendCallbackTest(unittest.TestCase):
    def test_passes_verify_flag_to_request(self):
        import app

        captured = {}

        def fake_post(url, json=None, timeout=None, verify=None):
            captured["verify"] = verify

            class R:
                status_code = 200

            return R()

        with mock.patch.object(config, "LARAVEL_VERIFY_SSL", False), \
             mock.patch.object(app.requests, "post", side_effect=fake_post):
            app.send_callback_with_retry("/api/x", {"a": 1})

        self.assertFalse(captured["verify"])


if __name__ == "__main__":
    unittest.main()
