Skip to content

Commit

Permalink
Merge pull request #1146 from pycontw/test_attendee
Browse files Browse the repository at this point in the history
test(attendee): add test cases for attendee apis
  • Loading branch information
josix authored Jul 24, 2023
2 parents 2ffcf7b + 7fff581 commit acf07f8
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/attendee/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import pytest
from django.conf import settings
from registry.helper import reg
from attendee.models import Attendee
from core.models import Token


@pytest.mark.parametrize('attendee_token,status,num_channel', [
('123', 400, 0),
('1234', 200, 0),
('1234', 200, 1),
('1234', 200, 2),
])
@pytest.mark.django_db
def test_attendee(drf_api_client, bare_user, attendee_token, status, num_channel):
token = Token.objects.get_or_create(user=bare_user)
drf_api_client.credentials(HTTP_AUTHORIZATION="Token " + str(token[0]))
attendee = Attendee(token="1234")
attendee.save() # insert to database
# add slug
key_prefix = f"{settings.CONFERENCE_DEFAULT_SLUG}.live."
reg["pycontw-1999.live.r1"] = "video_old_id" # unrelated
for i in range(num_channel):
reg[f"{key_prefix}r{i}"] = f"video_id_{i}"

# test
response = drf_api_client.post('/api/attendee/verify/', data={"token": attendee_token})
assert response.status_code == status
if status == 200:
assert len(response.json()["youtube_infos"]) == num_channel

0 comments on commit acf07f8

Please sign in to comment.