def test_import_file(assets, new_document): """Import a file from the local file system. Returns the URL of the resulting element if translated.""" client = Client() cube_path = assets / 'Cube.x_t' file = open(cube_path, 'rb').read() r = client.blob_elements_api.upload_file_create_element( new_document.did, new_document.wvmid, _preload_content=False) # file=file, translate=True, encodedFilename=cube_path.name, media_type="application/stl", translation_id = get_field(r, 'translationId') print("The translationId is: {}.".format(translation_id)) state = 'ACTIVE' while state == 'ACTIVE': time.sleep(2) r = client.translation_api.get_translation(translation_id, _preload_content=False) state = get_field(r, "requestState") element_id = get_field(r, 'resultElementIds')[0] # Make the actual download when the translation is done, otherwise report the error if state == "DONE": print( "Translated document available at {host}/documents/{did}/w/{wid}/e/{eid}" .format(host=client.configuration.host, did=get_field(r, 'documentId'), wid=get_field(r, 'workspaceId'), eid=element_id)) else: print("An error ocurred on the server! Here is the response: \n") return element_id
def do_POST(self): content_length = int(self.headers['Content-Length']) body = self.rfile.read(content_length) unquoted_s = "" if six.PY2: import urllib unquoted_s = urllib.unquote(body) elif six.PY3: unquoted_s = body.decode('utf-8') data = json.loads(unquoted_s) from onshape_client.oas.models import BTDocumentParams bt_document_params = BTDocumentParams(name=data["doc_name"]) new_doc_response = Client.get_client().documents_api.create11( bt_document_params, _preload_content=False) did = get_field(new_doc_response, "id") wid = get_field(new_doc_response, "defaultWorkspace")["id"] # Use a fake eid because it isn't used later. eid = "00000000000000" self.onshape_element = OnshapeElement.create_from_ids( did, "w", wid, eid) if "import_items" in data: for import_item in data["import_items"]: self.import_item(import_item) self.send_response(200) self.send_header('Content-type', 'application/json') self.send_header('Access-Control-Allow-Origin', '*') self.end_headers() content = { "document_href": self.onshape_element.get_url(url_type="document") } self.wfile.write(sendable(json.dumps(content)))
def test_assembly_definition(client, element): """Simple api call without serialization.""" res = client.assemblies_api.get_assembly_definition( element.did, 'v', element.wvmid, element.eid, include_mate_features=True, include_mate_connectors=True, _preload_content=False) parts = get_field(res, "parts") assert parts[0]["mateConnectors"]
def test_assembly_definition(client, configurable_cubes_assemblies): cube = configurable_cubes_assemblies[2] did = cube.did vid = cube.wvmid eid = cube.eid assert client.assemblies_api.get_assembly_definition( did, 'v', vid, eid, _preload_content=False) # issue #4 res = client.assemblies_api.get_assembly_definition( did, 'v', vid, eid, include_mate_features=True, include_mate_connectors=True, _preload_content=False) parts = get_field(res, "parts") assert parts[0]["mateConnectors"]