Esempio n. 1
0
class StationResource(general_request.GeneralResource):

    LOGGER = 'flask.app.federator.station_resource'

    def __init__(self):
        super(StationResource, self).__init__()
        self.logger = logging.getLogger(self.LOGGER)

    @use_args(schema.StationSchema(), locations=('query', ))
    @utils.use_fdsnws_kwargs(
        eidangws.schema.ManySNCLSchema(context={'request': request}),
        locations=('query', ))
    def get(self, station_args, sncls):
        # request.method == 'GET'
        self.logger.debug('SNCLs: %s' % sncls)

        s = schema.StationSchema()
        station_args = s.dump(station_args).data
        self.logger.debug('StationSchema (serialized): %s' % station_args)

        # process request
        return self._process_request(station_args,
                                     sncls,
                                     self._get_result_mimetype(station_args),
                                     path_tempfile=self.path_tempfile)

    # get ()

    @utils.use_fdsnws_args(schema.StationSchema(), locations=('form', ))
    @utils.use_fdsnws_kwargs(
        eidangws.schema.ManySNCLSchema(context={'request': request}),
        locations=('form', ))
    def post(self, station_args, sncls):
        # request.method == 'POST'

        self.logger.debug('SNCLs: %s' % sncls)

        # serialize objects
        s = schema.StationSchema()
        station_args = s.dump(station_args).data
        self.logger.debug('StationSchema (serialized): %s' % station_args)

        return self._process_request(station_args,
                                     sncls,
                                     self._get_result_mimetype(station_args),
                                     path_tempfile=self.path_tempfile,
                                     post=True)

    # post ()

    def _get_result_mimetype(self, args):
        """Return result mimetype (either XML or plain text."""
        try:
            args['format'] == 'text'
            return settings.STATION_MIMETYPE_TEXT
        except KeyError:
            return settings.STATION_MIMETYPE_XML
Esempio n. 2
0
    def test_geographic_opts(self):
        self.maxDiff = None
        s = schema.StationSchema()
        reference_result = {
            'service': 'station',
            'format': 'xml',
            'level': 'station',
            'minlatitude': '0.0',
            'maxlatitude': '45.0',
            'includerestricted': 'true',
            'matchtimeseries': 'false',
            'nodata': '204',
            'includeavailability': 'false'}

        test_datasets = [{'minlatitude': 0.,
                          'maxlatitude': 45.,
                          'nodata': 204},
                         {'minlat': 0.,
                          'maxlat': 45.,
                          'nodata': 204}]

        result = s.dump(s.load(test_datasets[0]))
        self.assertEqual(result, reference_result)
        result = s.dump(s.load(test_datasets[1]))
        self.assertEqual(result, reference_result)
Esempio n. 3
0
    def get(self, station_args, sncls):
        # request.method == 'GET'
        self.logger.debug('SNCLs: %s' % sncls)

        s = schema.StationSchema()
        station_args = s.dump(station_args).data
        self.logger.debug('StationSchema (serialized): %s' % station_args)

        # process request
        return self._process_request(station_args,
                                     sncls,
                                     self._get_result_mimetype(station_args),
                                     path_tempfile=self.path_tempfile)
Esempio n. 4
0
    def post(self, station_args, sncls):
        # request.method == 'POST'

        self.logger.debug('SNCLs: %s' % sncls)

        # serialize objects
        s = schema.StationSchema()
        station_args = s.dump(station_args).data
        self.logger.debug('StationSchema (serialized): %s' % station_args)

        return self._process_request(station_args,
                                     sncls,
                                     self._get_result_mimetype(station_args),
                                     path_tempfile=self.path_tempfile,
                                     post=True)
Esempio n. 5
0
 def setUp(self):
     self.schema = schema.StationSchema()
Esempio n. 6
0
 def test_rect_and_circular(self):
     s = schema.StationSchema()
     test_data = {'minlatitude': 0., 'latitude': 45.}
     with self.assertRaises(ma.ValidationError):
         result = s.load(test_data)