all repos — FixYouTube-legacy @ 6394a2385768605c8c2b66f3c9a0f6353e68ec91

A better way to embed YouTube videos everywhere (inspired by FixTweet).

tests/test_flask.py (view raw)

 1import pytest
 2import fixyoutube.constants as c
 3from fixyoutube import app as flask_app
 4from fixyoutube.db import clear_cache
 5
 6@pytest.fixture()
 7def app():
 8    flask_app.config.update({ "TESTING": True })
 9    clear_cache()
10    yield flask_app
11
12@pytest.fixture()
13def client(app):
14    return app.test_client()
15
16def test_homepage(client):
17    response = client.get("/")
18    assert b"youtu.be" in response.data
19
20def test_redirect(client):
21    response = client.get("/" + c.GOOD_VIDEO_ID)
22    assert response.location == c.BASE_URL + c.GOOD_VIDEO_ID
23
24def test_working_video(client):
25    response = client.get("/" + c.GOOD_VIDEO_ID, headers={'User-Agent': c.TELEGRAM_USER_AGENT})
26    response_data = response.data.decode("utf-8")
27    assert b"/proxy/" + c.GOOD_VIDEO_ID.encode("utf-8") in response.data
28
29    response = client.get("/proxy/" + c.GOOD_VIDEO_ID)
30    assert response.status_code == 200
31
32def test_not_working_video(client):
33    response = client.get("/" + c.BAD_VIDEO_ID, headers={'User-Agent': c.TELEGRAM_USER_AGENT})
34    assert b"/proxy/" + c.BAD_VIDEO_ID.encode("utf-8") not in response.data
35    
36    response = client.get("/proxy/" + c.BAD_VIDEO_ID)
37    assert response.status_code == 400