def test(self):
        resetDb()
        rest = ImagingInterface(isManual=False)

        # empty table
        self.assertIsNone(rest.getAllSubmittedTargets())

        # create one target
        ret = rest.getNextRawImage()
        self.assertIsNotNone(ret)
        resp = rest.postCroppedImage(ret[1], ret[0], [22, 22], [236, 236])
        self.assertIsNotNone(resp)
        self.assertEqual(resp.status_code,
                         200)  # assert successful post to cropped
        cropId = int(resp.headers['X-Crop-Id'])
        classToPost = Classification(cropId, 'standard', 'NE', 'circle',
                                     'white', 'T', 'yellow')
        resp = rest.postClass(classToPost)
        self.assertIsNotNone(resp)
        classId = int(resp.headers['X-Class-Id'])
        modelResult = rest.getClassById(classId)
        self.assertIsNotNone(modelResult)
        targetId = modelResult.target

        # post a second crop and classification which goes to a different target:
        resp = rest.postCroppedImage(ret[1], ret[0], [22, 22], [236, 236])
        self.assertIsNotNone(resp)
        self.assertEqual(resp.status_code,
                         200)  # assert successful post to cropped
        cropId2 = int(resp.headers['X-Crop-Id'])
        # since it's shape is different, this should be a different target
        classToPost = Classification(cropId2, 'standard', 'NE', 'square',
                                     'orange', 'T', 'black')
        resp = rest.postClass(classToPost)
        self.assertIsNotNone(resp)
        classId2 = int(resp.headers['X-Class-Id'])
        modelResult = rest.getClassById(classId2)
        self.assertIsNotNone(modelResult)
        targetId2 = modelResult.target

        self.assertNotEqual(targetId, targetId2)

        self.assertIsNotNone(rest.postSubmitAllTargets())

        resp = rest.getAllSubmittedTargets()
        self.assertIsNotNone(resp)
        self.assertEqual(len(resp), 2)

        if resp[0].target == targetId:
            self.assertEqual(resp[0].crop_id, cropId)
            self.assertEqual(resp[1].crop_id, cropId2)
        elif resp[0].target == targetId2:
            self.assertEqual(resp[0].crop_id, cropId2)
        else:
            self.fail(
                msg=
                "errrmmm. One of the returned target ids does not match what we submitted"
            )
    def test(self):
        resetDb()

        rest = ImagingInterface()
        ret = rest.getNextRawImage()
        self.assertIsNotNone(ret)

        # get stuff into the cropped and classification table
        resp = rest.postCroppedImage(ret[1], ret[0], [22, 22], [236, 236])
        self.assertIsNotNone(resp)
        self.assertEqual(resp.status_code,
                         200)  # assert successful post to cropped
        _, cropId, _ = rest.getNextCroppedImage(
        )  # get the cropId as they would in the gui
        classToPost = Classification(cropId, 'standard', 'NE', 'circle',
                                     'white', 'T', 'yellow')
        resp = rest.postClass(classToPost)
        self.assertIsNotNone(resp)
        classId = int(resp.headers['X-Class-Id'])

        resp = rest.getClassById(classId)
        self.assertIsNotNone(resp)
        self.assertIsInstance(resp, Classification)
        # check data integrity from our previous post
        self.assertEqual(resp.crop_id, cropId)
        self.assertEqual(resp.class_id, classId)
        self.assertEqual(resp.type, 'standard')
        self.assertEqual(resp.orientation, 'NE')
        self.assertEqual(resp.shape, 'circle')
        self.assertEqual(resp.background_color, 'white')
        self.assertEqual(resp.alphanumeric, 'T')
        self.assertEqual(resp.alphanumeric_color, 'yellow')
        self.assertEqual(resp.submitted, 'unsubmitted')
        self.assertEqual(resp.description, '')
        self.assertIsNotNone(resp.target)
    def test(self):
        resetDb()

        rest = ImagingInterface()
        ret = rest.getNextRawImage()
        self.assertIsNotNone(ret)

        resp = rest.postCroppedImage(ret[1], ret[0], [22, 22], [236, 236])
        self.assertIsNotNone(resp)
        self.assertEqual(resp.status_code,
                         200)  # assert successful post to cropped

        _, cropId, _ = rest.getNextCroppedImage(
        )  # get the cropId as they would in the gui

        classToPost = Classification(cropId, 'standard', 'NE', 'circle',
                                     'white', 'T', 'yellow')

        resp = rest.postClass(classToPost)
        self.assertIsNotNone(resp)
        classId = resp.headers['X-Class-Id']
        self.assertIsNotNone(classId)
        self.assertNotEqual(int(classId), -1)

        resp = rest.deleteClass(classId)
        self.assertIsNotNone(resp)
        self.assertEqual(resp.status_code, 200)

        # we should fail to get the classification
        self.assertIsNone(rest.getClassById(classId))
    def test(self):
        resetDb()

        rest = ImagingInterface()

        # should get none when we try and post on empty table
        self.assertIsNone(rest.postSubmitTargetById(100))

        ret = rest.getNextRawImage()
        self.assertIsNotNone(ret)
        resp = rest.postCroppedImage(ret[1], ret[0], [22, 22], [236, 236])
        self.assertIsNotNone(resp)
        self.assertEqual(resp.status_code,
                         200)  # assert successful post to cropped
        cropId = int(resp.headers['X-Crop-Id'])
        classToPost = Classification(cropId, 'standard', 'NE', 'circle',
                                     'white', 'T', 'yellow')
        resp = rest.postClass(classToPost)
        self.assertIsNotNone(resp)
        classId = int(resp.headers['X-Class-Id'])
        modelResult = rest.getClassById(classId)
        self.assertIsNotNone(modelResult)
        targetId = modelResult.target

        # trying to submit an id that doesn't exist should also fail
        self.assertIsNone(rest.postSubmitTargetById(targetId + 20))

        resp = rest.postSubmitTargetById(targetId)
        self.assertIsNotNone(resp)
        self.assertEqual(resp.status_code, 200)

        # confirm that the classification's status has changed to submitted
        modelResult = rest.getClassById(classId)
        self.assertIsNotNone(modelResult)
        self.assertIsNotNone(modelResult.target)
        self.assertEqual(modelResult.submitted, 'submitted')

        # trying to submit the same target again should fail:
        self.assertIsNone(rest.postSubmitTargetById(targetId))
    def test(self):
        resetDb()

        rest = ImagingInterface()
        ret = rest.getNextRawImage()
        self.assertIsNotNone(ret)

        resp = rest.postCroppedImage(ret[1], ret[0], [22, 22], [236, 236])
        self.assertIsNotNone(resp)
        self.assertEqual(resp.status_code,
                         200)  # assert successful post to cropped

        _, cropId, _ = rest.getNextCroppedImage(
        )  # get the cropId as they would in the gui

        classToPost = Classification(cropId, 'standard', 'NE', 'circle',
                                     'white', 'T', 'yellow')

        resp = rest.postClass(classToPost)
        self.assertIsNotNone(resp)
        classId = resp.headers['X-Class-Id']
        self.assertIsNotNone(classId)
        self.assertNotEqual(int(classId), -1)

        # should fail to update stuff that doesn't exist
        stuffToUpdate = Classification(None, None, "SE", "square", None, "Y",
                                       "purple")
        self.assertIsNone(rest.updateClass(int(classId) + 20, stuffToUpdate))

        resp = rest.updateClass(classId, stuffToUpdate)

        # confirm update claims success
        self.assertIsNotNone(resp)
        self.assertEqual(resp.status_code, 200)

        # confirm update was acutlaly successful
        updated = rest.getClassById(classId)
        self.assertIsNotNone(updated)
        self.assertEqual(updated.crop_id, cropId)
        self.assertEqual(updated.type, 'standard')
        self.assertEqual(updated.orientation, 'SE')
        self.assertEqual(updated.shape, 'square')
        self.assertEqual(updated.background_color, 'white')
        self.assertEqual(updated.alphanumeric, "Y")
        self.assertEqual(updated.alphanumeric_color, "purple")
    def test(self):
        resetDb()

        rest = ImagingInterface()

        # empty table
        self.assertIsNone(rest.getSubmittedTargetById(100))

        ret = rest.getNextRawImage()
        self.assertIsNotNone(ret)
        resp = rest.postCroppedImage(ret[1], ret[0], [22, 22], [236, 236])
        self.assertIsNotNone(resp)
        self.assertEqual(resp.status_code,
                         200)  # assert successful post to cropped
        cropId = int(resp.headers['X-Crop-Id'])
        classToPost = Classification(cropId, 'standard', 'NE', 'circle',
                                     'white', 'T', 'yellow')
        resp = rest.postClass(classToPost)
        self.assertIsNotNone(resp)
        classId = int(resp.headers['X-Class-Id'])
        modelResult = rest.getClassById(classId)
        self.assertIsNotNone(modelResult)
        targetId = modelResult.target

        # should still be none since the target is unsubmitted
        self.assertIsNone(rest.getSubmittedTargetById(targetId))

        # submit the target
        resp = rest.postSubmitTargetById(targetId)
        self.assertIsNotNone(resp)

        # now lets see if the getter works:
        resp = rest.getSubmittedTargetById(targetId)
        self.assertIsNotNone(resp)
        self.assertIsInstance(resp, Classification)
        self.assertEqual(resp.target, targetId)
        self.assertEqual(resp.crop_id, cropId)
        self.assertEqual(resp.type, 'standard')
        self.assertEqual(resp.shape, 'circle')
        self.assertEqual(resp.orientation, 'NE')
        self.assertEqual(resp.background_color, 'white')
        self.assertEqual(resp.alphanumeric, 'T')
        self.assertEqual(resp.alphanumeric_color, 'yellow')
        self.assertEqual(resp.submitted, 'pending')