The function will create a Job object for testing purposes. You can supply you own project if there is one in specific that has to be attached, if not the function will also mock a project for you. The idea is that new developer don't have to worry about the relation
(job_data, session)
| 456 | |
| 457 | |
| 458 | def create_job(job_data, session): |
| 459 | """ |
| 460 | The function will create a Job object for testing purposes. You can supply you own |
| 461 | project if there is one in specific that has to be attached, if not the function will |
| 462 | also mock a project for you. The idea is that new developer don't have to worry about the |
| 463 | relations between object in order to mock faster. |
| 464 | For example: "I want to create a Job, but I don't really care about the project." |
| 465 | - Then I should not worry about the details of mocking a project. |
| 466 | |
| 467 | TODO: |
| 468 | More data mocks are still pending, like members, labels, etc... |
| 469 | For now, this is sufficient for the current tests we're writing. |
| 470 | :param job_data: |
| 471 | :param session: |
| 472 | :return: |
| 473 | """ |
| 474 | if job_data.get('project'): |
| 475 | job = Job(member_created = None, project = job_data.get('project')) |
| 476 | else: |
| 477 | project_string_id = f"{get_random_string(8)}-job-project" |
| 478 | project_context = { |
| 479 | 'project_string_id': project_string_id, |
| 480 | 'project_name': f"{project_string_id}-job-project", |
| 481 | 'users': [ |
| 482 | {'username': f"{get_random_string(5)}-job-user", |
| 483 | 'email': 'test@test.com', |
| 484 | 'password': 'diffgram123', |
| 485 | 'project_string_id': project_string_id |
| 486 | } |
| 487 | ] |
| 488 | } |
| 489 | project_data = create_project_with_context(project_context, session) |
| 490 | job = Job(member_created = None, project = project_data.get('project'), |
| 491 | project_id = project_data.get('project').id) |
| 492 | session.add(job) |
| 493 | |
| 494 | # TODO: support mocking labels. |
| 495 | job.label_dict = job_data.get('label_dict', {}) |
| 496 | job.type = job_data.get('type', 'draft') |
| 497 | job.status = job_data.get('status', 'draft') |
| 498 | job.label_dict['label_file_list'] = job_data.get('label_file_list', []) |
| 499 | job.name = job_data.get('name', None) |
| 500 | job.output_dir_action = job_data.get('output_dir_action', 'nothing') |
| 501 | job.share_type = job_data.get('name', 'project') |
| 502 | job.allow_reviews = job_data.get('allow_reviews', False) |
| 503 | |
| 504 | job.share_type = job.share_type.lower() |
| 505 | |
| 506 | job.launch_datetime = datetime.datetime.now() |
| 507 | |
| 508 | if job.launch_datetime is not None: |
| 509 | job.waiting_to_be_launched = True |
| 510 | |
| 511 | job.interface_connection_id = job_data.get('interface_connection_id') |
| 512 | job.file_count = job_data.get('file_count', 0) # note this is user set |
| 513 | |
| 514 | job.permission = job_data.get('file_count', 'all_secure_users') |
| 515 | job.label_mode = job_data.get('label_mode', 'open') |
no test coverage detected