Пример #1
0
    def test(self):
        truncateTable('submitted_target')
        dao = SubmittedTargetDAO(defaultConfigPath())

        testIns = submitted_target()
        testIns.shape = 'square'
        testIns.type = 'standard'
        testIns.crop_path = '/another/totally/real/crop/path/ikr.jpg'
        testIns.background_color = 'white'
        testIns.alphanumeric = "T"
        testIns.alphanumeric_color = "orange"
        testIns.autonomous = False
        testIns.target = 10

        self.assertNotEqual(dao.upsertTarget(testIns), -1)

        resultingModel = dao.getTarget(10, False)

        self.assertIsNotNone(resultingModel)
        self.assertEqual(resultingModel.target, 10)
        self.assertFalse(resultingModel.autonomous)
        self.assertEqual(resultingModel.type, 'standard')
        self.assertEqual(resultingModel.crop_path,
                         '/another/totally/real/crop/path/ikr.jpg')
        self.assertEqual(resultingModel.shape, 'square')
        self.assertEqual(resultingModel.background_color, 'white')
        self.assertEqual(resultingModel.alphanumeric, 'T')
        self.assertEqual(resultingModel.alphanumeric_color, 'orange')
        self.assertEqual(resultingModel.submitted, 'pending')
        self.assertIsNone(resultingModel.latitude)
        self.assertIsNone(resultingModel.longitude)
        self.assertIsNone(resultingModel.orientation)
Пример #2
0
    def test(self):
        model = incoming_image()
        model.time_stamp = 1547453775.2
        model.focal_length = 16.0
        model.image_path = '/im/a/totally/real/path/i/swear.jpg'
        model.manual_tap = False
        model.autonomous_tap = False

        truncateTable('incoming_image')
        dao = IncomingImageDAO(defaultConfigPath())
        self.assertIsNotNone(dao)

        # test with empty table

        self.assertIsNone(dao.getImage(1))

        resultingId = dao.addImage(model)
        self.assertNotEqual(resultingId, -1)

        resultingModel = dao.getImage(resultingId)

        self.assertIsNotNone(resultingModel)
        self.assertAlmostEqual(resultingModel.time_stamp, model.time_stamp)
        self.assertEqual(resultingModel.focal_length, model.focal_length)
        self.assertEqual(resultingModel.image_path, model.image_path)
        self.assertEqual(resultingModel.manual_tap, model.manual_tap)
        self.assertEqual(resultingModel.autonomous_tap, model.autonomous_tap)
Пример #3
0
    def test(self):
        truncateTable('submitted_target')
        dao = SubmittedTargetDAO(defaultConfigPath())

        # none should fail to insert
        result = dao.upsertTarget(None)
        self.assertIsNotNone(result)
        self.assertEqual(result, -1)

        testIns = submitted_target()
        testIns.shape = 'square'
        testIns.type = 'standard'
        testIns.crop_path = '/another/totally/real/crop/path/ikr.jpg'
        testIns.background_color = 'white'
        testIns.alphanumeric = "T"
        testIns.alphanumeric_color = "orange"

        # should fail when we try and upsert an image that doesn't have a target or autonomous field
        self.assertEqual(dao.upsertTarget(testIns), -1)

        testIns.autonomous = False
        # should fail when we try and upsert an image that doesn't have a target field
        self.assertEqual(dao.upsertTarget(testIns), -1)

        testIns.target = 10
        self.assertNotEqual(dao.upsertTarget(testIns), -1)
Пример #4
0
    def test(self):
        truncateTable('outgoing_manual')
        dao = OutgoingManualDAO(defaultConfigPath())

        # see how it works on an empty table
        self.assertIsNone(dao.submitAllPendingTargets())

        # this will insert records for 2 different targets from 3 classifications:
        testIns = outgoing_manual()
        testIns.crop_id = 42
        testIns.shape = 'circle'
        testIns.background_color = 'white'
        testIns.alphanumeric = 'A'
        testIns.alphanumeric_color = 'black'
        dao.addClassification(testIns)

        testIns.crop_id = 43
        dao.addClassification(testIns)

        testIns.crop_id = 44
        testIns.alphanumeric = 'C'
        testIns.submitted = 'submitted'  # this wont work -> it should still be unsubmitted
        dao.addClassification(testIns)

        result = dao.submitAllPendingTargets()
        self.assertIsNotNone(result)
        self.assertEqual(len(result), 2)  # should have 2 targets
