def test_task_can_generate_valid_feature_collection(self):
        self.test_project, self.test_user = create_canned_project()
        # Act
        feature_collection = Task.get_tasks_as_geojson_feature_collection(
            self.test_project.id, "1")
        self.assertIsInstance(feature_collection, geojson.FeatureCollection)
        self.assertEqual(1, len(feature_collection.features))

        feature_collection = Task.get_tasks_as_geojson_feature_collection(
            self.test_project.id, None)
        self.assertIsInstance(feature_collection, geojson.FeatureCollection)
        self.assertEqual(2, len(feature_collection.features))
    def _attach_tasks_to_project(draft_project: Project, tasks_geojson):
        """
        Validates then iterates over the array of tasks and attach them to the draft project
        :param draft_project: Draft project in scope
        :param tasks_geojson: GeoJSON feature collection of mapping tasks
        :raises InvalidGeoJson, InvalidData
        """
        tasks = geojson.loads(json.dumps(tasks_geojson))

        if type(tasks) is not geojson.FeatureCollection:
            raise InvalidGeoJson(
                "Tasks: Invalid GeoJson must be FeatureCollection")

        is_valid_geojson = geojson.is_valid(tasks)
        if is_valid_geojson["valid"] == "no":
            raise InvalidGeoJson(
                f"Tasks: Invalid FeatureCollection - {is_valid_geojson['message']}"
            )

        task_count = 1
        for feature in tasks["features"]:
            try:
                task = Task.from_geojson_feature(task_count, feature)
            except (InvalidData, InvalidGeoJson) as e:
                raise e

            draft_project.tasks.append(task)
            task_count += 1

        task_count -= 1  # Remove last increment before falling out loop
        draft_project.total_tasks = task_count
예제 #3
0
    def test_task_can_generate_valid_feature_collection(self):
        if self.skip_tests:
            return

        # Act
        feature_collection = Task.get_tasks_as_geojson_feature_collection(
            self.test_project.id, "1"
        )
        self.assertIsInstance(feature_collection, geojson.FeatureCollection)
        self.assertEqual(1, len(feature_collection.features))

        feature_collection = Task.get_tasks_as_geojson_feature_collection(
            self.test_project.id, None
        )
        self.assertIsInstance(feature_collection, geojson.FeatureCollection)
        self.assertEqual(2, len(feature_collection.features))