Пример #1
0
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
Пример #2
0
    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)
Пример #3
0
    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)
Пример #4
0
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
Пример #5
0
    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', ''))
Пример #6
0
    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)
Пример #7
0
    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', '')
        )
Пример #8
0
 def testWrongSerial(self):
     case = utils.match_case('wrong', '123123', '')
     self.assertIsNone(case)
Пример #9
0
 def testWrongScanID(self):
     case = utils.match_case('VH014466XK', 'wrong', '')
     self.assertIsNone(case)
Пример #10
0
 def testFindsCorrectCase(self):
     case = utils.match_case('VH014466XK', '123123', '')
     self.assertEqual(self.case_id, case._id)
Пример #11
0
class ScanLookupTests(UTHTests):
    def testFindsCorrectCase(self):
        case = utils.match_case('VH014466XK', '123123', '')
        self.assertEqual(self.case_id, case._id)
Пример #12
0
        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', ''))
Пример #13
0
    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", ""))
Пример #14
0
 def testWrongSerial(self):
     case = utils.match_case("wrong", "123123", "")
     self.assertIsNone(case)
Пример #15
0
 def testWrongScanID(self):
     case = utils.match_case("VH014466XK", "wrong", "")
     self.assertIsNone(case)
Пример #16
0
 def testFindsCorrectCase(self):
     case = utils.match_case("VH014466XK", "123123", "")
     self.assertEqual(self.case_id, case._id)