def test_invalid_send(): client = SpeckleClient() client.account = Account(token="fake_token") transport = ServerTransport("3073b96e86", client) with pytest.raises(SpeckleException): operations.send(Base(), [transport])
def test_commit_create(self, client, stream, mesh, commit): transport = ServerTransport(client=client, stream_id=stream.id) mesh.id = operations.send(mesh, transports=[transport]) commit.id = client.commit.create( stream_id=stream.id, object_id=mesh.id, message=commit.message ) assert isinstance(commit.id, str)
def test_send_and_receive(self, client, sample_stream, mesh): transport = ServerTransport(client=client, stream_id=sample_stream.id) hash = operations.send(mesh, transports=[transport]) # use a fresh memory transport to force receiving from remote received = operations.receive( hash, remote_transport=transport, local_transport=MemoryTransport() ) assert isinstance(received, FakeMesh) assert received.vertices == mesh.vertices assert isinstance(received.origin, Point) assert received.origin.value == mesh.origin.value # not comparing hashes as order is not guaranteed back from server mesh.id = hash # populate with decomposed id for use in proceeding tests
def import_stl(): file_path, user_id, stream_id, branch_name, commit_message = sys.argv[1:] print(f'ImportSTL argv[1:]: {sys.argv[1:]}') # Parse input stl_mesh = stl.mesh.Mesh.from_file(file_path) print( f'Parsed mesh with {stl_mesh.points.shape[0]} faces ({stl_mesh.points.shape[0] * 3} vertices)' ) # Construct speckle obj vertices = stl_mesh.points.flatten().tolist() faces = [] for i in range(stl_mesh.points.shape[0]): faces.extend([0, 3 * i, 3 * i + 1, 3 * i + 2]) speckle_mesh = Mesh(vertices=vertices, faces=faces, colors=[], textureCoordinates=[]) print('Constructed Speckle Mesh object') # Commit client = SpeckleClient(host=os.getenv('SPECKLE_SERVER_URL', 'localhost:3000'), use_ssl=False) client.authenticate(os.environ['USER_TOKEN']) if not client.branch.get(stream_id, branch_name): client.branch.create( stream_id, branch_name, 'File upload branch' if branch_name == 'uploads' else '') transport = ServerTransport(client=client, stream_id=stream_id) id = operations.send(base=speckle_mesh, transports=[transport]) commit_id = client.commit.create(stream_id=stream_id, object_id=id, branch_name=(branch_name or DEFAULT_BRANCH), message=(commit_message or 'STL file upload'), source_application='STL') return commit_id
def test_branch_get(self, client, mesh, stream, branch): transport = ServerTransport(client=client, stream_id=stream.id) mesh.id = operations.send(mesh, transports=[transport]) client.commit.create( stream_id=stream.id, branch_name=branch.name, object_id=mesh.id, message="a commit for testing branch get", ) fetched_branch = client.branch.get(stream_id=stream.id, name=branch.name) assert isinstance(fetched_branch, Branch) assert fetched_branch.name == branch.name assert fetched_branch.description == branch.description assert isinstance(fetched_branch.commits.items, list) assert isinstance(fetched_branch.commits.items[0], Commit)
def processItem(item): client, stream, branch, description, message, key, data, run = item if not run: return None # create a base object to hold data base = Base() base[key] = data transport = ServerTransport(stream.id, client) # and send the data to the server and get back the hash of the object obj_id = operations.send(base, [transport]) # now create a commit on that branch with your updated data! commit_id = client.commit.create( stream.id, obj_id, "gbxml", message=message, ) print("COMMIT ID", commit_id) for commit in branch.commits.items: print(" VS. COMMIT.ID", commit.id) if commit.id == commit_id: return commit return None
def processItem(item): client, stream, branch, description, message, key, blender_object, openURL, run = item if not run: return None # create a base object to hold data #base = Base() #base[key] = obj transport = ServerTransport(stream.id, client) # and send the data to the server and get back the hash of the object print("Blender Object:", blender_object) base = convert_to_speckle(blender_object, 1.0, desgraph=None) obj_id = operations.send(base[0], [transport]) # now create a commit on that branch with your updated data! commit_id = client.commit.create( stream.id, obj_id, branch.name, message=message, ) web_address = client.url + "/streams/" + stream.id + "/commits/" + commit_id if openURL: webbrowser.open(web_address) return web_address
def test_receive_local(self, client, mesh): hash = operations.send(mesh) # defaults to SQLiteTransport received = operations.receive(hash) assert isinstance(received, Base) assert mesh.get_id() == received.get_id()
def import_obj(): file_path, user_id, stream_id, branch_name, commit_message = sys.argv[1:] print(f'ImportOBJ argv[1:]: {sys.argv[1:]}') # Parse input obj = ObjFile(file_path) print( f'Parsed obj with {len(obj.faces)} faces ({len(obj.vertices) * 3} vertices)' ) speckle_root = Base() speckle_root['@objects'] = [] for objname in obj.objects: print(f' Converting {objname}...') speckle_obj = Base() speckle_obj.name = objname speckle_obj['@displayValue'] = [] speckle_root['@objects'].append(speckle_obj) for obj_mesh in obj.objects[objname]: speckle_vertices = [ coord for point in obj_mesh['vertices'] for coord in point ] speckle_faces = [] for obj_face in obj_mesh['faces']: if len(obj_face) == 3: speckle_faces.append(0) elif len(obj_face) == 4: speckle_faces.append(1) else: speckle_faces.append(len(obj_face)) speckle_faces.extend(obj_face) has_vertex_colors = False for vc in obj_mesh['vertex_colors']: if vc is not None: has_vertex_colors = True colors = [] if has_vertex_colors: for vc in obj_mesh['vertex_colors']: if vc is None: r, g, b = (1.0, 1.0, 1.0) else: r, g, b = vc argb = (1.0, r, g, b) color = int.from_bytes([int(val * 255) for val in argb], byteorder="big", signed=True) colors.append(color) speckle_mesh = Mesh(vertices=speckle_vertices, faces=speckle_faces, colors=colors, textureCoordinates=[]) obj_material = obj_mesh['material'] if obj_material: speckle_mesh['renderMaterial'] = convert_material(obj_material) speckle_obj['@displayValue'].append(speckle_mesh) # Commit client = SpeckleClient(host=os.getenv('SPECKLE_SERVER_URL', 'localhost:3000'), use_ssl=False) client.authenticate(os.environ['USER_TOKEN']) if not client.branch.get(stream_id, branch_name): client.branch.create( stream_id, branch_name, 'File upload branch' if branch_name == 'uploads' else '') transport = ServerTransport(client=client, stream_id=stream_id) id = operations.send(base=speckle_root, transports=[transport]) commit_id = client.commit.create(stream_id=stream_id, object_id=id, branch_name=(branch_name or DEFAULT_BRANCH), message=(commit_message or 'OBJ file upload'), source_application='OBJ') return commit_id