def test_status_unreachable(self, mock_get_uri): printer = Octoprint("192.168.1.15", client=PrinterClientInfo(connected=True)) result = printer.status() self.assertEqual(result, { "state": "Printer is not responding", "temperature": {} })
def test_status_conflict(self, mock_get_uri): mock_get_uri.return_value.status_code = 409 printer = Octoprint("192.168.1.15", client=PrinterClientInfo(connected=True)) result = printer.status() self.assertEqual( result, { "state": "Printer is not connected to Octoprint", "temperature": {} }, )
def test_status_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.status() self.assertEqual( result, { "state": "Printer is responding with invalid data", "temperature": {} }, )
def test_status_ok(self, mock_get_uri): mock_get_uri.return_value.status_code = 200 mock_get_uri.return_value.json.return_value = { "state": { "text": "Printing" }, "temperature": { "bed": { "actual": 49.8, "offset": 0, "target": 50.0 }, "tool0": { "actual": 240.4, "offset": 0, "target": 240.0 }, }, } printer = Octoprint("192.168.1.15", client=PrinterClientInfo(connected=True)) result = printer.status() self.assertEqual( result, { "state": "Printing", "temperature": { "bed": { "actual": 49.8, "offset": 0, "target": 50.0 }, "tool0": { "actual": 240.4, "offset": 0, "target": 240.0 }, }, }, )
def test_status_disconnected(self, mock_get_uri): printer = Octoprint("192.168.1.15", client=PrinterClientInfo(connected=False)) printer.status() self.assertEqual(mock_get_uri.call_count, 0)