def get_jobs( *, db_session: Session = Depends(deps.db_session), job_crud: CRUDJob = Depends(deps.job_crud), active_only: bool = True, ) -> Any: """Get all Jobs""" return job_crud.get_multi(db_session, active_only=active_only)
def test(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_1 = schemas.JobCreate( name="test_job_1", description="A Test Job 1", 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, ) created_timestamp_1 = job_crud.create( db_session=session, job_create_in=job_create_1).created job_create_2 = schemas.JobCreate( name="test_job_2", description="A Test Job 2", 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), notify_if_results=False, ) created_timestamp_2 = job_crud.create( db_session=session, job_create_in=job_create_2).created job_create_3 = schemas.JobCreate( name="test_job_3", description="A Test Job 3", 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), notify_if_results=False, ) _job_3 = job_crud.create(db_session=session, job_create_in=job_create_3) job_3 = schemas.Job.from_orm(_job_3) # activate 1, 2 job_update = schemas.JobUpdate(active=True) _activated_job_1 = job_crud.update_version( db_session=session, job_name="test_job_1", created=created_timestamp_1, job_update=job_update, ) activated_job_1 = schemas.Job.from_orm(_activated_job_1) _activated_job_2 = job_crud.update_version( db_session=session, job_name="test_job_2", created=created_timestamp_2, job_update=job_update, ) activated_job_2 = schemas.Job.from_orm(_activated_job_2) _active_only_jobs = job_crud.get_multi(db_session=session, active_only=True) active_only_jobs = [ schemas.Job.from_orm(job) for job in _active_only_jobs ] self.assertEqual(active_only_jobs, [activated_job_1, activated_job_2]) _all_jobs = job_crud.get_multi(db_session=session, active_only=False) all_jobs = [schemas.Job.from_orm(job) for job in _all_jobs] self.assertEqual(all_jobs, [activated_job_1, activated_job_2, job_3])