Skip to content

Commit

Permalink
Merge pull request pycontw#1 from erik1110/feature/unit_test
Browse files Browse the repository at this point in the history
[feat] add test cases
  • Loading branch information
erik1110 committed Sep 16, 2023
2 parents 5d3c25f + 68e82bd commit 9f81fd0
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/ccip/tests/api/test_ccip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import pytest
from django.conf import settings

endpoint = "/ccip/"

def assert_data_structure(data, key):
assert key in data
items = data.get(key, [])
for item in items:
assert 'id' in item
assert 'zh' in item
assert 'en' in item
assert 'name' in item['zh']
assert 'name' in item['en']
if key == "speakers":
assert 'avatar' in item
assert 'bio' in item['zh']
assert 'bio' in item['en']

@pytest.mark.django_db
def test_data_structure(client):
response = client.get(endpoint, follow=True)
assert response.status_code == 200
data = response.json()

assert_data_structure(data, 'session_types')
assert_data_structure(data, 'tags')
assert_data_structure(data, 'rooms')
assert_data_structure(data, 'speakers')

@pytest.mark.django_db
def test_session(client):
response = client.get(endpoint, follow=True)
data = response.json()
assert 'sessions' in data
sessions = data.get('sessions', [])
# 檢查每個 session 是否包含所需的字段
required_fields = [
"id", "type", "start", "end", "slide", "speakers", "tags",
"en", "zh", "room", "broadcast", "qa", "live", "record"
]
for session in sessions:
for field in required_fields:
assert field in session
assert 'title' in session['en']
assert 'description' in session['en']
assert 'title' in session['zh']
assert 'description' in session['zh']

0 comments on commit 9f81fd0

Please sign in to comment.