def setUp(self):
        celery.conf.task_always_eager = True

        db.create_all()

        testfiles = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                 "files")

        with open(os.path.join(testfiles, "PPN821881744.mets.xml"),
                  "r",
                  encoding="utf-8") as tfh:
            responses.add(method=responses.GET,
                          url="http://foo.bar/mets.xml",
                          body=tfh.read(),
                          status=200)

        for i in "123":
            with open(os.path.join(testfiles, f"0000000{i}.jpg"), "rb") as tfh:
                img_file = tfh.read()
                responses.add(
                    method=responses.GET,
                    url=("https://content.staatsbibliothek-berlin.de/dc/"
                         f"PPN821881744-0000000{i}/full/max/0/default.jpg"),
                    body=img_file,
                    status=200,
                    content_type="image/jpg")
                responses.add(
                    method=responses.GET,
                    url=("https://content.staatsbibliothek-berlin.de/dc/"
                         f"PPN821881744-0000000{i}/full/max/0/default.tif"),
                    body=img_file,
                    status=200,
                    content_type="image/tiff")
Ejemplo n.º 2
0
    def setUp(self):
        db.create_all()

        def create_api_task_callback(request):
            db_task = db_model_Task(uid="id",
                                    src="mets_url",
                                    default_file_grp="file_grp",
                                    worker_task_id="worker_task.id",
                                    chain_id="chain.id",
                                    parameters="")
            db.session.add(db_task)
            db.session.commit()
            headers = {}
            # "message": "Task created."
            return (201, headers, json.dumps({"task_id": 1, "created": True}))

        def delete_api_task_callback(request):
            db_model_Task.query.filter_by(id=1).delete()
            db.session.commit()
            return (200, {}, json.dumps({"task_id": 1, "deleted": True}))

        responses.add_callback(responses.POST,
                               "http://localhost/api/tasks",
                               callback=create_api_task_callback)

        responses.add(responses.GET,
                      "http://foo.bar/mets.xml",
                      body="<xml>foo</xml>",
                      status=200)

        responses.add_callback(responses.DELETE,
                               "http://localhost/api/tasks/1",
                               callback=delete_api_task_callback)

        def api_get_taskinfo_callback(request):
            return (200, {},
                    json.dumps({
                        "task_id": 1,
                        "state": "PENDING",
                        "result": None,
                    }))

        responses.add_callback(
            responses.GET,
            "http://localhost:5555/api/task/info/worker_task.id",
            callback=api_get_taskinfo_callback)
Ejemplo n.º 3
0
    def setUp(self):

        from ocrd_butler import celery
        celery.conf.task_always_eager = True

        db.create_all()

        testfiles = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                 "files")
        with open("{0}/sbb-mets-PPN821929127.xml".format(testfiles),
                  "r") as tfh:
            responses.add(responses.GET,
                          "http://foo.bar/mets.xml",
                          body=tfh.read(),
                          status=200)
            tfh.close()
        with open("{0}/00000001.jpg".format(testfiles), "rb") as tfh:
            responses.add(responses.GET,
                          "http://content.staatsbibliothek-berlin.de/dms/"
                          "PPN821929127/800/0/00000001.jpg",
                          body=tfh.read(),
                          status=200,
                          content_type="image/jpg")
            tfh.close()
        with open("{0}/00000002.jpg".format(testfiles), "rb") as tfh:
            responses.add(responses.GET,
                          "http://content.staatsbibliothek-berlin.de/dms/"
                          "PPN821929127/800/0/00000002.jpg",
                          body=tfh.read(),
                          status=200,
                          content_type="image/jpg")
            tfh.close()
        with open("{0}/00000003.jpg".format(testfiles), "rb") as tfh:
            responses.add(responses.GET,
                          "http://content.staatsbibliothek-berlin.de/dms/"
                          "PPN821929127/800/0/00000003.jpg",
                          body=tfh.read(),
                          status=200,
                          content_type="image/jpg")
            tfh.close()
Ejemplo n.º 4
0
 def setUp(self):
     db.create_all()
Ejemplo n.º 5
0
    def setUp(self):
        db.create_all()

        def create_api_task_callback(request):
            db_task = models.Task.create(
                uid="uid",
                src="mets_url",
                default_file_grp="file_grp",
                worker_task_id="worker_task.id",
                workflow_id=1,
            )
            db.session.add(db_task)
            db.session.commit()
            headers = {}
            # "message": "Task created."
            return (201, headers, json.dumps({"task_id": 1, "created": True}))

        def delete_api_task_callback(request):
            models.Task.query.filter_by(id=1).delete()
            db.session.commit()
            return (200, {}, json.dumps({"task_id": 1, "deleted": True}))

        def get_api_tasks_callback(request):
            tasks = []
            for task in models.Task.get_all():
                workflow = models.Workflow.get(id=task.workflow_id)
                task.workflow = workflow
                tasks.append(task)
            return (200, {}, json.dumps([task.to_json() for task in tasks]))

        responses.add_callback(responses.POST,
                               "http://localhost/api/tasks",
                               callback=create_api_task_callback)

        responses.add(responses.GET,
                      "http://foo.bar/mets.xml",
                      body="<xml>foo</xml>",
                      status=200)

        responses.add_callback(
            method=responses.GET,
            url='http://localhost/api/tasks',
            callback=get_api_tasks_callback,
        )

        responses.add_callback(responses.DELETE,
                               "http://localhost/api/tasks/uid",
                               callback=delete_api_task_callback)

        def api_get_taskinfo_callback(request):
            return (200, {},
                    json.dumps({
                        "task_id": 1,
                        "state": "PENDING",
                        "result": None,
                    }))

        responses.add_callback(
            responses.GET,
            "http://localhost:5555/api/task/info/worker_task.id",
            callback=api_get_taskinfo_callback)

        responses.add(method=responses.POST,
                      url="http://localhost/api/tasks/1/run",
                      body=json.dumps({
                          "worker_task_id": "1",
                          "status": "SUCCESS",
                      }),
                      status=200)

        responses.add(
            method=responses.GET,
            url='http://localhost/api/workflows',
            body=json.dumps([
                models.Workflow(**dict(
                    name="TC Workflow",
                    description="Workflow with tesseract and calamari recog.",
                    processors=[{
                        "name": "ocrd-olena-binarize",
                        "parameters": {
                            "impl": "sauvola-ms-split"
                        }
                    }])).to_json()
            ]),
            status=200)