[misc] Use black to reformat code
This commit is contained in:
parent
4146cb89b5
commit
2c058d7e15
|
@ -142,16 +142,19 @@ class Censor:
|
||||||
async def __is_appropriate(self, message):
|
async def __is_appropriate(self, message):
|
||||||
for badword in await BadWord.objects.filter(hood=self.hood).all():
|
for badword in await BadWord.objects.filter(hood=self.hood).all():
|
||||||
if search(badword.pattern, message.text, IGNORECASE):
|
if search(badword.pattern, message.text, IGNORECASE):
|
||||||
logger.debug('Matched bad word - dropped message: {0}'.format(
|
logger.debug(
|
||||||
message.text))
|
'Matched bad word - dropped message: {0}'.format(message.text)
|
||||||
|
)
|
||||||
return False
|
return False
|
||||||
for trigger in await Trigger.objects.filter(hood=self.hood).all():
|
for trigger in await Trigger.objects.filter(hood=self.hood).all():
|
||||||
if search(trigger.pattern, message.text, IGNORECASE):
|
if search(trigger.pattern, message.text, IGNORECASE):
|
||||||
logger.debug('Matched trigger - passed message: {0}'.format(
|
logger.debug(
|
||||||
message.text))
|
'Matched trigger - passed message: {0}'.format(message.text)
|
||||||
|
)
|
||||||
return True
|
return True
|
||||||
logger.debug('Did not match any trigger - dropped message: {0}'.format(
|
logger.debug(
|
||||||
message.text))
|
'Did not match any trigger - dropped message: {0}'.format(message.text)
|
||||||
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,9 @@ class EmailBot(Censor):
|
||||||
while True:
|
while True:
|
||||||
message = await self.receive()
|
message = await self.receive()
|
||||||
logger.debug(
|
logger.debug(
|
||||||
'Received message from censor ({0}): {1}'.format(self.hood.name, message.text)
|
'Received message from censor ({0}): {1}'.format(
|
||||||
|
self.hood.name, message.text
|
||||||
|
)
|
||||||
)
|
)
|
||||||
for subscriber in await EmailSubscribers.objects.filter(
|
for subscriber in await EmailSubscribers.objects.filter(
|
||||||
hood=self.hood
|
hood=self.hood
|
||||||
|
|
|
@ -66,7 +66,9 @@ class Main:
|
||||||
)
|
)
|
||||||
|
|
||||||
response = post(
|
response = post(
|
||||||
'{0}/api/hoods/{1}/email/messages/'.format(config['root_url'], email.hood.pk),
|
'{0}/api/hoods/{1}/email/messages/'.format(
|
||||||
|
config['root_url'], email.hood.pk
|
||||||
|
),
|
||||||
json={'text': text, 'secret': email.secret},
|
json={'text': text, 'secret': email.secret},
|
||||||
)
|
)
|
||||||
if response.status_code == status.HTTP_201_CREATED:
|
if response.status_code == status.HTTP_201_CREATED:
|
||||||
|
|
|
@ -48,13 +48,15 @@ class TelegramBot(Censor):
|
||||||
await self.telegram_model.update(username=user.username)
|
await self.telegram_model.update(username=user.username)
|
||||||
await gather(self.dp.start_polling(), self._push())
|
await gather(self.dp.start_polling(), self._push())
|
||||||
except CancelledError:
|
except CancelledError:
|
||||||
logger.debug('Bot {0} received Cancellation.'.format(
|
logger.debug(
|
||||||
self.telegram_model.hood.name))
|
'Bot {0} received Cancellation.'.format(self.telegram_model.hood.name)
|
||||||
|
)
|
||||||
self.dp = None
|
self.dp = None
|
||||||
raise
|
raise
|
||||||
except exceptions.ValidationError:
|
except exceptions.ValidationError:
|
||||||
logger.debug('Bot {0} has invalid auth token.'.format(
|
logger.debug(
|
||||||
self.telegram_model.hood.name))
|
'Bot {0} has invalid auth token.'.format(self.telegram_model.hood.name)
|
||||||
|
)
|
||||||
await self.telegram_model.update(enabled=False)
|
await self.telegram_model.update(enabled=False)
|
||||||
finally:
|
finally:
|
||||||
logger.debug('Bot {0} stopped.'.format(self.telegram_model.hood.name))
|
logger.debug('Bot {0} stopped.'.format(self.telegram_model.hood.name))
|
||||||
|
@ -64,7 +66,8 @@ class TelegramBot(Censor):
|
||||||
message = await self.receive()
|
message = await self.receive()
|
||||||
logger.debug(
|
logger.debug(
|
||||||
'Received message from censor ({0}): {1}'.format(
|
'Received message from censor ({0}): {1}'.format(
|
||||||
self.telegram_model.hood.name, message.text)
|
self.telegram_model.hood.name, message.text
|
||||||
|
)
|
||||||
)
|
)
|
||||||
for user in await TelegramUser.objects.filter(
|
for user in await TelegramUser.objects.filter(
|
||||||
bot=self.telegram_model
|
bot=self.telegram_model
|
||||||
|
@ -76,13 +79,15 @@ class TelegramBot(Censor):
|
||||||
await self.bot.send_message(user_id, message, disable_notification=False)
|
await self.bot.send_message(user_id, message, disable_notification=False)
|
||||||
except exceptions.BotBlocked:
|
except exceptions.BotBlocked:
|
||||||
logger.error(
|
logger.error(
|
||||||
'Target [ID:{0}] ({1}): blocked by user'.format(user_id,
|
'Target [ID:{0}] ({1}): blocked by user'.format(
|
||||||
self.telegram_model.hood.name)
|
user_id, self.telegram_model.hood.name
|
||||||
|
)
|
||||||
)
|
)
|
||||||
except exceptions.ChatNotFound:
|
except exceptions.ChatNotFound:
|
||||||
logger.error(
|
logger.error(
|
||||||
'Target [ID:{0}] ({1}): invalid user ID'.format(user_id,
|
'Target [ID:{0}] ({1}): invalid user ID'.format(
|
||||||
self.telegram_model.hood.name)
|
user_id, self.telegram_model.hood.name
|
||||||
|
)
|
||||||
)
|
)
|
||||||
except exceptions.RetryAfter as e:
|
except exceptions.RetryAfter as e:
|
||||||
logger.error(
|
logger.error(
|
||||||
|
@ -95,12 +100,15 @@ class TelegramBot(Censor):
|
||||||
return await self._send_message(user_id, message)
|
return await self._send_message(user_id, message)
|
||||||
except exceptions.UserDeactivated:
|
except exceptions.UserDeactivated:
|
||||||
logger.error(
|
logger.error(
|
||||||
'Target [ID:{0}] ({1}): user is deactivated'.format(user_id,
|
'Target [ID:{0}] ({1}): user is deactivated'.format(
|
||||||
self.telegram_model.hood.name)
|
user_id, self.telegram_model.hood.name
|
||||||
|
)
|
||||||
)
|
)
|
||||||
except exceptions.TelegramAPIError:
|
except exceptions.TelegramAPIError:
|
||||||
logger.exception(
|
logger.exception(
|
||||||
'Target [ID:{0}] ({1}): failed'.format(user_id, self.telegram_model.hood.name)
|
'Target [ID:{0}] ({1}): failed'.format(
|
||||||
|
user_id, self.telegram_model.hood.name
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
async def _send_welcome(self, message: types.Message):
|
async def _send_welcome(self, message: types.Message):
|
||||||
|
|
|
@ -49,14 +49,18 @@ class TwitterBot(Censor):
|
||||||
user = await self.client.user
|
user = await self.client.user
|
||||||
if user.screen_name:
|
if user.screen_name:
|
||||||
await self.twitter_model.update(username=user.screen_name)
|
await self.twitter_model.update(username=user.screen_name)
|
||||||
logger.debug('Starting Twitter bot: {0}'.format(self.twitter_model.__dict__))
|
logger.debug(
|
||||||
|
'Starting Twitter bot: {0}'.format(self.twitter_model.__dict__)
|
||||||
|
)
|
||||||
await gather(self.poll(), self.push())
|
await gather(self.poll(), self.push())
|
||||||
except CancelledError:
|
except CancelledError:
|
||||||
logger.debug('Bot {0} received Cancellation.'.format(
|
logger.debug(
|
||||||
self.twitter_model.hood.name))
|
'Bot {0} received Cancellation.'.format(self.twitter_model.hood.name)
|
||||||
|
)
|
||||||
except exceptions.Unauthorized:
|
except exceptions.Unauthorized:
|
||||||
logger.debug('Bot {0} has invalid auth token.'.format(
|
logger.debug(
|
||||||
self.twitter_model.hood.name))
|
'Bot {0} has invalid auth token.'.format(self.twitter_model.hood.name)
|
||||||
|
)
|
||||||
await self.twitter_model.update(enabled=False)
|
await self.twitter_model.update(enabled=False)
|
||||||
self.enabled = self.twitter_model.enabled
|
self.enabled = self.twitter_model.enabled
|
||||||
except (KeyError, ValueError, exceptions.NotAuthenticated):
|
except (KeyError, ValueError, exceptions.NotAuthenticated):
|
||||||
|
@ -75,7 +79,8 @@ class TwitterBot(Censor):
|
||||||
mentions = await self._poll_mentions()
|
mentions = await self._poll_mentions()
|
||||||
logger.debug(
|
logger.debug(
|
||||||
'Polled mentions ({0}): {1}'.format(
|
'Polled mentions ({0}): {1}'.format(
|
||||||
self.twitter_model.hood.name, str(mentions))
|
self.twitter_model.hood.name, str(mentions)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
await self.twitter_model.update(
|
await self.twitter_model.update(
|
||||||
dms_since_id=self.dms_since_id, mentions_since_id=self.mentions_since_id
|
dms_since_id=self.dms_since_id, mentions_since_id=self.mentions_since_id
|
||||||
|
@ -141,7 +146,8 @@ class TwitterBot(Censor):
|
||||||
message = await self.receive()
|
message = await self.receive()
|
||||||
logger.debug(
|
logger.debug(
|
||||||
'Received message from censor ({0}): {1}'.format(
|
'Received message from censor ({0}): {1}'.format(
|
||||||
self.twitter_model.hood.name, message.text)
|
self.twitter_model.hood.name, message.text
|
||||||
|
)
|
||||||
)
|
)
|
||||||
if hasattr(message, 'twitter_mention_id'):
|
if hasattr(message, 'twitter_mention_id'):
|
||||||
await self._retweet(message.twitter_mention_id)
|
await self._retweet(message.twitter_mention_id)
|
||||||
|
|
|
@ -103,7 +103,9 @@ def trigger_id(client, hood_id, auth_header):
|
||||||
@fixture(scope='function')
|
@fixture(scope='function')
|
||||||
def badword_id(client, hood_id, auth_header):
|
def badword_id(client, hood_id, auth_header):
|
||||||
response = client.post(
|
response = client.post(
|
||||||
'/api/hoods/{0}/badwords/'.format(hood_id), json={'pattern': ''}, headers=auth_header
|
'/api/hoods/{0}/badwords/'.format(hood_id),
|
||||||
|
json={'pattern': ''},
|
||||||
|
headers=auth_header,
|
||||||
)
|
)
|
||||||
assert response.status_code == status.HTTP_201_CREATED
|
assert response.status_code == status.HTTP_201_CREATED
|
||||||
badword_id = int(response.headers['Location'])
|
badword_id = int(response.headers['Location'])
|
||||||
|
@ -121,4 +123,6 @@ def test_id(client, hood_id, auth_header):
|
||||||
assert response.status_code == status.HTTP_201_CREATED
|
assert response.status_code == status.HTTP_201_CREATED
|
||||||
test_id = int(response.headers['Location'])
|
test_id = int(response.headers['Location'])
|
||||||
yield test_id
|
yield test_id
|
||||||
client.delete('/api/hoods/{0}/test/{1}'.format(hood_id, test_id), headers=auth_header)
|
client.delete(
|
||||||
|
'/api/hoods/{0}/test/{1}'.format(hood_id, test_id), headers=auth_header
|
||||||
|
)
|
||||||
|
|
|
@ -19,4 +19,6 @@ def email_row(client, hood_id, auth_header):
|
||||||
assert response.status_code == status.HTTP_201_CREATED
|
assert response.status_code == status.HTTP_201_CREATED
|
||||||
email_id = int(response.headers['Location'])
|
email_id = int(response.headers['Location'])
|
||||||
yield response.json()
|
yield response.json()
|
||||||
client.delete('/api/hoods/{0}/email/{1}'.format(hood_id, email_id), headers=auth_header)
|
client.delete(
|
||||||
|
'/api/hoods/{0}/email/{1}'.format(hood_id, email_id), headers=auth_header
|
||||||
|
)
|
||||||
|
|
|
@ -15,7 +15,8 @@ from kibicara.webapi.admin import to_token
|
||||||
|
|
||||||
def test_email_subscribe_unsubscribe(client, hood_id, receive_email):
|
def test_email_subscribe_unsubscribe(client, hood_id, receive_email):
|
||||||
response = client.post(
|
response = client.post(
|
||||||
'/api/hoods/{0}/email/subscribe/'.format(hood_id), json={'email': 'test@localhost'}
|
'/api/hoods/{0}/email/subscribe/'.format(hood_id),
|
||||||
|
json={'email': 'test@localhost'},
|
||||||
)
|
)
|
||||||
assert response.status_code == status.HTTP_202_ACCEPTED
|
assert response.status_code == status.HTTP_202_ACCEPTED
|
||||||
mail = receive_email()
|
mail = receive_email()
|
||||||
|
@ -27,17 +28,21 @@ def test_email_subscribe_unsubscribe(client, hood_id, receive_email):
|
||||||
)[0]
|
)[0]
|
||||||
start = len('token=')
|
start = len('token=')
|
||||||
response = client.post(
|
response = client.post(
|
||||||
'/api/hoods/{0}/email/subscribe/confirm/{1}'
|
'/api/hoods/{0}/email/subscribe/confirm/{1}'.format(
|
||||||
.format(hood_id, urlparse(confirm_url).query[start:])
|
hood_id, urlparse(confirm_url).query[start:]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
assert response.status_code == status.HTTP_201_CREATED
|
assert response.status_code == status.HTTP_201_CREATED
|
||||||
response = client.post(
|
response = client.post(
|
||||||
'/api/hoods/{0}/email/subscribe/confirm/{1}'
|
'/api/hoods/{0}/email/subscribe/confirm/{1}'.format(
|
||||||
.format(hood_id, urlparse(confirm_url).query[start:])
|
hood_id, urlparse(confirm_url).query[start:]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
assert response.status_code == status.HTTP_409_CONFLICT
|
assert response.status_code == status.HTTP_409_CONFLICT
|
||||||
token = to_token(email=mail['to'], hood=hood_id)
|
token = to_token(email=mail['to'], hood=hood_id)
|
||||||
response = client.delete('/api/hoods/{0}/email/unsubscribe/{1}'.format(hood_id, token))
|
response = client.delete(
|
||||||
|
'/api/hoods/{0}/email/unsubscribe/{1}'.format(hood_id, token)
|
||||||
|
)
|
||||||
assert response.status_code == status.HTTP_204_NO_CONTENT
|
assert response.status_code == status.HTTP_204_NO_CONTENT
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,9 @@ def test_email_create_unauthorized(client, hood_id):
|
||||||
|
|
||||||
|
|
||||||
def test_email_delete_unauthorized(client, hood_id, email_row):
|
def test_email_delete_unauthorized(client, hood_id, email_row):
|
||||||
response = client.delete('/api/hoods/{0}/email/{1}'.format(hood_id, email_row['id']))
|
response = client.delete(
|
||||||
|
'/api/hoods/{0}/email/{1}'.format(hood_id, email_row['id'])
|
||||||
|
)
|
||||||
assert response.status_code == status.HTTP_401_UNAUTHORIZED
|
assert response.status_code == status.HTTP_401_UNAUTHORIZED
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,9 @@ def test_email_message_wrong(client, hood_id, email_row):
|
||||||
def test_email_unsubscribe_wrong_token(client, hood_id):
|
def test_email_unsubscribe_wrong_token(client, hood_id):
|
||||||
try:
|
try:
|
||||||
client.delete(
|
client.delete(
|
||||||
'/api/hoods/{0}/email/unsubscribe/asdfasdfasdfasdfasdfasdfasdfasdf'.format(hood_id)
|
'/api/hoods/{0}/email/unsubscribe/asdfasdfasdfasdfasdfasdfasdfasdf'.format(
|
||||||
|
hood_id
|
||||||
|
)
|
||||||
)
|
)
|
||||||
except CryptoError:
|
except CryptoError:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -19,7 +19,8 @@ def test_telegram_delete_bot(client, event_loop, bot, telegram, auth_header):
|
||||||
TelegramUser.objects.create(user_id=5678, bot=telegram.id)
|
TelegramUser.objects.create(user_id=5678, bot=telegram.id)
|
||||||
)
|
)
|
||||||
response = client.delete(
|
response = client.delete(
|
||||||
'/api/hoods/{0}/telegram/{1}'.format(telegram.hood.id, telegram.id), headers=auth_header
|
'/api/hoods/{0}/telegram/{1}'.format(telegram.hood.id, telegram.id),
|
||||||
|
headers=auth_header,
|
||||||
)
|
)
|
||||||
assert response.status_code == status.HTTP_204_NO_CONTENT
|
assert response.status_code == status.HTTP_204_NO_CONTENT
|
||||||
with raises(NoMatch):
|
with raises(NoMatch):
|
||||||
|
@ -33,7 +34,9 @@ def test_telegram_delete_bot_invalid_id(client, auth_header, hood_id):
|
||||||
assert response.status_code == status.HTTP_404_NOT_FOUND
|
assert response.status_code == status.HTTP_404_NOT_FOUND
|
||||||
response = client.delete('/api/hoods/wrong/telegram/123', headers=auth_header)
|
response = client.delete('/api/hoods/wrong/telegram/123', headers=auth_header)
|
||||||
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
|
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
|
||||||
response = client.delete('/api/hoods/{0}/telegram/7331'.format(hood_id), headers=auth_header)
|
response = client.delete(
|
||||||
|
'/api/hoods/{0}/telegram/7331'.format(hood_id), headers=auth_header
|
||||||
|
)
|
||||||
assert response.status_code == status.HTTP_404_NOT_FOUND
|
assert response.status_code == status.HTTP_404_NOT_FOUND
|
||||||
response = client.delete(
|
response = client.delete(
|
||||||
'/api/hoods/{0}/telegram/wrong'.format(hood_id), headers=auth_header
|
'/api/hoods/{0}/telegram/wrong'.format(hood_id), headers=auth_header
|
||||||
|
@ -43,5 +46,7 @@ def test_telegram_delete_bot_invalid_id(client, auth_header, hood_id):
|
||||||
|
|
||||||
@mark.parametrize('bot', [{'api_token': 'apitoken123', 'welcome_message': 'msg'}])
|
@mark.parametrize('bot', [{'api_token': 'apitoken123', 'welcome_message': 'msg'}])
|
||||||
def test_telegram_delete_bot_unauthorized(client, bot, telegram):
|
def test_telegram_delete_bot_unauthorized(client, bot, telegram):
|
||||||
response = client.delete('/api/hoods/{0}/telegram/{1}'.format(telegram.hood.id, telegram.id))
|
response = client.delete(
|
||||||
|
'/api/hoods/{0}/telegram/{1}'.format(telegram.hood.id, telegram.id)
|
||||||
|
)
|
||||||
assert response.status_code == status.HTTP_401_UNAUTHORIZED
|
assert response.status_code == status.HTTP_401_UNAUTHORIZED
|
||||||
|
|
|
@ -10,7 +10,8 @@ from pytest import mark
|
||||||
@mark.parametrize('bot', [{'api_token': 'apitoken123', 'welcome_message': 'msg'}])
|
@mark.parametrize('bot', [{'api_token': 'apitoken123', 'welcome_message': 'msg'}])
|
||||||
def test_telegram_get_bot(client, auth_header, event_loop, bot, telegram):
|
def test_telegram_get_bot(client, auth_header, event_loop, bot, telegram):
|
||||||
response = client.get(
|
response = client.get(
|
||||||
'/api/hoods/{0}/telegram/{1}'.format(telegram.hood.id, telegram.id), headers=auth_header
|
'/api/hoods/{0}/telegram/{1}'.format(telegram.hood.id, telegram.id),
|
||||||
|
headers=auth_header,
|
||||||
)
|
)
|
||||||
assert response.status_code == status.HTTP_200_OK
|
assert response.status_code == status.HTTP_200_OK
|
||||||
assert response.json()['id'] == telegram.id
|
assert response.json()['id'] == telegram.id
|
||||||
|
@ -23,13 +24,19 @@ def test_telegram_get_bot_invalid_id(client, auth_header, hood_id):
|
||||||
assert response.status_code == status.HTTP_404_NOT_FOUND
|
assert response.status_code == status.HTTP_404_NOT_FOUND
|
||||||
response = client.get('/api/hoods/wrong/telegram/123', headers=auth_header)
|
response = client.get('/api/hoods/wrong/telegram/123', headers=auth_header)
|
||||||
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
|
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
|
||||||
response = client.get('/api/hoods/{0}/telegram/7331'.format(hood_id), headers=auth_header)
|
response = client.get(
|
||||||
|
'/api/hoods/{0}/telegram/7331'.format(hood_id), headers=auth_header
|
||||||
|
)
|
||||||
assert response.status_code == status.HTTP_404_NOT_FOUND
|
assert response.status_code == status.HTTP_404_NOT_FOUND
|
||||||
response = client.get('/api/hoods/{0}/telegram/wrong'.format(hood_id), headers=auth_header)
|
response = client.get(
|
||||||
|
'/api/hoods/{0}/telegram/wrong'.format(hood_id), headers=auth_header
|
||||||
|
)
|
||||||
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
|
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
|
||||||
|
|
||||||
|
|
||||||
@mark.parametrize('bot', [{'api_token': 'apitoken456', 'welcome_message': 'msg'}])
|
@mark.parametrize('bot', [{'api_token': 'apitoken456', 'welcome_message': 'msg'}])
|
||||||
def test_telegram_get_bot_unauthorized(client, bot, telegram):
|
def test_telegram_get_bot_unauthorized(client, bot, telegram):
|
||||||
response = client.get('/api/hoods/{0}/telegram/{1}'.format(telegram.hood.id, telegram.id))
|
response = client.get(
|
||||||
|
'/api/hoods/{0}/telegram/{1}'.format(telegram.hood.id, telegram.id)
|
||||||
|
)
|
||||||
assert response.status_code == status.HTTP_401_UNAUTHORIZED
|
assert response.status_code == status.HTTP_401_UNAUTHORIZED
|
||||||
|
|
|
@ -77,7 +77,9 @@ def test_twitter_create_bot(
|
||||||
)
|
)
|
||||||
|
|
||||||
# Twitter create endpoint
|
# Twitter create endpoint
|
||||||
response = client.post('/api/hoods/{0}/twitter/'.format(hood_id), headers=auth_header)
|
response = client.post(
|
||||||
|
'/api/hoods/{0}/twitter/'.format(hood_id), headers=auth_header
|
||||||
|
)
|
||||||
assert response.status_code == status.HTTP_201_CREATED
|
assert response.status_code == status.HTTP_201_CREATED
|
||||||
bot_id = response.json()['id']
|
bot_id = response.json()['id']
|
||||||
twitter = event_loop.run_until_complete(Twitter.objects.get(id=bot_id))
|
twitter = event_loop.run_until_complete(Twitter.objects.get(id=bot_id))
|
||||||
|
@ -139,7 +141,9 @@ def test_twitter_create_unauthorized(client, hood_id):
|
||||||
|
|
||||||
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('/api/hoods/{0}/twitter/'.format(hood_id), headers=auth_header)
|
response = client.post(
|
||||||
|
'/api/hoods/{0}/twitter/'.format(hood_id), headers=auth_header
|
||||||
|
)
|
||||||
assert response.status_code == status.HTTP_500_INTERNAL_SERVER_ERROR
|
assert response.status_code == status.HTTP_500_INTERNAL_SERVER_ERROR
|
||||||
|
|
||||||
# Invalid consumer keys
|
# Invalid consumer keys
|
||||||
|
@ -149,5 +153,7 @@ def test_twitter_create_wrong_consumer_keys(client, monkeypatch, auth_header, ho
|
||||||
{'consumer_key': 'consumer_key123', 'consumer_secret': 'consumer_secret123'},
|
{'consumer_key': 'consumer_key123', 'consumer_secret': 'consumer_secret123'},
|
||||||
)
|
)
|
||||||
|
|
||||||
response = client.post('/api/hoods/{0}/twitter/'.format(hood_id), headers=auth_header)
|
response = client.post(
|
||||||
|
'/api/hoods/{0}/twitter/'.format(hood_id), headers=auth_header
|
||||||
|
)
|
||||||
assert response.status_code == status.HTTP_500_INTERNAL_SERVER_ERROR
|
assert response.status_code == status.HTTP_500_INTERNAL_SERVER_ERROR
|
||||||
|
|
|
@ -12,7 +12,8 @@ from kibicara.platforms.twitter.model import Twitter
|
||||||
|
|
||||||
def test_twitter_delete_bot(client, event_loop, twitter, auth_header):
|
def test_twitter_delete_bot(client, event_loop, twitter, auth_header):
|
||||||
response = client.delete(
|
response = client.delete(
|
||||||
'/api/hoods/{0}/twitter/{1}'.format(twitter.hood.id, twitter.id), headers=auth_header
|
'/api/hoods/{0}/twitter/{1}'.format(twitter.hood.id, twitter.id),
|
||||||
|
headers=auth_header,
|
||||||
)
|
)
|
||||||
assert response.status_code == status.HTTP_204_NO_CONTENT
|
assert response.status_code == status.HTTP_204_NO_CONTENT
|
||||||
with raises(NoMatch):
|
with raises(NoMatch):
|
||||||
|
@ -24,12 +25,18 @@ def test_twitter_delete_bot_invalid_id(client, auth_header, hood_id):
|
||||||
assert response.status_code == status.HTTP_404_NOT_FOUND
|
assert response.status_code == status.HTTP_404_NOT_FOUND
|
||||||
response = client.delete('/api/hoods/wrong/twitter/123', headers=auth_header)
|
response = client.delete('/api/hoods/wrong/twitter/123', headers=auth_header)
|
||||||
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
|
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
|
||||||
response = client.delete('/api/hoods/{0}/twitter/7331'.format(hood_id), headers=auth_header)
|
response = client.delete(
|
||||||
|
'/api/hoods/{0}/twitter/7331'.format(hood_id), headers=auth_header
|
||||||
|
)
|
||||||
assert response.status_code == status.HTTP_404_NOT_FOUND
|
assert response.status_code == status.HTTP_404_NOT_FOUND
|
||||||
response = client.delete('/api/hoods/{0}/twitter/wrong'.format(hood_id), headers=auth_header)
|
response = client.delete(
|
||||||
|
'/api/hoods/{0}/twitter/wrong'.format(hood_id), headers=auth_header
|
||||||
|
)
|
||||||
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
|
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
|
||||||
|
|
||||||
|
|
||||||
def test_twitter_delete_bot_unauthorized(client, twitter):
|
def test_twitter_delete_bot_unauthorized(client, twitter):
|
||||||
response = client.delete('/api/hoods/{0}/twitter/{1}'.format(twitter.hood.id, twitter.id))
|
response = client.delete(
|
||||||
|
'/api/hoods/{0}/twitter/{1}'.format(twitter.hood.id, twitter.id)
|
||||||
|
)
|
||||||
assert response.status_code == status.HTTP_401_UNAUTHORIZED
|
assert response.status_code == status.HTTP_401_UNAUTHORIZED
|
||||||
|
|
|
@ -8,7 +8,8 @@ from fastapi import status
|
||||||
|
|
||||||
def test_twitter_get_bot(client, auth_header, event_loop, twitter):
|
def test_twitter_get_bot(client, auth_header, event_loop, twitter):
|
||||||
response = client.get(
|
response = client.get(
|
||||||
'/api/hoods/{0}/twitter/{1}'.format(twitter.hood.id, twitter.id), headers=auth_header
|
'/api/hoods/{0}/twitter/{1}'.format(twitter.hood.id, twitter.id),
|
||||||
|
headers=auth_header,
|
||||||
)
|
)
|
||||||
assert response.status_code == status.HTTP_200_OK
|
assert response.status_code == status.HTTP_200_OK
|
||||||
assert response.json()['id'] == twitter.id
|
assert response.json()['id'] == twitter.id
|
||||||
|
@ -21,12 +22,18 @@ def test_twitter_get_bot_invalid_id(client, auth_header, hood_id):
|
||||||
assert response.status_code == status.HTTP_404_NOT_FOUND
|
assert response.status_code == status.HTTP_404_NOT_FOUND
|
||||||
response = client.get('/api/hoods/wrong/twitter/123', headers=auth_header)
|
response = client.get('/api/hoods/wrong/twitter/123', headers=auth_header)
|
||||||
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
|
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
|
||||||
response = client.get('/api/hoods/{0}/twitter/7331'.format(hood_id), headers=auth_header)
|
response = client.get(
|
||||||
|
'/api/hoods/{0}/twitter/7331'.format(hood_id), headers=auth_header
|
||||||
|
)
|
||||||
assert response.status_code == status.HTTP_404_NOT_FOUND
|
assert response.status_code == status.HTTP_404_NOT_FOUND
|
||||||
response = client.get('/api/hoods/{0}/twitter/wrong'.format(hood_id), headers=auth_header)
|
response = client.get(
|
||||||
|
'/api/hoods/{0}/twitter/wrong'.format(hood_id), headers=auth_header
|
||||||
|
)
|
||||||
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
|
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
|
||||||
|
|
||||||
|
|
||||||
def test_twitter_get_bot_unauthorized(client, twitter):
|
def test_twitter_get_bot_unauthorized(client, twitter):
|
||||||
response = client.get('/api/hoods/{0}/twitter/{1}'.format(twitter.hood.id, twitter.id))
|
response = client.get(
|
||||||
|
'/api/hoods/{0}/twitter/{1}'.format(twitter.hood.id, twitter.id)
|
||||||
|
)
|
||||||
assert response.status_code == status.HTTP_401_UNAUTHORIZED
|
assert response.status_code == status.HTTP_401_UNAUTHORIZED
|
||||||
|
|
|
@ -25,7 +25,9 @@ def test_twitter_get_bots(client, auth_header, event_loop, hood_id):
|
||||||
access_token_secret='access_token_secret456',
|
access_token_secret='access_token_secret456',
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
response = client.get('/api/hoods/{0}/twitter'.format(twitter0.hood.id), headers=auth_header)
|
response = client.get(
|
||||||
|
'/api/hoods/{0}/twitter'.format(twitter0.hood.id), headers=auth_header
|
||||||
|
)
|
||||||
assert response.status_code == status.HTTP_200_OK
|
assert response.status_code == status.HTTP_200_OK
|
||||||
assert response.json()[0]['id'] == twitter0.id
|
assert response.json()[0]['id'] == twitter0.id
|
||||||
assert response.json()[0]['access_token'] == twitter0.access_token
|
assert response.json()[0]['access_token'] == twitter0.access_token
|
||||||
|
|
Loading…
Reference in a new issue