Commit ef19f30b authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Add unconnected client tests

Client instances are expected to raise RuntimeError when methods that
send commands to the server are called before the client is connected.
parent cb84175c
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -190,6 +190,16 @@ class SendMessageTests(unittest.TestCase):
			]
			assert await client.event("CTRL-EVENT-EXAMPLE")

	@anyio_mock.with_anyio()
	async def test_unconnected(self):
		"""
		Check that calling send_command() on an unconnected client raises RuntimeError
		"""
		client = base.BaseClient()

		with self.assertRaises(RuntimeError):
			await client.send_command("SOME_COMMAND")


class EventTests(unittest.TestCase):
	"""
@@ -287,3 +297,13 @@ class EventTests(unittest.TestCase):
				assert args is None

				assert await client.send_command("SOME_COMMAND", expect="FOO") is None

	@anyio_mock.with_anyio()
	async def test_unconnected(self):
		"""
		Check that calling event() on an unconnected client raises RuntimeError
		"""
		client = base.BaseClient()

		with self.assertRaises(RuntimeError):
			await client.event("some", "events")
+13 −0
Original line number Diff line number Diff line
@@ -139,3 +139,16 @@ class InterfaceMethodsTests(unittest.TestCase):
			args = client.sock.send.call_args_list
			self.assertTupleEqual(args[0][0], (b"INTERFACES",))
			assert args[1][0][0].startswith(b"INTERFACE_ADD enp1s0\t")

	@anyio_mock.with_anyio()
	async def test_unconnected(self):
		"""
		Check that calling add_interface() on an unconnected client raises RuntimeError

		This is similar to the identically-named test on the base class, but checks there
		are no issues related to the socket directory not being set.
		"""
		client = master.MasterClient()

		with self.assertRaises(RuntimeError):
			await client.add_interface("interface")