def test_jobs_view_expected_job(svc_client_cache): """Check non-empty result for user requested job.""" svc_client, headers, cache = svc_client_cache user = cache.ensure_user({"user_id": "user"}) job_data = { "job_id": uuid.uuid4().hex, "state": "CREATED", "renku_op": "dataset_import", "created_at": isoformat(datetime.now()), "updated_at": isoformat(datetime.now()), "extras": { "progress": 42 }, } project = Project(project_id="123", user_id=user.user_id, owner="renkumeister", name="testproject") project.abs_path.mkdir(parents=True, exist_ok=True) project.save() job = cache.make_job(user, project=project, job_data=job_data) response = svc_client.get("/jobs", headers=headers) assert 1 == len(response.json["result"]["jobs"]) assert { "job_id", "state", "created_at", "updated_at", "extras", "client_extras", "renku_op", "project" } == set(response.json["result"]["jobs"][0].keys()) cache.invalidate_job(user, job.job_id) response = svc_client.get("/jobs", headers=headers) assert 0 == len(response.json["result"]["jobs"])
def test_jobs_view_check_exclusion(svc_client_cache): """Check non-empty result for user requested jobs.""" svc_client, headers, cache = svc_client_cache user = cache.ensure_user({"user_id": "user"}) excluded_user = cache.ensure_user({"user_id": "excluded_user"}) for _ in range(10): job_data = { "job_id": uuid.uuid4().hex, "state": "CREATED", "created_at": isoformat(datetime.utcnow()), "updated_at": isoformat(datetime.utcnow()), "extras": { "progress": 42 }, "renku_op": "dataset_import", } project = Project(project_id="123", user_id=user.user_id, owner="renkumeister", name="testproject") project.abs_path.mkdir(parents=True, exist_ok=True) project.save() job1 = cache.make_job(user, project=project, job_data=job_data) assert job1 new_job = copy.deepcopy(job_data) new_job["job_id"] = uuid.uuid4().hex job2 = cache.make_job(excluded_user, project=project, job_data=new_job) assert job2 assert job1.job_id != job2.job_id response = svc_client.get("/jobs", headers=headers) assert {"result"} == set(response.json.keys()) assert 10 == len(response.json["result"]["jobs"]) for job in response.json["result"]["jobs"]: assert { "job_id", "state", "created_at", "updated_at", "extras", "client_extras", "renku_op", "project" } == set(job.keys())
def get_project(user, project_id): """Get user cached project.""" try: record = Project.get((Project.project_id == project_id) & (Project.user_id == user.user_id)) except ValueError: return return record
def get_project(user, project_id): """Get user cached project.""" try: record = Project.get((Project.project_id == project_id) & (Project.user_id == user.user_id)) except ValueError: raise ProjectNotFound(project_id) if not record.abs_path.exists(): record.delete() raise ProjectNotFound(project_id) return record
def test_job_details_2user(svc_client_cache): """Check job details for a user.""" svc_client, headers, cache = svc_client_cache user = cache.ensure_user({"user_id": "user"}) jobs = [{ "job_id": uuid.uuid4().hex, "state": "CREATED", "created_at": isoformat(datetime.now()), "updated_at": isoformat(datetime.now()), "extras": { "progress": 42 }, "renku_op": "dataset_import", } for _ in range(10)] project = Project(project_id="123", user_id=user.user_id, owner="renkumeister", name="testproject") project.abs_path.mkdir(parents=True, exist_ok=True) project.save() for job_data in jobs: cache.make_job(user, job_data=job_data, project=project) user_headers = copy.deepcopy(headers) headers["Renku-User-Id"] = "excluded_user" excluded_user_headers = copy.deepcopy(headers) for job in jobs: response = svc_client.get("/jobs/{0}".format(job["job_id"]), headers=user_headers) assert response assert job["job_id"] == response.json["result"]["job_id"] response = svc_client.get("/jobs/{0}".format(job["job_id"]), headers=excluded_user_headers) assert response.json["result"] is None
def get_projects(user): """Get all user cache projects.""" return Project.query(Project.user_id == user.user_id)
def make_project(self, data, **options): """Construct project object.""" return Project(**data)