def test_chunks(self): my_list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] self.assertEqual(len(get_chunks(my_list, 10)), 3) self.assertEqual(len(get_chunks(my_list, 26)), 1) self.assertEqual(len(get_chunks(my_list, 30)), 1) results = [] for chunk in get_chunks(my_list, 4): results += chunk self.assertEqual(results, my_list)
def delete(self, feature: SomeResourceIds, *, permanent: bool = False, **kwargs): """Delete a feature or multiple features. Args: feature: Identifier of the feature to delete, or list of such identifiers. permanent: Whether to delete features permanently or not. Default to False. **kwargs: Optional keyword arguments. Those arguments are passed as is to the API provider. """ data = kwargs if isinstance(feature, list): path = 'delete-features' if not permanent \ else 'delete-features-permanently' ids_chunks = get_chunks(feature, self._provider.max_per_delete) for ids_chunk in ids_chunks: data['features'] = ids_chunk self._provider.post(path, data=data, as_json=False) else: path = 'delete-feature' if not permanent \ else 'delete-feature-permanently' data['feature'] = feature self._provider.post(path, data=data, as_json=False)
def describe(self, flight: SomeResourceIds, **kwargs) -> SomeResources: """Describe a flight or a list of flights. Args: flight: Identifier of the flight to describe, or list of such identifiers. **kwargs: Optional keyword arguments. Those arguments are passed as is to the API provider. Returns: The flight description or a list of flight descriptions. """ data = kwargs if isinstance(flight, list): results = [] ids_chunks = get_chunks(flight, self._provider.max_per_describe) for ids_chunk in ids_chunks: data['flights'] = ids_chunk descs = self._provider.post('describe-flights', data=data) results += [Resource(**desc) for desc in descs] return results else: data['flight'] = flight desc = self._provider.post('describe-flight', data=data) return Resource(**desc)
def describe(self, company: SomeResourceIds, **kwargs) -> SomeResources: """Describe a company or multiple companies. Args: company: Identifier of the company to describe, or list of such identifiers. **kwargs: Optional keyword arguments. Those arguments are passed as is to the API provider. Returns: The company description or a list of company description. """ data = kwargs if isinstance(company, list): results = [] ids_chunks = get_chunks(company, self._provider.max_per_describe) for ids_chunk in ids_chunks: data['companies'] = ids_chunk descs = self._provider.post('describe-companies', data=data) results += [Resource(**desc) for desc in descs] return results else: data['company'] = company desc = self._provider.post('describe-company', data=data) return Resource(**desc)
def describe(self, task: SomeResourceIds, **kwargs) -> SomeResources: """Describe a collection task. Args: task: Identifier of the collection task to describe, or list of such identifiers. Returns: Resource: The collection task description or a list of collection task descriptions. """ data = kwargs if isinstance(task, list): results = [] ids_chunks = get_chunks(task, self._provider.max_per_describe) for ids_chunk in ids_chunks: data['tasks'] = ids_chunk descs = self._provider.post('describe-tasks', data=data) results += [Resource(**desc) for desc in descs] return results else: data['task'] = task desc = self._provider.post('describe-task', data=data) return Resource(**desc)
def describe(self, carrier: SomeResourceIds, **kwargs) -> SomeResources: """Describe a carrier or a list of carriers. Args: carrier: Identifier of the carrier to describe, or list of such identifiers. **kwargs: Optional keyword arguments. Those arguments are passed as is to the API provider. Returns: Resource: The carrier description or a list of carriers descriptions. """ data = kwargs if isinstance(carrier, list): results = [] ids_chunks = get_chunks(carrier, self._provider.max_per_describe) for ids_chunk in ids_chunks: data['carriers'] = ids_chunk descs = self._provider.post('describe-carriers', data=data) results += [Resource(**desc) for desc in descs] return results else: data['carrier'] = carrier desc = self._provider.post('describe-carrier', data=data) return Resource(**desc)
def describe(self, team: SomeResourceIds, **kwargs) -> SomeResources: """Describe a team or list of teams. Args: team: Identifier of the team to describe, or list of such identifiers. **kwargs: Optional keyword arguments. Those arguments are passed as is to the API provider. Returns: Resource: A team resource or a list of team resources. """ data = kwargs if isinstance(team, list): results = [] ids_chunks = get_chunks(team, self._provider.max_per_describe) for ids_chunk in ids_chunks: data['teams'] = ids_chunk descs = self._provider.post('describe-teams', data=data) results += [Resource(**desc) for desc in descs] return results else: data['team'] = team desc = self._provider.post('describe-team', data=data) return Resource(**desc)
def delete(self, annotation: SomeResourceIds, **kwargs): """Delete an annotation or multiple annotations. Args: annotation: Identifier of the annotation to delete, or list of such identifiers. **kwargs: Optional keyword arguments. Those arguments are passed as is to the API provider. """ data = kwargs if 'resource' in kwargs: raise RuntimeError( 'Support for "resource" parameter is not supported') if isinstance(annotation, Resource): raise RuntimeError( 'Support for parameters of type "Resource" is not supported') if not isinstance(annotation, list): annotation = [annotation] ids_chunks = get_chunks(annotation, self._provider.max_per_delete) for ids_chunk in ids_chunks: data['annotations'] = ids_chunk self._provider.post('delete-annotations', data=data, as_json=False)
def describe(self, annotation: SomeResourceIds, **kwargs) -> SomeResources: """Describe a dataset or a list of datasets. Args: annotation: Identifier of the annotation to describe, or list of such identifiers. **kwargs: Optional keyword arguments. Those arguments are passed as is to the API provider. Returns: The annotation description or a list of annotation description. """ data = kwargs if isinstance(annotation, list): results = [] ids_chunks = get_chunks(annotation, self._provider.max_per_describe) for ids_chunk in ids_chunks: data['annotations'] = ids_chunk descs = self._provider.post('describe-annotations', data=data) results += [Resource(**desc) for desc in descs] return results else: data['annotation'] = annotation desc = self._provider.post('describe-annotation', data=data) return Resource(**desc)
def delete(self, dataset: SomeResourceIds, **kwargs): """Delete a dataset or multiple datasets. Args: dataset: Identifier of the dataset to delete, or list of such identifiers. **kwargs: Optional keyword arguments. Those arguments are passed as is to the API provider. """ data = kwargs if not isinstance(dataset, list): dataset = [dataset] ids_chunks = get_chunks(dataset, self._provider.max_per_delete) for ids_chunk in ids_chunks: data['datasets'] = ids_chunk self._provider.post('delete-datasets', data=data, as_json=False)