From 4cd90b152c89f5d5e57e11e31b4c499838aa1b5d Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Fri, 18 Jan 2019 17:16:14 +0200 Subject: [PATCH] Moved dev/msgtest.py to test case in tests.msgobj --- src/tests/core.py | 1 + src/tests/msgobj.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/tests/msgobj.py diff --git a/src/tests/core.py b/src/tests/core.py index 2085c0ef..3217a92d 100644 --- a/src/tests/core.py +++ b/src/tests/core.py @@ -415,6 +415,7 @@ def run(): loader = unittest.defaultTestLoader loader.sortTestMethodsUsing = None suite = loader.loadTestsFromTestCase(TestCore) + suite.addTests(loader.loadTestsFromName('tests.msgobj')) try: import bitmessageqt.tests from xvfbwrapper import Xvfb diff --git a/src/tests/msgobj.py b/src/tests/msgobj.py new file mode 100644 index 00000000..7e535564 --- /dev/null +++ b/src/tests/msgobj.py @@ -0,0 +1,31 @@ +"""Tests for messagetypes module""" + +import unittest + +import messagetypes + + +class TestMessagetypes(unittest.TestCase): + """A test case for messagetypes""" + _valid_msgdict = {"": "message", "subject": "subject", "body": "body"} + _invalid_msgdict = {"": "vote", "msgid": "msgid"} + + def _test_msgObj(self, data): + """Construct and process msg from dict""" + msgObj = messagetypes.constructObject(data) + if msgObj is None: + self.fail("Failed to construct msg object") + # Hope ERROR will be sufficient + msgObj.process() + + def test_msgType(self): + """No empty string in dict""" + data = {"fsck": 1} + with self.assertRaises(KeyError): + data[""] + + def test_msgObj(self): + """Test valid and invalid message dicts""" + self._test_msgObj(self._valid_msgdict) + with self.assertRaises(AssertionError): + self._test_msgObj(self._invalid_msgdict)