def test_upload_job_printing(self, mock_post_uri, mock_get_uri): mock_get_uri.return_value.status_code = 200 mock_get_uri.return_value.json.return_value = { "state": { "text": "Printing" }, "temperature": {}, } with self.assertRaises(PrinterDriverException) as context: printer = Octoprint("192.168.1.15", client=PrinterClientInfo(connected=True)) printer.upload_and_start_job(self.file_mock.name) self.assertTrue("Printer is printing" in str(context.exception))
def test_upload_job_path_ok(self, mock_post_uri, mock_get_uri): mock_get_uri.return_value.status_code = 200 mock_get_uri.return_value.json.return_value = { "state": { "text": "Operational" }, "temperature": {}, } mock_post_uri.return_value.status_code = 201 mock_post_uri.return_value.json.return_value = { "files": { "local": { "name": "20mm-umlaut-box", "origin": "local", "refs": { "resource": "http://example.com/api/files/local/whistle_v2.gcode", "download": "http://example.com/downloads/files/local/whistle_v2.gcode", }, } }, "done": True, } printer = Octoprint("192.168.1.15", client=PrinterClientInfo(connected=True)) result = printer.upload_and_start_job(self.file_mock.name, path="sub/path/on/disk") self.assertTrue(result) args, kwargs = mock_post_uri.call_args self.assertEqual(kwargs["data"], { "path": "karmen/sub/path/on/disk", "print": True }) self.assertEqual(kwargs["files"]["file"].name, self.file_mock.name)
def test_upload_job_no_response(self, mock_post_uri, mock_get_uri): mock_get_uri.return_value.status_code = 200 mock_get_uri.return_value.json.return_value = { "state": { "text": "Operational" }, "temperature": {}, } printer = Octoprint("192.168.1.15", client=PrinterClientInfo(connected=True)) result = printer.upload_and_start_job(self.file_mock.name) self.assertFalse(result)
def test_upload_job_inactive_printer(self, mock_post_uri, mock_get_uri): printer = Octoprint("192.168.1.15") self.assertEqual(mock_post_uri.call_count, 0) result = printer.upload_and_start_job(self.file_mock.name) self.assertFalse(result)