def test_connected_printer(self, mock_get_uri): class Response: def __init__(self, status_code, contents): self.status_code = status_code self.contents = contents def json(self): return {"text": "something"} def mock_call(uri, **kwargs): return Response(200, "") mock_get_uri.side_effect = mock_call printer = Octoprint("192.168.1.15") self.assertFalse(printer.client.connected) self.assertTrue(printer.is_alive()) self.assertTrue(printer.client.connected) self.assertEqual(mock_get_uri.call_count, 2)
def test_disconnected_printer(self, mock_get_uri): printer = Octoprint("192.168.1.15") self.assertFalse(printer.client.connected) self.assertFalse(printer.is_alive()) self.assertFalse(printer.client.connected) self.assertEqual(mock_get_uri.call_count, 1)