forked from DenverCoder1/github-readme-youtube-cards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: Add test cases for rendering the cards (DenverCoder1#44)
- Loading branch information
1 parent
ace8c1d
commit 0de9103
Showing
3 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .index import app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import pytest | ||
|
||
from api import app | ||
|
||
|
||
@pytest.fixture() | ||
def client(): | ||
return app.test_client() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,73 @@ | ||
"""TODO: Tests for the rendering of SVG cards.""" | ||
import re | ||
from urllib.parse import urlencode | ||
|
||
|
||
def test_request_no_id(client): | ||
response = client.get("/") | ||
data = response.data.decode("utf-8") | ||
|
||
assert response.status_code == 400 | ||
assert "Required parameter 'id' is missing" in data | ||
|
||
|
||
def test_request_invalid_id(client): | ||
response = client.get("/?id=**********") | ||
data = response.data.decode("utf-8") | ||
|
||
assert response.status_code == 400 | ||
assert "id expects a video ID but got '**********'" in data | ||
|
||
|
||
def test_request_unknown_id(client): | ||
response = client.get("/?id=abc_123-456") | ||
data = response.data.decode("utf-8") | ||
|
||
assert response.status_code == 404 | ||
assert "Not Found" in data | ||
|
||
|
||
def test_request_valid_params(client): | ||
params = { | ||
"id": "dQw4w9WgXcQ", | ||
"title": "Rick Astley - Never Gonna Give You Up (Official Music Video)", | ||
"timestamp": "1256450400", | ||
"background_color": "#000000", | ||
"title_color": "#111111", | ||
"stats_color": "#222222", | ||
"width": "500", | ||
"duration": "211", | ||
} | ||
response = client.get(f"/?{urlencode(params)}") | ||
data = response.data.decode("utf-8") | ||
|
||
assert response.status_code == 200 | ||
|
||
# test views | ||
views_regex = re.compile(r"\d+(?:\.\d)?[KMBT]? views") | ||
assert views_regex.search(data) is not None | ||
|
||
# test width | ||
assert 'width="500"' in data | ||
|
||
# test background color | ||
assert 'fill="#000000"' in data | ||
|
||
# test title color | ||
assert 'fill="#111111"' in data | ||
|
||
# test stats color | ||
assert 'fill="#222222"' in data | ||
|
||
# test title | ||
assert "Rick Astley - Never Gonna Give You Up (Official Music Video)" in data | ||
|
||
# test duration | ||
assert "3:31" in data | ||
|
||
# test thumbnail | ||
thumbnail_regex = re.compile(r'href="data:image/jpeg;base64,[a-zA-Z0-9+/]+={0,2}"') | ||
assert thumbnail_regex.search(data) is not None | ||
|
||
# test timestamp | ||
timestamp_regex = re.compile(r"\d+ years ago") | ||
assert timestamp_regex.search(data) is not None |