Пример #5
0
    def test(self):
        testIns = outgoing_manual()
        testIns.crop_id = 42
        testIns.type = 'standard'
        testIns.orientation = 'NE'
        testIns.shape = 'star'
        testIns.background_color = 'blue'
        testIns.alphanumeric = 'A'
        testIns.alphanumeric_color = 'purple'
        testIns.latitude  = 40.11111
        testIns.longitude = -111.222222

        truncateTable('outgoing_manual')
        dao = OutgoingManualDAO(defaultConfigPath())

        id = dao.addClassification(testIns)
        self.assertNotEqual(id, -1)

        model = dao.getClassification(id)
        self.assertIsNotNone(model)

        classOut = dao.submitPendingTarget(model.target)
        self.assertIsNotNone(classOut)

        imgPath = os.path.dirname(os.path.realpath(__file__)) + '/assets/star.png'
        
        targetOut = submitted_target(outgoingManualOrAutonomous=classOut, autonomous_in=False)
        targetOut.crop_path = imgPath
        auvsiDao = AuvsiOdlcDao()
        auvsiDao.addTarget(targetOut)
Пример #6
0
    def test(self):
        # insert some targets
        dao = OutgoingManualDAO(defaultConfigPath())

        truncateTable('outgoing_manual')
        # see what it does with an empty table:
        self.assertIsNone(dao.submitPendingTarget(1))

        testIns = outgoing_manual()
        testIns.crop_id = 42
        testIns.latitude = 40.111
        testIns.longitude = -111.111
        testIns.orientation = 'N'
        testIns.shape = 'circle'
        testIns.background_color = 'white'
        testIns.alphanumeric = 'A'
        testIns.alphanumeric_color = 'black'
        self.assertIsNot(dao.addClassification(testIns), -1)

        testIns.crop_id = 43
        testIns.latitude = 40.222
        testIns.longitude = -111.222
        testIns.orientation = 'NE'
        testIns.background_color = 'orange'
        self.assertIsNot(dao.addClassification(testIns), -1)

        testIns.crop_id = 44
        testIns.latitude = 40.333
        testIns.longitude = -111.333
        testIns.alphanumeric_color = 'white'
        resultingId = dao.addClassification(testIns)
        self.assertIsNot(resultingId, -1)

        classResult = dao.getClassification(resultingId)
        submissionResult = dao.submitPendingTarget(classResult.target)

        self.assertAlmostEqual(submissionResult.latitude, 40.222)
        self.assertAlmostEqual(submissionResult.longitude, -111.222)
        self.assertEqual(submissionResult.orientation, 'NE')
        self.assertEqual(submissionResult.background_color, 'orange')
        self.assertEqual(submissionResult.alphanumeric_color, 'black')
        self.assertEqual(submissionResult.alphanumeric, 'A')
        self.assertEqual(submissionResult.shape, 'circle')

        # make sure that when we submit another classification that belongs
        # to the same target that its submitted state automatically goes to
        # 'inherited_submission'
        testIns.crop_id = 45
        resultingId = dao.addClassification(testIns)
        self.assertNotEqual(resultingId, -1)
        classResult = dao.getClassification(resultingId)
        self.assertIsNotNone(classResult)
        self.assertEqual(classResult.submitted, 'inherited_submission')
Пример #7
0
    def test(self):
        truncateTable('incoming_image')
        dao = IncomingImageDAO(defaultConfigPath())
        self.assertIsNotNone(dao)

        # test with empty table
        self.assertIsNone(dao.getNextImage(True))
        self.assertIsNone(dao.getNextImage(False))

        model = incoming_image()
        model.time_stamp = 1547453775.2
        model.focal_length = 16.0
        model.image_path = '/im/a/totally/real/path/i/swear.jpg'
        model.manual_tap = False
        model.autonomous_tap = False
        resultingId = dao.addImage(model)
        self.assertNotEqual(resultingId, -1)

        # identical timestamps should make no difference
        model.focal_length = 16.0
        model.image_path = '/im/a/totally/real/path/2/i/swear.jpg'
        resultingId2 = dao.addImage(model)
        self.assertNotEqual(resultingId2, -1)

        resultModel = dao.getNextImage(True)
        self.assertIsNotNone(resultModel)
        self.assertEqual(resultModel.image_id, resultingId)
        self.assertTrue(resultModel.manual_tap)
        self.assertFalse(resultModel.autonomous_tap)

        resultModel = dao.getNextImage(True)
        self.assertIsNotNone(resultModel)
        self.assertEqual(resultModel.image_id, resultingId2)
        self.assertTrue(resultModel.manual_tap)
        self.assertFalse(resultModel.autonomous_tap)

        resultModel = dao.getNextImage(False)
        self.assertIsNotNone(resultModel)
        self.assertEqual(resultModel.image_id, resultingId)
        self.assertTrue(resultModel.manual_tap)
        self.assertTrue(resultModel.autonomous_tap)

        resultModel = dao.getNextImage(True)
        self.assertIsNone(resultModel)

        resultModel = dao.getNextImage(False)
        self.assertIsNotNone(resultModel)
        self.assertEqual(resultModel.image_id, resultingId2)
        self.assertTrue(resultModel.manual_tap)
        self.assertTrue(resultModel.autonomous_tap)

        resultModel = dao.getNextImage(False)
        self.assertIsNone(resultModel)
