Moved dev/msgtest.py to test case in tests.msgobj

This commit is contained in:
Dmitri Bogomolov 2019-01-18 17:16:14 +02:00
parent 5ca6a73b73
commit 4cd90b152c
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
2 changed files with 32 additions and 0 deletions

View File

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

31
src/tests/msgobj.py Normal file
View File

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