Exemple #1
0
 def test05_check_half_of_multiple_messages(self):
     # new instance of the chat plugin to test
     chat_instance = Plugin(self.service, [])
     # create a message event request
     player_ids = [200, 220, 999]
     sentences = [
         "This is my sentence!", "Yeah another test hello.",
         "Ping ping poing pong."
     ]
     when = []
     for i in range(3):
         sleep(0.1)
         when.append(int(runtime.seconds() * 1000))
         request = Request(action=['message'],
                           player_id=[player_ids[i]],
                           sentence=[sentences[i]])
         # run the request
         result = yield chat_instance.preprocess(True, request)
     # check to make sure no message is returned if we ask for now or later
     # we check right back to one second ago to make sure all recently added messages are caught
     state, players_id_list = yield chat_instance.state(
         {"modified": [when[-1] - 150]})
     # this time because of the 100ms delay between messages, and only checking to 150ms ago
     # we should only get the last two messages
     self.assertEquals(len(state['messages']), 2)
     for i in range(2):
         self.assertEquals(state['messages'][i]['player_id'],
                           player_ids[i + 1])
         self.assertEquals(state['messages'][i]['sentence'],
                           sentences[i + 1])
     self.assertEquals(players_id_list, player_ids[-2:])
Exemple #2
0
 def test11_link_url(self):
     # new instance of the chat plugin to test
     chat_instance = Plugin(self.service, [])
     # create a message event request
     player_id = 201
     url_sentence = 'For searching the web I use google.com, it\'s great!'
     now = int(runtime.seconds() * 1000)
     request = Request(action=['message'], player_id=[player_id], sentence=[url_sentence])
     # run the request
     result = yield chat_instance.preprocess(True, request)
     # check to make sure our message is returned with a link for the url
     state, players_id_list = yield chat_instance.state({"modified": [now - 1]})
     self.assertEquals(state['messages'][0]['player_id'], player_id)
     self.assertEquals(state['messages'][0]['sentence'], 'For searching the web I use <a target="_blank" href="http://google.com">google.com</a>, it\'s great!')
Exemple #3
0
 def test10_escape_html(self):
     # new instance of the chat plugin to test
     chat_instance = Plugin(self.service, [])
     # create a message event request
     player_id = 201
     naughty_sentence = '<script>alert("haha!")</script>'
     now = int(runtime.seconds() * 1000)
     request = Request(action=['message'], player_id=[player_id], sentence=[naughty_sentence])
     # run the request
     result = yield chat_instance.preprocess(True, request)
     # check to make sure our naughty message is returned properly escaped
     state, players_id_list = yield chat_instance.state({"modified": [now - 1]})
     self.assertEquals(state['messages'][0]['player_id'], player_id)
     self.assertEquals(state['messages'][0]['sentence'], '&lt;script&gt;alert("haha!")&lt;/script&gt;')
Exemple #4
0
 def test02_check_added_message_after_now(self):
     # new instance of the chat plugin to test
     chat_instance = Plugin(self.service, [])
     # create a message event request
     player_id = 200
     sentence = "This is my sentence!"
     now = int(runtime.seconds() * 1000)
     request = Request(action=['message'], player_id=[player_id], sentence=[sentence])
     # run the request
     result = yield chat_instance.preprocess(True, request)
     # check to make sure no message is returned if we ask for now or later
     state, players_id_list = yield chat_instance.state({"modified": [now + 1]})
     self.assertTrue(state.has_key('messages'))
     self.assertEquals(len(state['messages']), 0)
     self.assertEquals(players_id_list, [])
Exemple #5
0
 def test10_escape_html(self):
     # new instance of the chat plugin to test
     chat_instance = Plugin(self.service, [])
     # create a message event request
     player_id = 201
     naughty_sentence = '<script>alert("haha!")</script>'
     now = int(runtime.seconds() * 1000)
     request = Request(action=['message'],
                       player_id=[player_id],
                       sentence=[naughty_sentence])
     # run the request
     result = yield chat_instance.preprocess(True, request)
     # check to make sure our naughty message is returned properly escaped
     state, players_id_list = yield chat_instance.state(
         {"modified": [now - 1]})
     self.assertEquals(state['messages'][0]['player_id'], player_id)
     self.assertEquals(state['messages'][0]['sentence'],
                       '&lt;script&gt;alert("haha!")&lt;/script&gt;')
Exemple #6
0
 def test02_check_added_message_after_now(self):
     # new instance of the chat plugin to test
     chat_instance = Plugin(self.service, [])
     # create a message event request
     player_id = 200
     sentence = "This is my sentence!"
     now = int(runtime.seconds() * 1000)
     request = Request(action=['message'],
                       player_id=[player_id],
                       sentence=[sentence])
     # run the request
     result = yield chat_instance.preprocess(True, request)
     # check to make sure no message is returned if we ask for now or later
     state, players_id_list = yield chat_instance.state(
         {"modified": [now + 1]})
     self.assertTrue(state.has_key('messages'))
     self.assertEquals(len(state['messages']), 0)
     self.assertEquals(players_id_list, [])
Exemple #7
0
 def test11_link_url(self):
     # new instance of the chat plugin to test
     chat_instance = Plugin(self.service, [])
     # create a message event request
     player_id = 201
     url_sentence = 'For searching the web I use google.com, it\'s great!'
     now = int(runtime.seconds() * 1000)
     request = Request(action=['message'],
                       player_id=[player_id],
                       sentence=[url_sentence])
     # run the request
     result = yield chat_instance.preprocess(True, request)
     # check to make sure our message is returned with a link for the url
     state, players_id_list = yield chat_instance.state(
         {"modified": [now - 1]})
     self.assertEquals(state['messages'][0]['player_id'], player_id)
     self.assertEquals(
         state['messages'][0]['sentence'],
         'For searching the web I use <a target="_blank" href="http://google.com">google.com</a>, it\'s great!'
     )
Exemple #8
0
 def test04_check_multiple_messages(self):
     # new instance of the chat plugin to test
     chat_instance = Plugin(self.service, [])
     # create a message event request
     player_ids = [200, 220, 999]
     sentences = ["This is my sentence!", "Yeah another test hello.", "Ping ping poing pong."]
     when = []
     for i in range(3):
         when.append(int(runtime.seconds() * 1000))
         request = Request(action=['message'], player_id=[player_ids[i]], sentence=[sentences[i]])
         # run the request
         result = yield chat_instance.preprocess(True, request)
     # check to make sure no message is returned if we ask for now or later
     # we check right back to one second ago to make sure all recently added messages are caught
     state, players_id_list = yield chat_instance.state({"modified": [when[-1] - 1000]})
     self.assertEquals(len(state['messages']), 3)
     for i in range(3):
         self.assertEquals(state['messages'][i]['player_id'], player_ids[i])
         self.assertEquals(state['messages'][i]['sentence'], sentences[i])
     self.assertEquals(players_id_list, player_ids)