Пример #8
0
    def test(self):
        model = incoming_state()
        model.time_stamp = 1547453775.2
        model.roll = 40.111
        model.pitch = -111.222
        model.yaw = 12.3

        truncateTable('incoming_state')
        dao = IncomingStateDAO(defaultConfigPath())
        self.assertIsNotNone(dao)
        resultingId = dao.addState(model)
        self.assertIsNotNone(resultingId)
        self.assertNotEqual(resultingId, -1)
Пример #9
0
    def test(self):
        model = incoming_gps()
        model.time_stamp = 1547453775.2
        model.lat = 40.111
        model.lon = -111.222
        model.alt = 1234.5

        truncateTable('incoming_gps')
        dao = IncomingGpsDAO(defaultConfigPath())

        resultingId = dao.addGps(model)
        self.assertIsNotNone(resultingId)
        self.assertNotEqual(resultingId, -1)
Пример #10
0
    def test(self):
        # Note: the closest TS function doesnt work by absolute closest,
        # but instead for ease, speed and readability, just checks <= 
        # These tests reflect this type of functionality and would probably have
        # to be redone if true closest TS was ever implemented

        truncateTable('incoming_gps')
        dao = IncomingGpsDAO(defaultConfigPath())
        self.assertIsNotNone(dao)

        baseTs = 1547453775.2
        # test on empty table
        resultModel = dao.getGpsByClosestTS(baseTs)
        self.assertIsNone(resultModel)
        
        model = incoming_gps()
        model.time_stamp = baseTs
        model.lat = 40.111
        model.lon = -111.222
        model.alt = 1234.5
        resultingId1 = dao.addGps(model)
        self.assertNotEqual(resultingId1, -1)

        model.time_stamp = baseTs + 20000
        model.lat = 40.222
        model.lon = -111.333
        model.alt = 5678.9
        resultingId2 = dao.addGps(model)
        self.assertNotEqual(resultingId2, -1)

        # as explained above, this should return None
        resultModel = dao.getGpsByClosestTS(baseTs - 10000)
        self.assertIsNone(resultModel)

        resultModel = dao.getGpsByClosestTS(baseTs + 1000)
        self.assertIsNotNone(resultModel)
        self.assertEqual(resultModel.id, resultingId1)

        # while this is absolutely closer to id2, we should
        # still get id1 for the spec reasons described at the 
        # top of this method
        resultModel = dao.getGpsByClosestTS(baseTs + 15000)
        self.assertIsNotNone(resultModel)
        self.assertEqual(resultModel.id, resultingId1)

        # test when time is exactly equal
        resultModel = dao.getGpsByClosestTS(baseTs + 20000)
        self.assertIsNotNone(resultModel)
        self.assertEqual(resultModel.id, resultingId2)
Пример #11
0
    def test(self):
        truncateTable('outgoing_manual')
        dao = OutgoingManualDAO(defaultConfigPath())

        testIns = outgoing_manual()
        testIns.crop_id = 42
        testIns.shape = 'circle'
        testIns.background_color = 'white'
        testIns.alphanumeric = 'A'
        testIns.alphanumeric_color = 'black'
        self.assertNotEqual(dao.addClassification(testIns), -1)

        # should now fail to insert a duplicate crop_id
        self.assertEqual(dao.addClassification(testIns), -1)
        self.assertIsNotNone(dao.getClassificationByUID(42))
Пример #12
0
    def test(self):
        truncateTable("incoming_gps")
        dao = IncomingGpsDAO(defaultConfigPath())

        # empty table
        self.assertIsNone(dao.getAll())

        # insert a couple rows
        model = incoming_gps()
        baseTs = 1547453775.2
        model.time_stamp = baseTs
        model.lat = 40.111
        model.lon = -111.222
        model.alt = 1234.5
        resultingId1 = dao.addGps(model)
        self.assertNotEqual(resultingId1, -1)

        model.time_stamp = baseTs + 20000
        model.lat = 40.222
        model.lon = -111.333
        model.alt = 5678.9
        resultingId2 = dao.addGps(model)
        self.assertNotEqual(resultingId2, -1)

        results = dao.getAll()
        self.assertIsNotNone(results) 
        self.assertEqual(len(results), 2)

        if results[0].id == resultingId1:
            self.assertAlmostEqual(results[0].lat, 40.111)
            self.assertAlmostEqual(results[0].lon, -111.222)
            self.assertAlmostEqual(results[0].alt, 1234.5)

            self.assertAlmostEqual(results[1].lat, 40.222)
            self.assertAlmostEqual(results[1].lon, -111.333)
            self.assertAlmostEqual(results[1].alt, 5678.9)
        
        elif results[0].id == resultingId2:
            self.assertAlmostEqual(results[1].lat, 40.111)
            self.assertAlmostEqual(results[1].lon, -111.222)
            self.assertAlmostEqual(results[1].alt, 1234.5)

            self.assertAlmostEqual(results[0].lat, 40.222)
            self.assertAlmostEqual(results[0].lon, -111.333)
            self.assertAlmostEqual(results[0].alt, 5678.9)
        
        else:
            self.fail("dont recognize one of the ids returned by gps.getAll")
