# Path: notifications_utils/base64_uuid.py
# def base64_to_bytes(key):
#     return urlsafe_b64decode(key + '==')
# 
# def base64_to_uuid(value):
#     # uuids are 16 bytes, and will always have two ==s of padding
#     return UUID(bytes=urlsafe_b64decode(value.encode('ascii') + b'=='))
# 
# def bytes_to_base64(bytes):
#     # remove trailing = to save precious bytes
#     return urlsafe_b64encode(bytes).decode('ascii').rstrip('=')
# 
# def uuid_to_base64(value):
#     if not isinstance(value, UUID):
#         value = UUID(value)
#     return bytes_to_base64(value.bytes)


import os
import pytest
from uuid import UUID
from notifications_utils.base64_uuid import (
    base64_to_bytes,
    base64_to_uuid,
    bytes_to_base64,
    uuid_to_base64,
)




def test_bytes_to_base64_to_bytes():
    b = os.urandom(32)
    b64 = bytes_to_base64(b)
    assert base64_to_bytes(b64) == b


@pytest.mark.parametrize('url_val', [
    'AAAAAAAAAAAAAAAAAAAAAQ',
    'AAAAAAAAAAAAAAAAAAAAAQ=',  # even though this has invalid padding we put extra =s on the end so this is okay
    'AAAAAAAAAAAAAAAAAAAAAQ==',
])
def test_base64_converter_to_python(url_val):
    assert base64_to_uuid(url_val) == UUID(int=1)


@pytest.mark.parametrize('python_val', [
    UUID(int=1),
    '00000000-0000-0000-0000-000000000001'
])
def test_base64_converter_to_url(python_val):

# Path: notifications_utils/base64_uuid.py
# def base64_to_bytes(key):
#     return urlsafe_b64decode(key + '==')
# 
# def base64_to_uuid(value):
#     # uuids are 16 bytes, and will always have two ==s of padding
#     return UUID(bytes=urlsafe_b64decode(value.encode('ascii') + b'=='))
# 
# def bytes_to_base64(bytes):
#     # remove trailing = to save precious bytes
#     return urlsafe_b64encode(bytes).decode('ascii').rstrip('=')
# 
# def uuid_to_base64(value):
#     if not isinstance(value, UUID):
#         value = UUID(value)
#     return bytes_to_base64(value.bytes)


# Path: tests/test_base64_uuid.py
import os
import pytest
from uuid import UUID
from notifications_utils.base64_uuid import (
    base64_to_bytes,
    base64_to_uuid,
    bytes_to_base64,
    uuid_to_base64,
)





def test_bytes_to_base64_to_bytes():
    b = os.urandom(32)
    b64 = bytes_to_base64(b)
    assert base64_to_bytes(b64) == b


@pytest.mark.parametrize('url_val', [
    'AAAAAAAAAAAAAAAAAAAAAQ',
    'AAAAAAAAAAAAAAAAAAAAAQ=',  # even though this has invalid padding we put extra =s on the end so this is okay
    'AAAAAAAAAAAAAAAAAAAAAQ==',
])
def test_base64_converter_to_python(url_val):
    assert base64_to_uuid(url_val) == UUID(int=1)


@pytest.mark.parametrize('python_val', [
    UUID(int=1),
    '00000000-0000-0000-0000-000000000001'
])
def test_base64_converter_to_url(python_val):

    assert uuid_to_base64(python_val) == 'AAAAAAAAAAAAAAAAAAAAAQ'