Exemple #1
0
    def test_process_path(self):
        path = '/forest-change/forma-alerts/admin/bra'
        value = args.process_path(path, 'iso')
        self.assertEqual({'iso': 'bra'}, value)

        path = '/forest-change/forma-alerts/admin/bra/123'
        value = args.process_path(path, 'id1')
        self.assertEqual({'iso': 'bra', 'id1': '123'}, value)

        path = '/forest-change/forma-alerts/wdpa/123'
        value = args.process_path(path, 'wdpaid')
        self.assertEqual({'wdpaid': '123'}, value)

        path = '/forest-change/forma-alerts/use/logging/123'
        value = args.process_path(path, 'use')
        self.assertEqual({'use': 'logging', 'useid': '123'}, value)
Exemple #2
0
    def test_process_path(self):
        path = '/forest-change/forma-alerts/admin/bra'
        value = args.process_path(path, 'iso')
        self.assertEqual({'iso': 'bra'}, value)

        path = '/forest-change/forma-alerts/admin/bra/123'
        value = args.process_path(path, 'id1')
        self.assertEqual({'iso': 'bra', 'id1': '123'}, value)

        path = '/forest-change/forma-alerts/wdpa/123'
        value = args.process_path(path, 'wdpaid')
        self.assertEqual({'wdpaid': '123'}, value)

        path = '/forest-change/forma-alerts/use/logging/123'
        value = args.process_path(path, 'use')
        self.assertEqual({'use': 'logging', 'useid': '123'}, value)
Exemple #3
0
    def get(self):
        try:
            path = self.request.path

            # Return API meta
            if path == '/forest-change':
                self.complete('respond', META)
                return

            dataset, rtype = _classify_request(path)

            # Unsupported dataset or reqest type
            if not dataset or not rtype:
                self.error(404)
                return

            # Handle request
            query_args = args.process(self.args(only=PARAMS[dataset][rtype]))
            path_args = args.process_path(path, rtype)
            params = dict(query_args, **path_args)

            # Queries for all require a geojson constraint for performance
            if rtype == 'all' and 'geojson' not in params:
                raise args.GeoJsonArgError()

            rid = self.get_id(params)
            target = TARGETS[dataset]
            action, data = self.get_or_execute(params, target, rid)

            # Redirect if needed
            if action != 'redirect':
                data.update(META[dataset])

            self.complete(action, data)
        except (Exception, args.ArgError), e:
            logging.exception(e)
            self.write_error(400, e.message)