Пример #13
0
    def test(self):
        truncateTable('outgoing_autonomous')
        dao = OutgoingAutonomousDAO(defaultConfigPath())

        testIns = outgoing_autonomous()
        testIns.crop_id = 42
        testIns.shape = 'circle'
        testIns.background_color = 'white'
        testIns.alphanumeric = 'A'
        testIns.alphanumeric_color = 'black'
        resultingId = dao.addClassification(testIns)
        self.assertNotEqual(resultingId, -1)

        # should not be able to insert a duplicate record
        self.assertEqual(dao.addClassification(testIns), -1)
        self.assertIsNotNone(dao.getClassification(resultingId))
Пример #14
0
def setupClientRestTestDb():
    # truncate all the tables:
    truncateTable('incoming_image')
    truncateTable('incoming_gps')
    truncateTable('incoming_state')
    truncateTable('outgoing_manual')
    truncateTable('outgoing_autonomous')

    # figure out the absolute path to our raw test image:
    rawImg = os.path.abspath(
        os.path.dirname(os.path.realpath(__file__)) +
        '/test/assets/rawFrame.jpg')

    # setup incoming tables
    setupIncomingImageTable(rawImg)
    setupIncomingGpsTable()
    setupIncomingStateTable()
Пример #15
0
    def test(self):
        truncateTable('submitted_target')
        dao = SubmittedTargetDAO(defaultConfigPath())

        # empty table
        self.assertIsNone(dao.getAllTargets(False))
        self.assertIsNone(dao.getAllTargets(True))

        testIns = submitted_target()
        testIns.shape = 'square'
        testIns.type = 'standard'
        testIns.crop_path = '/another/totally/real/crop/path/ikr.jpg'
        testIns.background_color = 'white'
        testIns.alphanumeric = "T"
        testIns.alphanumeric_color = "orange"
        testIns.autonomous = False
        testIns.target = 10
        self.assertNotEqual(dao.upsertTarget(testIns), -1)

        testIns.shape = 'circle'
        testIns.target = 15
        self.assertNotEqual(dao.upsertTarget(testIns), -1)

        testIns.autonomous = True
        testIns.alphanumeric = "Y"
        testIns.alphanumeric_color = 'purple'
        self.assertNotEqual(dao.upsertTarget(testIns), -1)

        targetList = dao.getAllTargets(False)

        self.assertIsNotNone(targetList)
        self.assertEqual(len(targetList), 2)
        # spot check a couple values to confirm the thing was really added to list properly
        self.assertEqual(targetList[0].type, 'standard')
        self.assertEqual(targetList[1].type, 'standard')
        self.assertEqual(targetList[0].crop_path,
                         '/another/totally/real/crop/path/ikr.jpg')
        self.assertEqual(targetList[1].crop_path,
                         '/another/totally/real/crop/path/ikr.jpg')
        self.assertFalse(targetList[0].autonomous)
        self.assertFalse(targetList[1].autonomous)

        # get the one autonomous target
        targetList = dao.getAllTargets(True)
        self.assertIsNotNone(targetList)
        self.assertEqual(len(targetList), 1)
