1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-13 21:52:18 +00:00
supysonic/tests/api/test_chat.py

52 lines
1.6 KiB
Python
Raw Normal View History

2017-11-03 22:15:48 +00:00
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
# Copyright (C) 2017 Alban 'spl0k' Féron
#
# Distributed under terms of the GNU AGPLv3 license.
import unittest
import time
from .apitestbase import ApiTestBase
2019-06-29 15:25:44 +00:00
2017-11-03 22:15:48 +00:00
class ChatTestCase(ApiTestBase):
def test_add_message(self):
2019-06-29 15:25:44 +00:00
self._make_request("addChatMessage", error=10)
rv, child = self._make_request("getChatMessages", tag="chatMessages")
2017-11-03 22:15:48 +00:00
self.assertEqual(len(child), 0)
2019-06-29 15:25:44 +00:00
self._make_request(
"addChatMessage", {"message": "Heres a message"}, skip_post=True
)
rv, child = self._make_request("getChatMessages", tag="chatMessages")
2017-11-03 22:15:48 +00:00
self.assertEqual(len(child), 1)
2019-06-29 15:25:44 +00:00
self.assertEqual(child[0].get("username"), "alice")
self.assertEqual(child[0].get("message"), "Heres a message")
2017-11-03 22:15:48 +00:00
def test_get_messages(self):
2019-06-29 15:25:44 +00:00
self._make_request("addChatMessage", {"message": "Hello"}, skip_post=True)
2017-11-03 22:15:48 +00:00
time.sleep(1)
2019-06-29 15:25:44 +00:00
self._make_request(
"addChatMessage", {"message": "Is someone there?"}, skip_post=True
)
2017-11-03 22:15:48 +00:00
2019-06-29 15:25:44 +00:00
rv, child = self._make_request("getChatMessages", tag="chatMessages")
2017-11-03 22:15:48 +00:00
self.assertEqual(len(child), 2)
2019-06-29 15:25:44 +00:00
rv, child = self._make_request(
"getChatMessages",
{"since": int(time.time()) * 1000 - 500},
tag="chatMessages",
)
2017-11-03 22:15:48 +00:00
self.assertEqual(len(child), 1)
2019-06-29 15:25:44 +00:00
self.assertEqual(child[0].get("message"), "Is someone there?")
2017-11-03 22:15:48 +00:00
2019-06-29 15:25:44 +00:00
self._make_request("getChatMessages", {"since": "invalid timestamp"}, error=0)
2017-11-03 22:15:48 +00:00
2019-06-29 15:25:44 +00:00
if __name__ == "__main__":
unittest.main()