def async_find_and_attach(upload_id): """ Task backend for Vscan upload """ case = None try: upload_doc = VscanUpload.get(upload_id) files = get_files_from_doc(upload_doc) case = match_case( upload_doc.scanner_serial, upload_doc.scan_id, ) if case: files = {} attachments = (upload_doc.blobs if isinstance( upload_doc, BlobMixin) else upload_doc._attachments) for f in attachments: files[f] = io.BytesIO(upload_doc.fetch_attachment(f)) attach_images_to_case(case._id, files) else: return -1 upload_doc.delete() except: # mark the case as having errored (if we know what it is) # but reraise the error since we don't want to hide it if case: submit_error_case(case._id) raise
def testGetsOnlyUnmarkedCases(self): self.create_scan_case(self.vscan_user._id, 'VH014466XK', '123123', '2014-03-30T10:48:49Z', scan_status='scan_complete') case = utils.match_case('VH014466XK', '123123', '') self.assertEqual(self.case_id, case._id)
def testGetsOnlyUnmarkedCases(self): self.create_scan_case( self.vscan_user._id, "VH014466XK", "123123", "2014-03-30T10:48:49Z", scan_status="scan_complete" ) case = utils.match_case("VH014466XK", "123123", "") self.assertEqual(self.case_id, case._id)
def async_find_and_attach(upload_id): """ Task backend for Vscan upload """ case = None try: upload_doc = VscanUpload.get(upload_id) files = get_files_from_doc(upload_doc) case = match_case(upload_doc.scanner_serial, upload_doc.scan_id) if case: files = {} for f in upload_doc._attachments.keys(): files[f] = io.BytesIO(upload_doc.fetch_attachment(f)) attach_images_to_case(case._id, files) else: return -1 upload_doc.delete() except: # mark the case as having errored (if we know what it is) # but reraise the error since we don't want to hide it if case: submit_error_case(case._id) raise
def testErrorsWithTwoCases(self): self.create_scan_case(self.vscan_user._id, 'VH014466XK', '123123', '2014-03-29T10:48:49Z') self.create_scan_case(self.vscan_user._id, 'VH014466XK', '123123', '2014-03-22T10:48:49Z') self.assertRaises(MultipleResultsFound, lambda: utils.match_case('VH014466XK', '123123', ''))
def testGetsOnlyUnmarkedCases(self): self.create_scan_case( self.vscan_user._id, 'VH014466XK', '123123', '2014-03-30T10:48:49Z', scan_status='scan_complete' ) case = utils.match_case('VH014466XK', '123123', '') self.assertEqual(self.case_id, case._id)
def testErrorsWithTwoCases(self): self.create_scan_case( self.vscan_user._id, 'VH014466XK', '123123', '2014-03-29T10:48:49Z' ) self.create_scan_case( self.vscan_user._id, 'VH014466XK', '123123', '2014-03-22T10:48:49Z' ) self.assertRaises( MultipleResultsFound, lambda: utils.match_case('VH014466XK', '123123', '') )
def testWrongSerial(self): case = utils.match_case('wrong', '123123', '') self.assertIsNone(case)
def testWrongScanID(self): case = utils.match_case('VH014466XK', 'wrong', '') self.assertIsNone(case)
def testFindsCorrectCase(self): case = utils.match_case('VH014466XK', '123123', '') self.assertEqual(self.case_id, case._id)
class ScanLookupTests(UTHTests): def testFindsCorrectCase(self): case = utils.match_case('VH014466XK', '123123', '') self.assertEqual(self.case_id, case._id)
username = format_username('vscan_user', UTH_DOMAIN) self.vscan_user = CommCareUser.get_by_username( username) or CommCareUser.create(UTH_DOMAIN, username, 'secret') self.case_id = self.create_scan_case(self.vscan_user._id, 'VH014466XK', '123123', '2014-03-28T10:48:49Z') class ScanLookupTests(UTHTests): def testFindsCorrectCase(self): case = utils.match_case('VH014466XK', '123123', '') self.assertEqual(self.case_id, case._id) def testWrongScanID(self): case = utils.match_case('VH014466XK', 'wrong', '') self.assertIsNone(case) def testWrongSerial(self): case = utils.match_case('wrong', '123123', '') self.assertIsNone(case) def testErrorsWithTwoCases(self): self.create_scan_case(self.vscan_user._id, 'VH014466XK', '123123', '2014-03-29T10:48:49Z') self.create_scan_case(self.vscan_user._id, 'VH014466XK', '123123', '2014-03-22T10:48:49Z') self.assertRaises(MultipleResultsFound, lambda: utils.match_case('VH014466XK', '123123', ''))
def testErrorsWithTwoCases(self): self.create_scan_case(self.vscan_user._id, "VH014466XK", "123123", "2014-03-29T10:48:49Z") self.create_scan_case(self.vscan_user._id, "VH014466XK", "123123", "2014-03-22T10:48:49Z") self.assertRaises(MultipleResultsFound, lambda: utils.match_case("VH014466XK", "123123", ""))
def testWrongSerial(self): case = utils.match_case("wrong", "123123", "") self.assertIsNone(case)
def testWrongScanID(self): case = utils.match_case("VH014466XK", "wrong", "") self.assertIsNone(case)
def testFindsCorrectCase(self): case = utils.match_case("VH014466XK", "123123", "") self.assertEqual(self.case_id, case._id)