[tests] Split conftest.py into subfolders

This commit is contained in:
Cathy Hu 2020-07-19 14:13:15 +02:00
parent 2af4b27e0b
commit a8f4d2220b
4 changed files with 60 additions and 40 deletions

View file

@ -6,9 +6,7 @@
from fastapi import FastAPI, status
from fastapi.testclient import TestClient
from kibicara import email
from kibicara.model import Hood, Mapping
from kibicara.platforms.twitter.model import Twitter
from kibicara.platforms.telegram.model import Telegram
from kibicara.model import Mapping
from kibicara.webapi import router
from pytest import fixture
from urllib.parse import urlparse
@ -121,40 +119,3 @@ def test_id(client, hood_id, auth_header):
test_id = int(response.headers['Location'])
yield test_id
client.delete('/api/hoods/%d/test/%d' % (hood_id, test_id), headers=auth_header)
@fixture(scope="function")
def email_row(client, hood_id, auth_header):
response = client.post(
'/api/hoods/%d/email/' % hood_id,
json={'name': 'kibicara-test'},
headers=auth_header,
)
assert response.status_code == status.HTTP_201_CREATED
email_id = int(response.headers['Location'])
yield response.json()
client.delete('/api/hoods/%d/email/%d' % (hood_id, email_id), headers=auth_header)
@fixture(scope='function')
def twitter(event_loop, hood_id):
hood = event_loop.run_until_complete(Hood.objects.get(id=hood_id))
return event_loop.run_until_complete(
Twitter.objects.create(
hood=hood,
access_token='access_token123',
access_token_secret='access_token_secret123',
)
)
@fixture(scope='function')
def telegram(event_loop, hood_id, bot):
hood = event_loop.run_until_complete(Hood.objects.get(id=hood_id))
return event_loop.run_until_complete(
Telegram.objects.create(
hood=hood,
api_token=bot['api_token'],
welcome_message=bot['welcome_message'],
)
)

View file

@ -0,0 +1,21 @@
# Copyright (C) 2020 by Maike <maike@systemli.org>
# Copyright (C) 2020 by Cathy Hu <cathy.hu@fau.de>
#
# SPDX-License-Identifier: 0BSD
from fastapi import status
from pytest import fixture
@fixture(scope="function")
def email_row(client, hood_id, auth_header):
response = client.post(
'/api/hoods/%d/email/' % hood_id,
json={'name': 'kibicara-test'},
headers=auth_header,
)
assert response.status_code == status.HTTP_201_CREATED
email_id = int(response.headers['Location'])
yield response.json()
client.delete('/api/hoods/%d/email/%d' % (hood_id, email_id), headers=auth_header)

View file

@ -0,0 +1,19 @@
# Copyright (C) 2020 by Cathy Hu <cathy.hu@fau.de>
#
# SPDX-License-Identifier: 0BSD
from kibicara.model import Hood
from kibicara.platforms.telegram.model import Telegram
from pytest import fixture
@fixture(scope='function')
def telegram(event_loop, hood_id, bot):
hood = event_loop.run_until_complete(Hood.objects.get(id=hood_id))
return event_loop.run_until_complete(
Telegram.objects.create(
hood=hood,
api_token=bot['api_token'],
welcome_message=bot['welcome_message'],
)
)

View file

@ -0,0 +1,19 @@
# Copyright (C) 2020 by Cathy Hu <cathy.hu@fau.de>
#
# SPDX-License-Identifier: 0BSD
from kibicara.model import Hood
from kibicara.platforms.twitter.model import Twitter
from pytest import fixture
@fixture(scope='function')
def twitter(event_loop, hood_id):
hood = event_loop.run_until_complete(Hood.objects.get(id=hood_id))
return event_loop.run_until_complete(
Twitter.objects.create(
hood=hood,
access_token='access_token123',
access_token_secret='access_token_secret123',
)
)