Beispiel #1
0
    def post_deployment(self, request, **kwargs):
        # should extract and validate the form...
        form = staging_forms.ApiDeploymentForm(request.POST)
        if form.is_valid():
            # extract the path we are working with
            base = staging_settings.STAGING_IMPORT_DIR
            path = os.path.join(base, kwargs['pk'].decode('hex'))
            path = os.path.abspath(path)

            # now we create the deployment
            created_deployment = Deployment()

            data = form.cleaned_data

            created_deployment.short_name = data['short_name']
            created_deployment.campaign = data['campaign']
            created_deployment.license = data['license']
            created_deployment.descriptive_keywords = data[
                'descriptive_keywords']

            print "passing to function to process"
            # now pass to the parsing function
            try:
                DeploymentImporter.import_path(created_deployment, path)
                logger.debug("DeploymentImporter Run successfully.")
                return self.create_response(request, created_deployment)
            except Exception:
                logger.exception("Unable to import deployment.")
Beispiel #2
0
    def test_deployment_import(self):
        """Test the actual import code."""

        # create a few measurement types needed for this
        cadence = ScientificMeasurementType()

        cadence.normalised_name = "cadence"
        cadence.display_name = "Cadence"
        cadence.max_value = 200
        cadence.min_value = 0
        cadence.description = "How fast you pedal"
        cadence.units = 'm'

        cadence.save()

        index = ScientificMeasurementType()

        index.normalised_name = "index"
        index.display_name = "Index"
        index.max_value = 100000
        index.min_value = 0
        index.description = "Number of the Image"
        index.units = "m"

        index.save()

        # get the fixture path
        path = self.deployment_path

        # prefill what we need to
        deployment = Deployment()

        deployment.short_name = "TestDeployment"
        deployment.campaign = self.campaign
        deployment.license = "CC-BY"
        deployment.descriptive_keywords = "Test Keyword, Other Keyword"

        # and fire it off!
        # this should throw nothing
        deploymentimport.DeploymentImporter.import_path(deployment, path)

        # now check it worked!

        # there are 16 image pairs
        self.assertEqual(deployment.pose_set.count(), 16)

        for p in deployment.pose_set.all():
            # check the correct number of images per pose
            self.assertEqual(p.image_set.count(), 2)

            # check the cadence pose measurement came through
            self.assertEqual(p.scientificposemeasurement_set.count(), 1)

            cadence_m = p.scientificposemeasurement_set.get(measurement_type__normalised_name="cadence")

            # get the front image
            front = p.image_set.get(camera__name="Front")

            # check it has an index measurement
            self.assertEqual(front.scientificimagemeasurement_set.count(), 1)

            index_m = front.scientificimagemeasurement_set.get(measurement_type__normalised_name="index")