File: test_short.py

package info (click to toggle)
python-youtubeaio 2.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 788 kB
  • sloc: python: 1,658; makefile: 3
file content (49 lines) | stat: -rw-r--r-- 1,350 bytes parent folder | download
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
38
39
40
41
42
43
44
45
46
47
48
49
"""Tests for the YouTube client."""

import aiohttp
from aresponses import ResponsesMockServer

from youtubeaio.youtube import YouTube


async def test_is_short(
    aresponses: ResponsesMockServer,
) -> None:
    """Test YouTube video id that is a short."""
    aresponses.add(
        "www.youtube.com",
        "/shorts/2YUPfsi8PF4",
        "HEAD",
        aresponses.Response(
            status=200,
            headers={"Content-Type": "text/html"},
        ),
    )
    async with aiohttp.ClientSession() as session:
        youtube = YouTube(session=session)
        response = await youtube.is_short("2YUPfsi8PF4")
        assert response
        await youtube.close()


async def test_is_not_short(
    aresponses: ResponsesMockServer,
) -> None:
    """Test YouTube video id that is not a short."""
    aresponses.add(
        "www.youtube.com",
        "/shorts/KXaMtA6kWXU",
        "HEAD",
        aresponses.Response(
            status=303,
            headers={
                "Content-Type": "application/binary",
                "Location": "https://www.youtube.com/watch?v=KXaMtA6kWXU",
            },
        ),
    )
    async with aiohttp.ClientSession() as session:
        youtube = YouTube(session=session)
        response = await youtube.is_short("KXaMtA6kWXU")
        assert not response
        await youtube.close()