Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests for transport.Message #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import datetime
import unittest

from socker.tree import Tree
from socker.transport import Message


class TestTree(unittest.TestCase):
Expand Down Expand Up @@ -110,5 +112,34 @@ def test_not_matches(self):
self.assertNotIn(wildcard_path, matches)


class TestMessage(unittest.TestCase):

def test_from_string(self):
# This takes having a pipe in the json data into account. The pipe
# has a special purpose but in the context of the json data it should
# be consider a normal character with no purpose.
message = Message.from_string(
'my name|{"some-key": "some-value", "pipe": "|"}')
self.assertEqual(message.name, "my name")
self.assertEqual(message.data, {"some-key": "some-value", "pipe": "|"})

def test___str_(self):
# Test a message with where data is a dict
self.assertEqual(
str(Message('my name', {'data': 1})), 'my name|{"data": 1}')

# Test a message where data is a date
self.assertEqual(
str(Message('my name', datetime.date(2023, 6, 15))),
'my name|"2023-06-15"'
)

# Test a message where data is a datetime
self.assertEqual(
str(Message('my name', datetime.datetime(2023, 6, 15))),
'my name|"2023-06-15T00:00:00"'
)


if __name__ == '__main__':
unittest.main()