Пример #1
0
 def test_get_active_job_with_no_active_job(self):
     db_ro_user = "******"
     job_crud = CRUDJob(
         db_ro_user=db_ro_user,
         result_expiration_sec_default=int(1e6),
         result_expiration_sec_limit=int(1e6),
         max_graph_age_sec_default=int(1e6),
         max_graph_age_sec_limit=int(1e6),
         max_result_age_sec_default=int(1e6),
         max_result_age_sec_limit=int(1e6),
         account_id_key="test_account_id",
     )
     with temp_db_session() as session:
         session.execute(f"CREATE ROLE {db_ro_user}")
         job_create = schemas.JobCreate(
             name="test_job",
             description="A Test Job",
             graph_spec=schemas.JobGraphSpec(graph_names=["1", "2"]),
             category=schemas.Category.gov,
             severity=schemas.Severity.info,
             query=
             "select ?s ?p ?test_account_id where {?s ?p ?test_account_id} limit 10",
             max_graph_age_sec=int(1e6),
             result_expiration_sec=int(1e6),
             max_result_age_sec=int(1e6),
             notify_if_results=False,
         )
         job_crud.create(db_session=session, job_create_in=job_create)
         with self.assertRaises(ActiveJobVersionNotFound):
             job_crud.get_active(session, "test_job")
Пример #2
0
    def test_get_active_job(self):
        db_ro_user = "******"
        job_crud = CRUDJob(
            db_ro_user=db_ro_user,
            result_expiration_sec_default=int(1e6),
            result_expiration_sec_limit=int(1e6),
            max_graph_age_sec_default=int(1e6),
            max_graph_age_sec_limit=int(1e6),
            max_result_age_sec_default=int(1e6),
            max_result_age_sec_limit=int(1e6),
            account_id_key="test_account_id",
        )
        with temp_db_session() as session:
            session.execute(f"CREATE ROLE {db_ro_user}")
            # job which will be activated
            job_create = schemas.JobCreate(
                name="test_job",
                description="A Test Job",
                graph_spec=schemas.JobGraphSpec(graph_names=["1", "2"]),
                category=schemas.Category.gov,
                severity=schemas.Severity.info,
                query=
                "select ?s ?p ?test_account_id where {?s ?p ?test_account_id} limit 10",
                max_graph_age_sec=int(1e6),
                result_expiration_sec=int(1e6),
                max_result_age_sec=int(1e6),
            )
            created_timestamp = job_crud.create(
                db_session=session, job_create_in=job_create).created

            # dummy inactive job
            another_job_create = schemas.JobCreate(
                name="test_job",
                description="A Test Job",
                graph_spec=schemas.JobGraphSpec(graph_names=["a", "b"]),
                category=schemas.Category.gov,
                severity=schemas.Severity.info,
                query=
                "select ?q ?r ?test_account_id where {?q ?r ?test_account_id} limit 10",
                max_graph_age_sec=int(1e6),
                result_expiration_sec=int(1e6),
                max_result_age_sec=int(1e6),
            )
            job_crud.create(db_session=session,
                            job_create_in=another_job_create).created

            # activate
            job_update = schemas.JobUpdate(active=True)
            _activated_job = job_crud.update_version(
                db_session=session,
                job_name="test_job",
                created=created_timestamp,
                job_update=job_update,
            )
            activated_job = schemas.Job.from_orm(_activated_job)

            _job = job_crud.get_active(session, "test_job")
            job = schemas.Job.from_orm(_job)
            self.assertEqual(activated_job, job)
Пример #3
0
def get_job(
    *,
    db_session: Session = Depends(deps.db_session),
    job_crud: CRUDJob = Depends(deps.job_crud),
    job_name: str,
) -> Any:
    """Get the currently active version of a Job"""
    try:
        return job_crud.get_active(db_session, job_name=job_name)
    except ActiveJobVersionNotFound as ex:
        raise HTTPException(status_code=HTTP_404_NOT_FOUND, detail=str(ex)) from ex