Пример #16
0
    def test(self):
        truncateTable("cropped_manual")
        dao = CroppedManualDAO(defaultConfigPath())

        model = cropped_manual()
        model.image_id = 123
        model.time_stamp = 1547453775.2
        model.cropped_path = '/im/a/totally/real/cropped/path/i/swear.jpg'
        model.crop_coordinate_br = "(12,34)"
        model.crop_coordinate_tl = "(56,78)"
        resultingId = dao.upsertCropped(model)
        self.assertNotEqual(resultingId, -1)

        updateContent = {
            "time_stamp": model.time_stamp + 1000,
            "image_id": 456
        }

        # confirm update to bad id does nothing
        self.assertIsNone(dao.updateImage(resultingId + 20, updateContent))

        resultingModel = dao.getImage(resultingId)
        # confirm that nothing was changed in our one row:
        self.assertIsNotNone(resultingModel)
        self.assertEqual(resultingId, resultingModel.crop_id)
        self.assertEqual(model.time_stamp, resultingModel.time_stamp)
        self.assertEqual(model.image_id, resultingModel.image_id)
        self.assertEqual(model.cropped_path, resultingModel.cropped_path)
        self.assertEqual(model.crop_coordinate_br.__str__(),
                         resultingModel.crop_coordinate_br.__str__())
        self.assertEqual(model.crop_coordinate_tl.__str__(),
                         resultingModel.crop_coordinate_tl.__str__())
        self.assertFalse(resultingModel.tapped)

        # do a legit update now:
        resultingModel = dao.updateImage(resultingId, updateContent)
        self.assertIsNotNone(resultingModel)
        self.assertEqual(resultingId, resultingModel.crop_id)
        self.assertEqual(resultingModel.image_id, 456)
        self.assertEqual(model.time_stamp + 1000, resultingModel.time_stamp)
        self.assertEqual(model.cropped_path, resultingModel.cropped_path)
        self.assertEqual(model.crop_coordinate_br.__str__(),
                         resultingModel.crop_coordinate_br.__str__())
        self.assertEqual(model.crop_coordinate_tl.__str__(),
                         resultingModel.crop_coordinate_tl.__str__())
        self.assertFalse(resultingModel.tapped)
Пример #17
0
    def test(self):
        """
        Currently the method that we're testing here isnt used by the api, but
        its good to test andways since it exists, and is pretty basic - meaning it
        will catch some simpler errors before we go to the complicated ones
        """
        model = cropped_manual()
        model.image_id = 123
        model.time_stamp = 1547453775.2
        model.cropped_path = '/im/a/totally/real/cropped/path/i/swear.jpg'

        truncateTable('cropped_manual')
        dao = CroppedManualDAO(defaultConfigPath())

        self.assertEqual(dao.addImage(None), -1)

        resultingId = dao.addImage(model)
        self.assertIsNotNone(resultingId)
        self.assertNotEqual(resultingId, -1)
Пример #18
0
    def test(self):
        truncateTable('cropped_manual')
        dao = CroppedManualDAO(defaultConfigPath())

        self.assertIsNone(dao.getNextImage())

        model = cropped_manual()
        model.image_id = 123
        model.time_stamp = 1547453775.2
        model.cropped_path = '/im/a/totally/real/cropped/path/i/swear.jpg'
        model.crop_coordinate_br = "(12,34)"
        model.crop_coordinate_tl = "(56,78)"
        resultingId = dao.upsertCropped(model)
        self.assertNotEqual(resultingId, -1)

        model.cropped_path = '/im/a/totally/real/cropped/path/2/i/swear.jpg'
        model.image_id = 456
        resultingId2 = dao.upsertCropped(model)
        self.assertNotEqual(resultingId2, -1)

        resultModel = dao.getNextImage()
        self.assertIsNotNone(resultModel)
        self.assertEqual(resultModel.crop_id, resultingId)
        self.assertTrue(resultModel.tapped)
        self.assertEqual(resultModel.image_id, 123)
        self.assertEqual(resultModel.crop_coordinate_tl.__str__(),
                         model.crop_coordinate_tl)
        self.assertEqual(resultModel.crop_coordinate_br.__str__(),
                         model.crop_coordinate_br)

        resultModel = dao.getNextImage()
        self.assertIsNotNone(resultModel)
        self.assertEqual(resultModel.crop_id, resultingId2)
        self.assertTrue(resultModel.tapped)
        self.assertEqual(resultModel.image_id, model.image_id)
        self.assertEqual(resultModel.cropped_path, model.cropped_path)
        self.assertEqual(resultModel.crop_coordinate_tl.__str__(),
                         model.crop_coordinate_tl)
        self.assertEqual(resultModel.crop_coordinate_br.__str__(),
                         model.crop_coordinate_br)

        self.assertIsNone(dao.getNextImage())
Пример #19
0
    def test(self):
        model = incoming_state()
        model.time_stamp = 1547453775.2
        model.roll = 40.111
        model.pitch = -111.222
        model.yaw = 12.3

        truncateTable('incoming_state')
        dao = IncomingStateDAO(defaultConfigPath())
        self.assertIsNotNone(dao)
        resultingId = dao.addState(model)
        self.assertNotEqual(resultingId, -1)

        gottenMeas = dao.getStateById(resultingId)
        self.assertIsNotNone(gottenMeas)

        self.assertEqual(gottenMeas.id, resultingId)
        self.assertAlmostEqual(gottenMeas.time_stamp, 1547453775.2)
        self.assertAlmostEqual(gottenMeas.roll, 40.111)
        self.assertAlmostEqual(gottenMeas.pitch, -111.222)
        self.assertAlmostEqual(gottenMeas.yaw, 12.3)
