[tests] Add tests for deleting a twitter bot
This commit is contained in:
parent
48db2de748
commit
efebe40a44
|
@ -6,7 +6,8 @@
|
||||||
from fastapi import FastAPI, status
|
from fastapi import FastAPI, status
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from kibicara import email
|
from kibicara import email
|
||||||
from kibicara.model import Mapping
|
from kibicara.model import Hood, Mapping
|
||||||
|
from kibicara.platforms.twitter.model import Twitter
|
||||||
from kibicara.webapi import router
|
from kibicara.webapi import router
|
||||||
from pytest import fixture
|
from pytest import fixture
|
||||||
|
|
||||||
|
@ -131,3 +132,15 @@ def email_row(client, hood_id, auth_header):
|
||||||
email_id = int(response.headers['Location'])
|
email_id = int(response.headers['Location'])
|
||||||
yield response.json()
|
yield response.json()
|
||||||
client.delete('/api/hoods/%d/email/%d' % (hood_id, email_id), headers=auth_header)
|
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',
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
|
@ -120,13 +120,18 @@ def test_twitter_callback_invalid_oauth_token(client):
|
||||||
assert response.status_code == status.HTTP_404_NOT_FOUND
|
assert response.status_code == status.HTTP_404_NOT_FOUND
|
||||||
|
|
||||||
|
|
||||||
def test_twitter_create_twitter_invalid_hood(client, auth_header):
|
def test_twitter_create_twitter_invalid_id(client, auth_header):
|
||||||
response = client.post('/api/hoods/1337/twitter/', headers=auth_header)
|
response = client.post('/api/hoods/1337/twitter/', headers=auth_header)
|
||||||
assert response.status_code == status.HTTP_404_NOT_FOUND
|
assert response.status_code == status.HTTP_404_NOT_FOUND
|
||||||
response = client.post('/api/hoods/wrong/twitter/', headers=auth_header)
|
response = client.post('/api/hoods/wrong/twitter/', headers=auth_header)
|
||||||
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
|
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
|
||||||
|
|
||||||
|
|
||||||
|
def test_twitter_create_unauthorized(client, hood_id):
|
||||||
|
response = client.post('/api/hoods/{hood_id}/twitter/')
|
||||||
|
assert response.status_code == status.HTTP_401_UNAUTHORIZED
|
||||||
|
|
||||||
|
|
||||||
def test_twitter_create_wrong_consumer_keys(client, monkeypatch, auth_header, hood_id):
|
def test_twitter_create_wrong_consumer_keys(client, monkeypatch, auth_header, hood_id):
|
||||||
# No consumer keys
|
# No consumer keys
|
||||||
response = client.post(f'/api/hoods/{hood_id}/twitter/', headers=auth_header)
|
response = client.post(f'/api/hoods/{hood_id}/twitter/', headers=auth_header)
|
||||||
|
|
33
tests/test_api_twitter_delete_bot.py
Normal file
33
tests/test_api_twitter_delete_bot.py
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
# Copyright (C) 2020 by Cathy Hu <cathy.hu@fau.de>
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: 0BSD
|
||||||
|
|
||||||
|
from fastapi import status
|
||||||
|
from kibicara.platforms.twitter.model import Twitter
|
||||||
|
from ormantic.exceptions import NoMatch
|
||||||
|
from pytest import raises
|
||||||
|
|
||||||
|
|
||||||
|
def test_twitter_delete_bot(client, event_loop, twitter, auth_header, monkeypatch):
|
||||||
|
response = client.delete(
|
||||||
|
f'/api/hoods/{twitter.hood.id}/twitter/{twitter.id}', headers=auth_header
|
||||||
|
)
|
||||||
|
assert response.status_code == status.HTTP_204_NO_CONTENT
|
||||||
|
with raises(NoMatch):
|
||||||
|
event_loop.run_until_complete(Twitter.objects.get(id=twitter.id))
|
||||||
|
|
||||||
|
|
||||||
|
def test_twitter_delete_bot_invalid_id(client, auth_header, hood_id):
|
||||||
|
response = client.delete('/api/hoods/1337/twitter/123', headers=auth_header)
|
||||||
|
assert response.status_code == status.HTTP_404_NOT_FOUND
|
||||||
|
response = client.delete('/api/hoods/wrong/twitter/123', headers=auth_header)
|
||||||
|
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
|
||||||
|
response = client.delete(f'/api/hoods/{hood_id}/twitter/7331', headers=auth_header)
|
||||||
|
assert response.status_code == status.HTTP_404_NOT_FOUND
|
||||||
|
response = client.delete(f'/api/hoods/{hood_id}/twitter/wrong', headers=auth_header)
|
||||||
|
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
|
||||||
|
|
||||||
|
|
||||||
|
def test_twitter_delete_bot_unauthorized(client, twitter):
|
||||||
|
response = client.delete(f'/api/hoods/{twitter.hood.id}/twitter/{twitter.id}')
|
||||||
|
assert response.status_code == status.HTTP_401_UNAUTHORIZED
|
Loading…
Reference in a new issue