def post(dataset_id: str, token: str, data: dict) -> bool: """Uploads a batch of embeddings to the servers. Args: dataset_id: Identifier of the dataset. token: The token for authenticating the request. data: Object with embedding data. Returns: A boolean value indicating successful upload. Raises: RuntimeError if upload was not successful. """ dst_url = _prefix(dataset_id=dataset_id) payload = { 'embeddingName': data['embeddingName'], 'embeddings': data['embeddings'], 'append': data['append'], 'token': token, } response = post_request(dst_url, json=payload) return response
def test_post_no_success(self): '''Make sure everything works in no-error scenario. ''' self.setup(psuccess=0.) responses.add_callback(responses.POST, self.dst_url, callback=self.callback, content_type='application/json') with self.assertRaises(RuntimeError): data = self.data json = self.json post_request(self.dst_url, data=data, json=json)
def test_post_some_success(self): '''Make sure everything works in no-error scenario. ''' self.setup(psuccess=.9) responses.add_callback(responses.POST, self.dst_url, callback=self.callback, content_type='application/json') for _ in range(N): data = self.data json = self.json post_request(self.dst_url, data=data, json=json)
def post(filename: str, thumbname: str, metadata: str, dataset_id: str, token: str): """Uploads a sample and its metadata to the servers. Args: filename: Filename of the sample. thumbname: Filename of thumbnail if it exists. metadata: Dictionary containing metadata of the sample. dataset_id: Identifier of the dataset. token: The token for authenticating the request. Returns: Sample id of the uploaded sample. Raises: RuntimeError if post request failed. """ dst_url = _prefix(dataset_id=dataset_id) payload = { 'sample': { 'fileName': filename, 'meta': metadata, }, 'token': token } # fix url, TODO: fix api instead dst_url += '/' if thumbname is not None: payload['sample']['thumbName'] = thumbname response = post_request(dst_url, json=payload) sample_id = response.json()['sampleId'] return sample_id