2020-07-18 21:20:46 +00:00
|
|
|
# Copyright (C) 2020 by Cathy Hu <cathy.hu@fau.de>
|
2020-09-28 22:39:32 +00:00
|
|
|
# Copyright (C) 2020 by Martin Rey <martin.rey@mailbox.org>
|
2020-07-18 21:20:46 +00:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: 0BSD
|
|
|
|
|
|
|
|
from fastapi import status
|
|
|
|
from kibicara.platforms.twitter.model import Twitter
|
|
|
|
from ormantic.exceptions import NoMatch
|
|
|
|
from pytest import raises
|
|
|
|
|
|
|
|
|
2020-07-18 22:31:10 +00:00
|
|
|
def test_twitter_delete_bot(client, event_loop, twitter, auth_header):
|
2020-07-18 21:20:46 +00:00
|
|
|
response = client.delete(
|
2020-09-28 22:39:32 +00:00
|
|
|
'/api/hoods/{0}/twitter/{1}'.format(twitter.hood.id, twitter.id), headers=auth_header
|
2020-07-18 21:20:46 +00:00
|
|
|
)
|
|
|
|
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
|
2020-09-28 22:39:32 +00:00
|
|
|
response = client.delete('/api/hoods/{0}/twitter/7331'.format(hood_id), headers=auth_header)
|
2020-07-18 21:20:46 +00:00
|
|
|
assert response.status_code == status.HTTP_404_NOT_FOUND
|
2020-09-28 22:39:32 +00:00
|
|
|
response = client.delete('/api/hoods/{0}/twitter/wrong'.format(hood_id), headers=auth_header)
|
2020-07-18 21:20:46 +00:00
|
|
|
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
|
|
|
|
|
|
|
|
|
|
|
|
def test_twitter_delete_bot_unauthorized(client, twitter):
|
2020-09-28 22:39:32 +00:00
|
|
|
response = client.delete('/api/hoods/{0}/twitter/{1}'.format(twitter.hood.id, twitter.id))
|
2020-07-18 21:20:46 +00:00
|
|
|
assert response.status_code == status.HTTP_401_UNAUTHORIZED
|