# retoor <retoor@molodetz.nl>

import uuid
import requests
from tests.conftest import BASE_URL
def _session_push():
    s = requests.Session()
    name = f"push_{uuid.uuid4().hex[:10]}"
    s.post(
        f"{BASE_URL}/auth/signup",
        data={
            "username": name,
            "email": f"{name}@test.dev",
            "password": "secret123",
            "confirm_password": "secret123",
        },
        allow_redirects=True,
    )
    return s


def test_browser_base64_is_url_safe_unpadded():
    import base64
    from devplacepy import push

    encoded = push.browser_base64(b"\xff\xfe\x00 hello")
    assert "=" not in encoded
    assert "+" not in encoded and "/" not in encoded
    assert base64.urlsafe_b64decode(encoded + "==") == b"\xff\xfe\x00 hello"


def test_hkdf_returns_requested_length():
    from devplacepy import push

    derived = push.hkdf(b"input-key-material", b"salt", b"info", 16)
    assert isinstance(derived, bytes)
    assert len(derived) == 16


def test_public_key_standard_b64_non_empty():
    from devplacepy import push

    assert push.public_key_standard_b64()


def test_create_notification_authorization_is_jwt():
    from devplacepy import push

    token = push.create_notification_authorization("https://push.example.com/endpoint")
    assert token.count(".") == 2
