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) )