-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_twarc_videos.py
57 lines (47 loc) · 1.7 KB
/
test_twarc_videos.py
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
50
51
52
53
54
55
import os
import json
import dotenv
import shutil
import pathlib
import twarc_videos
from twarc.client2 import Twarc2
from click.testing import CliRunner
dotenv.load_dotenv()
bearer_token = os.environ.get('BEARER_TOKEN')
test_data = pathlib.Path('test.json')
test_videos_dir = pathlib.Path('videos')
if test_videos_dir.is_dir():
shutil.rmtree(test_videos_dir)
def test_bearer_token():
assert bearer_token
def test_get_youtube_tweet():
if test_data.is_file():
test_data.unlink()
t = Twarc2(bearer_token=bearer_token)
results = next(t.search_recent('url:"https://youtu.be"'))
results['data'] = results['data'][0:2]
json.dump(results, test_data.open('w'))
def test_download_youtube():
assert test_data.is_file()
runner = CliRunner()
result = runner.invoke(twarc_videos.videos, ['--timeout', 10, 'test.json'])
assert test_videos_dir.is_dir()
videos_dir = test_videos_dir / "youtube"
assert videos_dir.is_dir()
assert len(list(videos_dir.iterdir())) > 0
def test_get_vimeo_tweet():
if test_data.is_file():
test_data.unlink()
t = Twarc2(bearer_token=bearer_token)
results = next(t.search_recent('url:"https://vimeo.com"'))
results['data'] = results['data'][0:2]
json.dump(results, test_data.open('w'))
def test_download_vimeo():
assert test_data.is_file()
runner = CliRunner()
result = runner.invoke(twarc_videos.videos, ['--timeout', 10, 'test.json'])
assert test_videos_dir.is_dir()
videos_dir1 = test_videos_dir / "vimeo"
videos_dir2 = test_videos_dir / "vimeo_-ondemand"
assert videos_dir1.is_dir() or videos_dir2.is_dir()
assert len(list(videos_dir1.iterdir())) > 0 or len(list(videos_dir2.iterdir())) > 0