Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_get_most_recent_message(self):
room_id = '40999743'
data = gitter.get_most_recent_message('fake_access_token', room_id)
self.assertIn('text', data)
self.assertIn('id', data)
self.assertIn('unread', data)
def test_response_status_code_not_ok(self):
response = MockResponse(404, {})
with self.assertRaises(gitter.HTTPStatusException):
gitter._validate_status_code(response)
def test_contains_mention(self):
contains = gitter._contains_mention([{'screenName': 'chatterbot'}], 'chatterbot')
self.assertTrue(contains)
def test_mark_messages_as_read(self):
room_id = '40999743'
user_id = '9893893'
data = gitter.mark_messages_as_read('fake_access_token', user_id, room_id, [1, 2, 3])
self.assertIn('id', data)
def test_join_room(self):
data = gitter.join_room('fake_access_token', 'room_name')
self.assertIn('id', data)
def test_should_respond_unread(self):
should = gitter.should_respond({'unread': True}, 'username', False)
self.assertTrue(should)
def setUp(self):
super().setUp()
import requests
requests.get = Mock(side_effect=mock_get_response)
requests.post = Mock(side_effect=mock_post_response)
gitter.requests = requests
def test_get_user_data(self):
data = gitter.get_user_data('fake_access_token')
self.assertIn('id', data[0])
def process_input(self, statement):
new_message = False
while not new_message:
data = gitter.get_most_recent_message(self.gitter_api_token, self.room_id)
if gitter.should_respond(data, self.username, self.only_respond_to_mentions):
gitter.mark_messages_as_read(
self.gitter_api_token,
self.user_id,
self.room_id,
[data['id']]
)
new_message = True
sleep(self.sleep_time)
text = gitter.remove_mentions(data['text'])
return Statement(text=text)
def __init__(self, chatbot, **kwargs):
super().__init__(chatbot, **kwargs)
self.gitter_room = kwargs.get('gitter_room')
self.gitter_api_token = kwargs.get('gitter_api_token')
# Join the Gitter room
room_data = gitter.join_room(self.gitter_api_token, self.gitter_room)
self.room_id = room_data.get('id')