def test_report_job(self): create_workflow(label='test workflow') test_workflow = Workflow.query.first() self.assertIsNotNone(test_workflow.workflowId) create_sysConfig( label='test sysconfig', nixConfigFilename='test.nix', nixConfig='{ nix: config }', workflowId=test_workflow.workflowId ) test_sysconfig = SystemConfigurationInput.query.first() create_reportJob( label='first report', sysConfigId=test_sysconfig.sysConfigId, workflowId=test_workflow.workflowId, statusId=JobStatus().query.order_by(JobStatus.statusId.desc()).first().statusId ) create_reportJob( label='second report', sysConfigId=test_sysconfig.sysConfigId, workflowId=test_workflow.workflowId, statusId=JobStatus().query.first().statusId ) test_report_jobs = ReportJob.query.all() self.assertIsNotNone(test_report_jobs) self.assertEqual(len(test_report_jobs), 2, msg='Expected only two report jobs to exist') test_workflow = Workflow.query.first() self.assertEqual(len(test_workflow.reportJobs), 2, msg='Expected to be able to find two report jobs for our workflow') first_report = test_workflow.reportJobs[0] self.assertEqual(first_report.label, 'first report')
def test_get(self): # add two report jobs r = ReportJob().query.all() self.assertListEqual(r, []) r1 = create_reportJob(label='r1', statusId=1, workflowId=self.workflowId) r2 = create_reportJob(label='r2', statusId=1, workflowId=self.workflowId) r = ReportJob().query.all() self.assertEqual(len(r), 2) # get them individually response = self.client.get(f'{self.BASE_ENDPOINT}/{r1.jobId}') self.assertEqual(response.status_code, 200) json_response = json.loads(response.get_data(as_text=True)) self.assertEqual(json_response['label'], 'r1') response = self.client.get(f'{self.BASE_ENDPOINT}/{r2.jobId}') self.assertEqual(response.status_code, 200) json_response = json.loads(response.get_data(as_text=True)) self.assertEqual(json_response['label'], 'r2') # get them all response = self.client.get(self.BASE_ENDPOINT) self.assertEqual(response.status_code, 200) json_response = json.loads(response.get_data(as_text=True)) self.assertEqual(len(json_response), 2)
def test_update_with_invalid_status(self): nonexistent_status_id = 10 self.assertIsNone(JobStatus.query.get(nonexistent_status_id)) rj = create_reportJob( workflowId=self.workflowId, label='REPORT w/ NONEXISTENT STATUS', statusId=self.status.statusId, ) self.assertIsNotNone(rj) response = self.client.put(f'{self.BASE_ENDPOINT}/{rj.jobId}', headers=DEFAULT_HEADERS, data=json.dumps( dict(workflowId=rj.workflowId, jobId=rj.jobId, label=rj.label, status=dict( statusId=nonexistent_status_id, label='NONEXISTENT STATUS')))) self.assertEqual(response.status_code, 400) self.assertEqual( response.get_json(), { 'message': 'Unable to find specified job status', 'status': { 'statusId': nonexistent_status_id, 'label': 'NONEXISTENT STATUS' } })
def test_basic_functionality(self): wf = create_workflow(label='test workflow') jobStatusId = JobStatus.query.filter_by( label='running').first().statusId self.assertIsNotNone(jobStatusId) create_reportJob(label='test report 1', workflowId=wf.workflowId, statusId=jobStatusId) testReportJob = ReportJob.query.filter_by( workflowId=wf.workflowId).first() self.assertIsNotNone(testReportJob) self.assertEqual(testReportJob.status.label, 'running')
def test_basic_functionality(self): rj = create_reportJob(workflowId=1, label='test reportJob', statusId=1) create_cwe_score(reportJobId=rj.jobId, cwe=1234, score='FAIL', notes='2/2 error') testCweScore = CweScore.query.filter_by(reportJobId=rj.jobId).first() self.assertIsNotNone(testCweScore) self.assertEqual(testCweScore.report, rj)
def test_attempt_to_change_workflow(self): rj = create_reportJob( workflowId=self.workflowId, label='TEST REPORT', statusId=self.status.statusId, ) self.assertIsNotNone(rj) response = self.client.put(f'{self.BASE_ENDPOINT}/{rj.jobId}', headers=DEFAULT_HEADERS, data=json.dumps( dict(workflowId=rj.workflowId + 1, jobId=rj.jobId, label=rj.label, status=dict( statusId=rj.status.statusId, label=rj.status.label)))) self.assertEqual(response.status_code, 400) self.assertEqual(response.get_json(), { 'message': 'Cannot change workflow association', })
def test_update(self): r = ReportJob().query.all() self.assertListEqual(r, []) r = create_reportJob(label='r1', statusId=self.status.statusId, workflowId=self.workflowId) self.assertEqual(len(ReportJob().query.all()), 1) label = f'{r.label}-{datetime.now()}' response = self.client.put(f'{self.BASE_ENDPOINT}/{r.jobId}', headers=DEFAULT_HEADERS, data=json.dumps( dict(jobId=r.jobId, label=label, status=dict( statusId=self.status.statusId, label=self.status.label), workflowId=self.workflowId))) self.assertEqual(response.status_code, 200) created_report_job = ReportJob.query.filter_by(label=label) self.assertIsNotNone(created_report_job)
def test_update_with_missing_data(self): r = ReportJob().query.all() self.assertListEqual(r, []) r = create_reportJob(label='r1', statusId=1, workflowId=self.workflowId) self.assertEqual(len(ReportJob().query.all()), 1) label = f'{r.label}-{datetime.now()}' response = self.client.put(f'{self.BASE_ENDPOINT}/{r.jobId}', headers=DEFAULT_HEADERS, data=json.dumps( dict(jobId=r.jobId, label=label))) self.assertEqual(response.status_code, 400) self.assertEqual( response.get_json(), { 'errors': { 'status': "'status' is a required property", 'workflowId': "'workflowId' is a required property" }, 'message': 'Input payload validation failed' })