From c11186e7bed95bf52381251f12530da6cfddc6a8 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Tue, 27 Jul 2021 00:01:49 +0300 Subject: [PATCH] Move test_network_group into the TestProtocol --- src/tests/test_networkgroup.py | 43 ---------------------------------- src/tests/test_protocol.py | 26 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 43 deletions(-) delete mode 100644 src/tests/test_networkgroup.py diff --git a/src/tests/test_networkgroup.py b/src/tests/test_networkgroup.py deleted file mode 100644 index 79163402..00000000 --- a/src/tests/test_networkgroup.py +++ /dev/null @@ -1,43 +0,0 @@ -""" -Test for network group -""" -import unittest - -from .common import skip_python3 - -skip_python3() - - -class TestNetworkGroup(unittest.TestCase): - """ - Test case for network group - """ - def test_network_group(self): - """Test various types of network groups""" - from pybitmessage.protocol import network_group - - test_ip = '1.2.3.4' - self.assertEqual('\x01\x02', network_group(test_ip)) - - test_ip = '127.0.0.1' - self.assertEqual('IPv4', network_group(test_ip)) - - test_ip = '0102:0304:0506:0708:090A:0B0C:0D0E:0F10' - self.assertEqual( - '\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C', - network_group(test_ip)) - - test_ip = 'bootstrap8444.bitmessage.org' - self.assertEqual( - 'bootstrap8444.bitmessage.org', - network_group(test_ip)) - - test_ip = 'quzwelsuziwqgpt2.onion' - self.assertEqual( - test_ip, - network_group(test_ip)) - - test_ip = None - self.assertEqual( - None, - network_group(test_ip)) diff --git a/src/tests/test_protocol.py b/src/tests/test_protocol.py index 7812d4ec..d612b934 100644 --- a/src/tests/test_protocol.py +++ b/src/tests/test_protocol.py @@ -70,3 +70,29 @@ class TestProtocol(unittest.TestCase): self.assertTrue( not protocol.checkSocksIP('127.0.0.1') or state.socksIP) + + def test_network_group(self): + """Test various types of network groups""" + + test_ip = '1.2.3.4' + self.assertEqual(b'\x01\x02', protocol.network_group(test_ip)) + + test_ip = '127.0.0.1' + self.assertEqual('IPv4', protocol.network_group(test_ip)) + + self.assertEqual( + protocol.network_group('8.8.8.8'), + protocol.network_group('8.8.4.4')) + self.assertNotEqual( + protocol.network_group('1.1.1.1'), + protocol.network_group('8.8.8.8')) + + test_ip = '0102:0304:0506:0708:090A:0B0C:0D0E:0F10' + self.assertEqual( + b'\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C', + protocol.network_group(test_ip)) + + for test_ip in ( + 'bootstrap8444.bitmessage.org', 'quzwelsuziwqgpt2.onion', None): + self.assertEqual( + test_ip, protocol.network_group(test_ip))