File: test_auth.py

package info (click to toggle)
python-youtubeaio 2.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 720 kB
  • sloc: python: 1,549; makefile: 3
file content (37 lines) | stat: -rw-r--r-- 1,508 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""Tests for the YouTube client."""

import aiohttp
import pytest

from youtubeaio.types import AuthScope, MissingScopeError
from youtubeaio.youtube import YouTube


async def test_user_authentication() -> None:
    """Test setting user authentication."""
    async with aiohttp.ClientSession() as session:
        youtube = YouTube(session=session)
        await youtube.set_user_authentication("token", [AuthScope.READ_ONLY], "refresh")
        assert youtube.get_user_auth_token() == "token"
        await youtube.close()


async def test_user_authentication_without_scopes() -> None:
    """Test setting user authentication without scopes."""
    async with aiohttp.ClientSession() as session:
        youtube = YouTube(session=session)
        with pytest.raises(MissingScopeError):
            await youtube.set_user_authentication("token", [], "refresh")
        await youtube.close()


async def test_user_authentication_without_refresh_token() -> None:
    """Test setting user authentication without refresh token."""
    async with aiohttp.ClientSession() as session:
        youtube = YouTube(session=session, app_id="asd", app_secret="asd")
        with pytest.raises(ValueError):
            await youtube.set_user_authentication("token", [AuthScope.READ_ONLY])
        youtube = YouTube(session=session, auto_refresh_auth=False)
        await youtube.set_user_authentication("token", [AuthScope.READ_ONLY])
        assert youtube.get_user_auth_token() == "token"
        await youtube.close()