def post(self, request, *args, **kwargs): """Import a manifest at a remote_url.""" remote_url = request.data.get("remote_url") if not remote_url: return Response( {'error': 'Did not provide remote_url.'}, status=status.HTTP_400_BAD_REQUEST) shared_id = str(uuid.uuid4()) imp = ManifestPreImporter(remote_url) lst = imp.get_all_urls() # If there are manifests to import, create a celery group for the task. if lst: if len(lst) == 1: g = group([import_single_manifest.s(imp.text, lst[0])]) else: g = group([import_single_manifest.s(None, url) for url in lst]).skew(start=0, step=0.3) task = g.apply_async(task_id=shared_id) task.save() else: if imp.errors: return Response({'errors': imp.errors}, status=status.HTTP_400_BAD_REQUEST) return Response({'errors': ['Failed to find recognisable IIIF manifest data.']}, status=status.HTTP_400_BAD_REQUEST) # Return a URL where the status of the import can be polled. status_url = reverse('status', request=request, args=[shared_id]) return Response({'status': status_url}, status.HTTP_202_ACCEPTED)
def test_get_nested_col(self): """ Get only manifest URLs when scarping through nested collections.""" pre_importer = ManifestPreImporter("http://localhost:8888/misirlou/tests/fixtures/collection_top.json") url_list = pre_importer.get_all_urls() self.assertListEqual(['http://localhost:8888/misirlou/tests/fixtures/manifest.json'], url_list)
def test_get_top_manifest(self): """ If there are no nested manifests, simply return the top level url.""" pre_importer = ManifestPreImporter("http://localhost:8888/misirlou/tests/fixtures/manifest.json") url_list = pre_importer.get_all_urls() self.assertListEqual(['http://localhost:8888/misirlou/tests/fixtures/manifest.json'], url_list)
def test_get_embedded_manifest(self): """ Get a manifest embedded in a collection. """ pre_importer = ManifestPreImporter("http://localhost:8888/misirlou/tests/fixtures/collection_bottom.json") url_list = pre_importer.get_all_urls() self.assertListEqual(['http://localhost:8888/misirlou/tests/fixtures/manifest.json'], url_list)