Skip to content

Commit

Permalink
ci: Add test cases for rendering the cards (DenverCoder1#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
DenverCoder1 committed Oct 14, 2022
1 parent ace8c1d commit 0de9103
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
1 change: 1 addition & 0 deletions api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .index import app
8 changes: 8 additions & 0 deletions tests/conftest.py
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()
74 changes: 73 additions & 1 deletion tests/test_app.py
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

0 comments on commit 0de9103

Please sign in to comment.