def test_job_ok(self, mock_get_uri): mock_get_uri.return_value.status_code = 200 mock_get_uri.return_value.json.return_value = { "job": { "file": { "display": "test-pouzdro-na-iphone.gcode" } }, "progress": { "completion": 12, "printTimeLeft": 35, "printTime": 10 }, "state": "Printing", } printer = Octoprint("192.168.1.15", client=PrinterClientInfo(connected=True)) result = printer.job() self.assertEqual( result, { "name": "test-pouzdro-na-iphone.gcode", "completion": 12, "printTimeLeft": 35, "printTime": 10, }, )
def test_job_malformed_json(self, mock_get_uri): mock_get_uri.return_value.status_code = 200 mock_get_uri.return_value.json.side_effect = json.decoder.JSONDecodeError( "msg", "aa", 123) printer = Octoprint("192.168.1.15", client=PrinterClientInfo(connected=True)) result = printer.job() self.assertEqual(result, {})
def test_job_offline_printer(self, mock_get_uri): mock_get_uri.return_value.status_code = 200 mock_get_uri.return_value.json.return_value = { "job": { "file": { "display": "test-pouzdro-na-iphone.gcode" } }, "progress": { "completion": 100, "printTimeLeft": 0, "printTime": 10 }, "state": "Offline (Error: Too many consecutive timeouts, printer still connected and alive?)", } printer = Octoprint("192.168.1.15", client=PrinterClientInfo(connected=True)) result = printer.job() self.assertEqual(result, {})
def test_job_inactive_printer(self, mock_get_uri): printer = Octoprint("192.168.1.15") self.assertEqual(mock_get_uri.call_count, 0) result = printer.job() self.assertEqual(result, {})
def test_job_no_response(self, mock_get_uri): printer = Octoprint("192.168.1.15", client=PrinterClientInfo(connected=True)) result = printer.job() self.assertEqual(result, {})
def test_job_disconnected(self, mock_get_uri): printer = Octoprint("192.168.1.15", client=PrinterClientInfo(connected=False)) printer.job() self.assertEqual(mock_get_uri.call_count, 0)
def test_job_disconnect(self, mock_get_uri): printer = Octoprint("192.168.1.15", client=PrinterClientInfo(connected=True)) self.assertTrue(printer.client.connected) printer.job() self.assertFalse(printer.client.connected)