From 0bdaea4591fae05a1a93b6ddcf066f92e8f224f4 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Sat, 25 Dec 2021 14:09:59 +0100 Subject: Move WS code outside the main into swiftstory.interface.ws.py Also, the GameManager object is not created globally anymore when importing the module. Signed-off-by: Olivier Gayot --- tests/test_swiftstory.py | 56 ------------------------------------------ tests/test_ws_interface.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 56 deletions(-) delete mode 100644 tests/test_swiftstory.py create mode 100644 tests/test_ws_interface.py (limited to 'tests') diff --git a/tests/test_swiftstory.py b/tests/test_swiftstory.py deleted file mode 100644 index aac1865..0000000 --- a/tests/test_swiftstory.py +++ /dev/null @@ -1,56 +0,0 @@ -import unittest - -import swiftstory.__main__ as SwiftStory -from swiftstory.status import error - - -class TestSwiftStory(unittest.TestCase): - def test_receive_invalid_json(self): - self.assertEqual( - error("badly formatted json"), - SwiftStory.message_received_handler(client=None, message="{invalid_json}") - ) - - def test_receive_json_array(self): - self.assertEqual( - error("invalid command"), - SwiftStory.message_received_handler(client=None, message='[]') - ) - - def test_receive_json_number(self): - self.assertEqual( - error("invalid command"), - SwiftStory.message_received_handler(client=None, message='2.3') - ) - - def test_receive_json_null(self): - self.assertEqual( - error("invalid command"), - SwiftStory.message_received_handler(client=None, message='null') - ) - - def test_receive_unknown_command(self): - self.assertEqual( - error("invalid command"), - SwiftStory.message_received_handler(client=None, message='{"op": "unknown"}') - ) - - def test_receive_without_command(self): - self.assertEqual( - error("invalid command"), - SwiftStory.message_received_handler(client=None, message='{}') - ) - - def test_play_card_not_specified(self): - payload = '{"op": "play_white_card"}' - self.assertEqual( - error("field `card_id' is required"), - SwiftStory.message_received_handler(client=None, message=payload) - ) - - def test_join_game_not_specified(self): - payload = '{"op": "join_game"}' - self.assertEqual( - error("field `game_name' is required"), - SwiftStory.message_received_handler(client=None, message=payload) - ) diff --git a/tests/test_ws_interface.py b/tests/test_ws_interface.py new file mode 100644 index 0000000..6776334 --- /dev/null +++ b/tests/test_ws_interface.py @@ -0,0 +1,61 @@ +import unittest + +from swiftstory.interface.ws import WebsocketsInterface +from swiftstory.status import error + + +class TestWebsocketsInterface(unittest.TestCase): + def setUp(self): + # XXX Passing None as the GameManager. Only OK if we don't try to join + # a game. + self.interface = WebsocketsInterface(None) + + def test_receive_invalid_json(self): + self.assertEqual( + error("badly formatted json"), + self.interface.message_received_handler(client=None, message="{invalid_json}") + ) + + def test_receive_json_array(self): + self.assertEqual( + error("invalid command"), + self.interface.message_received_handler(client=None, message='[]') + ) + + def test_receive_json_number(self): + self.assertEqual( + error("invalid command"), + self.interface.message_received_handler(client=None, message='2.3') + ) + + def test_receive_json_null(self): + self.assertEqual( + error("invalid command"), + self.interface.message_received_handler(client=None, message='null') + ) + + def test_receive_unknown_command(self): + self.assertEqual( + error("invalid command"), + self.interface.message_received_handler(client=None, message='{"op": "unknown"}') + ) + + def test_receive_without_command(self): + self.assertEqual( + error("invalid command"), + self.interface.message_received_handler(client=None, message='{}') + ) + + def test_play_card_not_specified(self): + payload = '{"op": "play_white_card"}' + self.assertEqual( + error("field `card_id' is required"), + self.interface.message_received_handler(client=None, message=payload) + ) + + def test_join_game_not_specified(self): + payload = '{"op": "join_game"}' + self.assertEqual( + error("field `game_name' is required"), + self.interface.message_received_handler(client=None, message=payload) + ) -- cgit v1.2.3