Пример #20
0
    def test(self):
        model = incoming_gps()
        model.time_stamp = 1547453775.2
        model.lat = 40.111
        model.lon = -111.222
        model.alt = 1234.5

        truncateTable('incoming_gps')
        dao = IncomingGpsDAO(defaultConfigPath())
        self.assertIsNotNone(dao)
        resultingId = dao.addGps(model)
        self.assertNotEqual(resultingId, -1)

        gottenMeas = dao.getGpsById(resultingId)
        self.assertIsNotNone(gottenMeas)

        self.assertEqual(gottenMeas.id, resultingId)
        self.assertAlmostEqual(gottenMeas.time_stamp, 1547453775.2)
        self.assertAlmostEqual(gottenMeas.lat, 40.111)
        self.assertAlmostEqual(gottenMeas.lon, -111.222)
        self.assertAlmostEqual(gottenMeas.alt, 1234.5)
Пример #21
0
    def test(self):
        truncateTable('outgoing_manual')

        dao = OutgoingManualDAO(defaultConfigPath())

        testIns = outgoing_manual()
        testIns.crop_id = 42
        testIns.shape = 'circle'
        testIns.background_color = 'white'
        testIns.alphanumeric = 'A'
        testIns.alphanumeric_color = 'black'

        resultingId = dao.addClassification(testIns)
        self.assertNotEqual(resultingId, -1)
        insResult = dao.getClassification(resultingId)
        self.assertIsNotNone(insResult.target)
        self.assertNotEqual(insResult.target, -1)

        testIns.crop_id = 43
        resultingId = dao.addClassification(testIns)
        self.assertNotEqual(resultingId, -1)
        insResult2 = dao.getClassification(resultingId)
        self.assertEqual(insResult.target, insResult2.target)

        testIns.crop_id = 44
        testIns.alphanumeric = 'C'
        testIns.submitted = 'submitted'  # this wont work -> it should still be unsubmitted
        resultingId = dao.addClassification(testIns)
        self.assertNotEqual(resultingId, -1)
        insResult3 = dao.getClassification(resultingId)
        self.assertNotEqual(insResult3.target, insResult2.target)

        # the target id should change on this update
        testIns.crop_id = 42
        testIns.alphanumeric = 'C'
        testIns.submitted = 'unsubmitted'
        result = dao.updateClassificationByUID(testIns.crop_id,
                                               testIns.toDict())
        self.assertNotEqual(result.class_id, -1)
        self.assertEqual(result.target, insResult3.target)
Пример #22
0
    def test(self):
        truncateTable('submitted_target')
        dao = SubmittedTargetDAO(defaultConfigPath())

        self.assertFalse(dao.removeTarget(10, False))
        self.assertFalse(dao.removeTarget(10, True))

        testIns = submitted_target()
        testIns.shape = 'square'
        testIns.type = 'standard'
        testIns.crop_path = '/another/totally/real/crop/path/ikr.jpg'
        testIns.background_color = 'white'
        testIns.alphanumeric = "T"
        testIns.alphanumeric_color = "orange"
        testIns.autonomous = False
        testIns.target = 10
        self.assertNotEqual(dao.upsertTarget(testIns), -1)

        testIns.shape = 'circle'
        testIns.target = 15
        self.assertNotEqual(dao.upsertTarget(testIns), -1)

        self.assertFalse(dao.removeTarget(10, True))
        self.assertFalse(dao.removeTarget(12, False))
        self.assertTrue(dao.removeTarget(10, False))

        # confirm it got deleted
        self.assertIsNone(dao.getTarget(10, False))
        targetList = dao.getAllTargets(False)
        self.assertIsNotNone(targetList)
        self.assertEqual(len(targetList), 1)
        self.assertEqual(targetList[0].target, 15)
        self.assertEqual(targetList[0].shape, 'circle')

        self.assertTrue(dao.removeTarget(15, False))
        # confirm the table is now empty
        self.assertIsNone(dao.getAllTargets(False))
        self.assertIsNone(dao.getAllTargets(True))
