From a8f4d2220bdf6d2d35418f82a0a1fe3dcd1bee24 Mon Sep 17 00:00:00 2001 From: Cathy Hu Date: Sun, 19 Jul 2020 14:13:15 +0200 Subject: [PATCH] [tests] Split conftest.py into subfolders --- tests/conftest.py | 41 +------------------------------- tests/tests_email/conftest.py | 21 ++++++++++++++++ tests/tests_telegram/conftest.py | 19 +++++++++++++++ tests/tests_twitter/conftest.py | 19 +++++++++++++++ 4 files changed, 60 insertions(+), 40 deletions(-) create mode 100644 tests/tests_email/conftest.py create mode 100644 tests/tests_telegram/conftest.py create mode 100644 tests/tests_twitter/conftest.py diff --git a/tests/conftest.py b/tests/conftest.py index 317f158..35f667d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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'], - ) - ) diff --git a/tests/tests_email/conftest.py b/tests/tests_email/conftest.py new file mode 100644 index 0000000..b7d211e --- /dev/null +++ b/tests/tests_email/conftest.py @@ -0,0 +1,21 @@ +# Copyright (C) 2020 by Maike +# Copyright (C) 2020 by Cathy Hu +# +# 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) diff --git a/tests/tests_telegram/conftest.py b/tests/tests_telegram/conftest.py new file mode 100644 index 0000000..aa2b8ef --- /dev/null +++ b/tests/tests_telegram/conftest.py @@ -0,0 +1,19 @@ +# Copyright (C) 2020 by Cathy Hu +# +# 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'], + ) + ) diff --git a/tests/tests_twitter/conftest.py b/tests/tests_twitter/conftest.py new file mode 100644 index 0000000..556ff11 --- /dev/null +++ b/tests/tests_twitter/conftest.py @@ -0,0 +1,19 @@ +# Copyright (C) 2020 by Cathy Hu +# +# 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', + ) + )