Exemple #1
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')
Exemple #2
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)
Exemple #3
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)
Exemple #4
0
    def get(self, class_id):

        # confirm that the X-Manual header was specified
        manual = checkXManual(request)

        dao = OutgoingManualDAO(
            defaultConfigPath()) if manual else OutgoingAutonomousDAO(
                defaultConfigPath())
        result = dao.getClassification(class_id)
        if result is None:
            return {
                'message':
                'Failed to locate classification with id {}'.format(class_id)
            }, 404
        return jsonify(result.toDict())
Exemple #5
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
Exemple #6
0
    def delete(self, class_id):

        # confirm that the X-Manual header was specified
        manual = checkXManual(request)

        dao = OutgoingManualDAO(
            defaultConfigPath()) if manual else OutgoingAutonomousDAO(
                defaultConfigPath())

        if dao.getClassification(class_id) is None:
            return {
                'message':
                'Couldnt find classification with id {}'.format(class_id)
            }, 404

        result = dao.removeClassification(class_id)
        if not result:
            return {
                'message':
                'Something went wrong while trying to delete id {} (was it delete by someone else first??)'
                .format(class_id)
            }, 500

        return {'message': 'success!', 'id': class_id}
Exemple #7
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')