Пример #23
0
    def test(self):
        # insert some targets
        dao = OutgoingManualDAO(defaultConfigPath())

        truncateTable('outgoing_manual')

        # make sure if fails when we try and remove on empty table:
        deleteResult = dao.removeClassification(100)
        self.assertFalse(deleteResult)

        testIns = outgoing_manual()
        testIns.crop_id = 42
        testIns.latitude = 40.111
        testIns.longitude = -111.111
        testIns.orientation = 'N'
        testIns.shape = 'circle'
        testIns.background_color = 'white'
        testIns.alphanumeric = 'A'
        testIns.alphanumeric_color = 'black'
        resultingId = dao.addClassification(testIns)
        self.assertIsNot(resultingId, -1)

        testIns.crop_id = 44
        otherId = dao.addClassification(testIns)
        self.assertNotEqual(otherId, -1)

        # make sure it doesn't delete everything:
        deleteResult = dao.removeClassification(
            otherId + 5)  # give bogus id that should fail
        self.assertFalse(deleteResult)
        self.assertEqual(len(dao.getAll()),
                         2)  # make sure there's still 2 records

        deleteResult = dao.removeClassification(resultingId)
        self.assertTrue(deleteResult)
        self.assertEqual(len(dao.getAll()), 1)  # should still be 1 record left
        self.assertIsNotNone(dao.getClassification(
            otherId))  # make sure the otherId wasn't deleted on accident
Пример #24
0
    def test(self):
        model = cropped_manual()
        model.image_id = 123
        model.time_stamp = 1547453775.2
        model.cropped_path = '/im/a/totally/real/cropped/path/i/swear.jpg'
        model.crop_coordinate_br = "(12, 34)"
        model.crop_coordinate_tl = "(56, 78)"

        truncateTable('cropped_manual')
        dao = CroppedManualDAO(defaultConfigPath())

        self.assertEqual(dao.upsertCropped(None), -1)
        self.assertEqual(dao.upsertCropped(cropped_manual()), -1)

        resultingId = dao.upsertCropped(model)
        self.assertIsNotNone(resultingId)
        self.assertNotEqual(resultingId, -1)

        model.crop_coordinate_br = "(56, 78)"
        model.crop_id = resultingId
        resultingId2 = dao.upsertCropped(model)
        self.assertNotEqual(resultingId2, -1)
        self.assertEqual(resultingId, resultingId2)
Пример #25
0
    def test(self):
        truncateTable('cropped_manual')
        dao = CroppedManualDAO(defaultConfigPath())

        self.assertEqual(dao.getAll(), [])

        model = cropped_manual()
        model.image_id = 123
        model.time_stamp = 1547453775.2
        model.cropped_path = '/im/a/totally/real/cropped/path/i/swear.jpg'
        model.crop_coordinate_br = "(12,34)"
        model.crop_coordinate_tl = "(56,78)"
        resultingId = dao.upsertCropped(model)
        self.assertNotEqual(resultingId, -1)

        model.cropped_path = '/im/a/totally/real/cropped/path/2/i/swear.jpg'
        model.image_id = 456
        resultingId2 = dao.upsertCropped(model)
        self.assertNotEqual(resultingId2, -1)

        result = dao.getAll()

        self.assertEqual(len(result), 2)
Пример #26
0
    def test(self):
        truncateTable('outgoing_autonomous')
        dao = OutgoingAutonomousDAO(defaultConfigPath())

        # empty table
        self.assertIsNone(dao.getUnlocatedClassifications())

        # populate with two classifications that need geo, one that doesnt
        testIns = outgoing_manual()
        testIns.crop_id = 42
        testIns.shape = 'circle'
        testIns.background_color = 'white'
        testIns.alphanumeric = 'A'
        testIns.alphanumeric_color = 'black'

        resultingId = dao.addClassification(testIns)
        self.assertNotEqual(resultingId, -1)

        testIns.crop_id = 43
        testIns.background_color = 'orange'
        resultingId2 = dao.addClassification(testIns)
        self.assertNotEqual(resultingId2, -1)

        testIns.crop_id = 44
        testIns.latitude = 40.111
        testIns.longitude = -111.222
        resultingId3 = dao.addClassification(testIns)
        self.assertNotEqual(resultingId3, -1)

        unlocated = dao.getUnlocatedClassifications()
        self.assertIsNotNone(unlocated)
        self.assertEqual(len(unlocated), 2)
        # the two models in the list should be our first two inserts and have
        # crop ids 42 and 43
        self.assertLess(unlocated[0].crop_id, 44)
        self.assertLess(unlocated[1].crop_id, 44)
