diff --git a/tests/test_config.py b/tests/test_config.py index 6747d80..3888866 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -8,15 +8,19 @@ from unittest import TestCase from rcon.config import Config +def random_passwd() -> str: + """Generates a random password containing all printable characters.""" + + chars = list(printable) + shuffle(chars) + return ''.join(chars) + class TestConfig(TestCase): """Test the named tuple Config.""" def setUp(self): """Sets up test and target data.""" - chars = list(printable) - shuffle(chars) - self.passwd = ''.join(chars) self.hosts = [ 'subsubdomain.subdomain.example.com', 'locahost', @@ -25,16 +29,17 @@ class TestConfig(TestCase): self.ports = range(65_536) @property - def sockets(self) -> Iterator[Tuple[str, int]]: + def _sockets(self) -> Iterator[Tuple[str, int]]: """Yields (host, port) tuples.""" return product(self.hosts, self.ports) def _test_from_string_with_password(self, host, port): """Tests the Config.from_string() method with a password.""" - config = Config.from_string(f'{self.passwd}@{host}:{port}') + passwd = random_passwd() + config = Config.from_string(f'{passwd}@{host}:{port}') self.assertEqual(config.host, host) self.assertEqual(config.port, port) - self.assertEqual(config.passwd, self.passwd) + self.assertEqual(config.passwd, passwd) def _test_from_string_without_password(self, host, port): """Tests the Config.from_string() method without a password.""" @@ -45,6 +50,6 @@ class TestConfig(TestCase): def test_from_string(self): """Tests the Config.from_string() method.""" - for host, port in self.sockets: + for host, port in self._sockets: self._test_from_string_with_password(host, port) self._test_from_string_without_password(host, port)