add test_captions
Browse files- tests/test_captions.py +34 -0
tests/test_captions.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pytube import Caption, CaptionQuery
|
2 |
+
|
3 |
+
|
4 |
+
def test_caption_query_all():
|
5 |
+
caption1 = Caption(
|
6 |
+
{"url": "url1", "name": {"simpleText": "name1"}, "languageCode": "en"}
|
7 |
+
)
|
8 |
+
caption2 = Caption(
|
9 |
+
{"url": "url2", "name": {"simpleText": "name2"}, "languageCode": "fr"}
|
10 |
+
)
|
11 |
+
caption_query = CaptionQuery(captions=[caption1, caption2])
|
12 |
+
assert caption_query.captions == [caption1, caption2]
|
13 |
+
|
14 |
+
|
15 |
+
def test_caption_query_get_by_language_code_when_exists():
|
16 |
+
caption1 = Caption(
|
17 |
+
{"url": "url1", "name": {"simpleText": "name1"}, "languageCode": "en"}
|
18 |
+
)
|
19 |
+
caption2 = Caption(
|
20 |
+
{"url": "url2", "name": {"simpleText": "name2"}, "languageCode": "fr"}
|
21 |
+
)
|
22 |
+
caption_query = CaptionQuery(captions=[caption1, caption2])
|
23 |
+
assert caption_query.get_by_language_code("en") == caption1
|
24 |
+
|
25 |
+
|
26 |
+
def test_caption_query_get_by_language_code_when_not_exists():
|
27 |
+
caption1 = Caption(
|
28 |
+
{"url": "url1", "name": {"simpleText": "name1"}, "languageCode": "en"}
|
29 |
+
)
|
30 |
+
caption2 = Caption(
|
31 |
+
{"url": "url2", "name": {"simpleText": "name2"}, "languageCode": "fr"}
|
32 |
+
)
|
33 |
+
caption_query = CaptionQuery(captions=[caption1, caption2])
|
34 |
+
assert caption_query.get_by_language_code("hello") is None
|