Пример #27
0
    def test(self):
        truncateTable('incoming_image')
        truncateTable('cropped_autonomous')
        truncateTable('outgoing_autonomous')
        dao = OutgoingAutonomousDAO(defaultConfigPath())

        testIns = outgoing_autonomous()
        testIns.crop_id = 42
        testIns.shape = 'circle'
        testIns.background_color = 'white'
        testIns.alphanumeric = 'A'
        testIns.alphanumeric_color = 'black'
        self.assertNotEqual(dao.addClassification(testIns), -1)

        dao = CroppedAutonomousDAO(defaultConfigPath())
        model = cropped_autonomous()
        model.image_id = 123
        model.time_stamp = 1547453775.2
        model.cropped_path = '/im/a/totally/real/cropped/path/i/swear.jpg'
        model.crop_coordinate_br = "(12, 34)"
        model.crop_coordinate_tl = "(56, 78)"
        self.assertNotEqual(dao.addImage(model), -1)

        dao = IncomingImageDAO(defaultConfigPath())
        model = incoming_image()
        model.time_stamp = 1547453775.2
        model.focal_length = 16.0
        model.image_path = '/im/a/totally/real/path/i/swear.jpg'
        model.manual_tap = True
        model.autonomous_tap = True
        resultingId = dao.addImage(model)
        self.assertNotEqual(resultingId, -1)

        util = UtilDAO(defaultConfigPath())
        util.resetAutonomousDB()

        resultingModel = dao.getImage(resultingId)
        self.assertIsNotNone(resultingModel)
        self.assertFalse(resultingModel.autonomous_tap)
        self.assertTrue(resultingModel.manual_tap)
        self.assertEqual(resultingModel.image_path, model.image_path)
        self.assertEqual(resultingModel.focal_length, model.focal_length)

        dao = CroppedAutonomousDAO(defaultConfigPath())
        self.assertEqual(len(dao.getAll()), 0)

        dao = OutgoingAutonomousDAO(defaultConfigPath())
        self.assertEqual(len(dao.getAll()), 0)
Пример #28
0
    def test(self):
        truncateTable('outgoing_manual')
        dao = OutgoingManualDAO(defaultConfigPath())

        # at this point we should've already passed a bunch of tests
        # relating to target submission above, so we can just test the
        # classification specification feature here

        testIns = outgoing_manual()
        testIns.crop_id = 42
        testIns.latitude = 40.111
        testIns.longitude = -111.111
        testIns.orientation = 'N'
        testIns.shape = 'circle'
        testIns.background_color = 'white'
        testIns.alphanumeric = 'A'
        testIns.alphanumeric_color = 'black'
        firstClass = dao.addClassification(testIns)
        self.assertNotEqual(firstClass, -1)

        testIns.crop_id = 43
        testIns.latitude = 40.222
        testIns.longitude = -111.222
        testIns.orientation = 'NE'
        testIns.background_color = 'orange'
        secondClass = dao.addClassification(testIns)
        self.assertNotEqual(secondClass, -1)

        testIns.crop_id = 44
        testIns.latitude = 40.333
        testIns.longitude = -111.333
        testIns.alphanumeric_color = 'white'
        thirdClass = dao.addClassification(testIns)
        self.assertNotEqual(thirdClass, -1)

        specs = {
            'orientation': secondClass,
            'crop_id': firstClass,
            'alphanumeric_color': thirdClass
        }

        classResult = dao.getClassification(secondClass)
        submissionResult = dao.submitPendingTarget(classResult.target, specs)

        self.assertIsNotNone(submissionResult)

        self.assertEqual(submissionResult.orientation, 'NE')
        self.assertEqual(submissionResult.crop_id, 42)
        self.assertEqual(submissionResult.alphanumeric_color, 'white')
        self.assertEqual(submissionResult.background_color, 'orange')
        self.assertEqual(submissionResult.alphanumeric, 'A')

        truncateTable('outgoing_manual')
        ############################################
        # test what happens when we put garbage in specs:
        ############################################
        testIns = outgoing_manual()
        testIns.crop_id = 42
        testIns.latitude = 40.111
        testIns.longitude = -111.111
        testIns.orientation = 'S'
        testIns.shape = 'circle'
        testIns.background_color = 'white'
        testIns.alphanumeric = 'Q'
        testIns.alphanumeric_color = 'black'
        self.assertNotEqual(dao.addClassification(testIns), -1)

        testIns.crop_id = 43
        testIns.latitude = 40.222
        testIns.longitude = -111.222
        testIns.orientation = 'W'
        testIns.background_color = 'orange'
        secondClass = dao.addClassification(testIns)
        self.assertNotEqual(secondClass, -1)

        testIns.crop_id = 44
        testIns.latitude = 40.333
        testIns.longitude = -111.333
        testIns.alphanumeric_color = 'white'
        self.assertNotEqual(dao.addClassification(testIns), -1)

        specs = {
            'orientation': secondClass,
            'crop_id': None,
            'alphanumeric_color': 'wasdf'
        }

        classResult = dao.getClassification(secondClass)
        submissionResult = dao.submitPendingTarget(classResult.target, specs)

        # Even though we fed a bunch of garbage in specs, submission should
        # still succeed, defaulting to most common value, for the garbage stuff
        self.assertIsNotNone(submissionResult)

        self.assertEqual(submissionResult.orientation, 'W')
        self.assertEqual(submissionResult.alphanumeric_color, 'black')
        self.assertEqual(submissionResult.background_color, 'orange')
        self.assertEqual(submissionResult.alphanumeric, 'Q')