from unittest.mock import patch

import pytest

from pallycon import PallyConClient


@pytest.fixture()
def client():
    return PallyConClient(
        site_id="TUTO",
        site_key="lU5D8s3PWoLls3PWFWkClULlFWk5D8oC",
        access_key="<KEY>",
        drm_type=PallyConClient.DrmType.WIDEVINE.value,
        user_id="test-user",
        content_id="bigbuckbunny",
        license_rule={
            "playback_policy": {"limit": True, "persistent": False, "duration": 3600}
        },
    )


class TestPallyConClient:
    def test_encrypted_license_rule(self, client):
        assert (
            client.encrypted_license_rule
            == "<KEY>
        )

    def test_license_token(self, client):
        with patch(
            "pallycon.PallyConClient._get_timestamp",
            return_value="2019-07-17T08:57:04Z",
        ):
            # {
            #     "drm_type": "Widevine",
            #     "site_id": "TUTO",
            #     "user_id": "test-user",
            #     "cid": "bigbuckbunny",
            #     "token": "<KEY>
            #     "timestamp": "2019-07-17T08:57:04Z",
            #     "hash": "0Zef3WHBbzQAR0oGf5KXn25G1TmvB2Bkvzv+7OqIWvQ=",
            # }
            assert (
                client.license_token
                == "<KEY>
            )

from unittest.mock import patch

import pytest

from pallycon import PallyConClient


@pytest.fixture()
def client():
    return PallyConClient(
        site_id="TUTO",
        site_key="lU5D8s3PWoLls3PWFWkClULlFWk5D8oC",
        access_key="<KEY>",
        drm_type=PallyConClient.DrmType.WIDEVINE.value,
        user_id="test-user",
        content_id="bigbuckbunny",
        license_rule={
            "playback_policy": {"limit": True, "persistent": False, "duration": 3600}
        },
    )


class TestPallyConClient:
    def test_encrypted_license_rule(self, client):
        assert (
            client.encrypted_license_rule
            == "<KEY>
        )

    def test_license_token(self, client):
        with patch(
            "pallycon.PallyConClient._get_timestamp",
            return_value="2019-07-17T08:57:04Z",
        ):
            # {
            #     "drm_type": "Widevine",
            #     "site_id": "TUTO",
            #     "user_id": "test-user",
            #     "cid": "bigbuckbunny",
            #     "token": "<KEY>
            #     "timestamp": "2019-07-17T08:57:04Z",
            #     "hash": "0Zef3WHBbzQAR0oGf5KXn25G1TmvB2Bkvzv+7OqIWvQ=",
            # }
            assert (
                client.license_token
                == "<KEY>
            )

# { #     "drm_type": "Widevine", #     "site_id": "TUTO", #     "user_id": "test-user", #     "cid": "bigbuckbunny", #     "token": "<KEY> #     "timestamp": "2019-07-17T08:57:04Z", #     "hash": "0Zef3WHBbzQAR0oGf5KXn25G1TmvB2Bkvzv+7OqIWvQ=", # }