Ejemplo n.º 1
0
    def on_get(self, req, resp):
        '''
        Return (R, G, B) colour for star of type <type><decimal><size
        GET /misc/starcolor/<code>

        Returns
        {
            "code": <code>,
            "RGB": {"red": <red>, "blue": <blue>, "green": <green>}
        }
        '''
        self.query_parameters = {'code': None}
        LOGGER.debug('query_string = %s', req.query_string)
        self.query_parameters = parse_query_string(req.query_string,
                                                   self.query_parameters)
        self.clear_data()
        code = self.query_parameters['code']
        self._validate_code(code)
        try:
            assert self.code is not None
            assert self.code != ''
        except AssertionError:
            raise falcon.HTTPUnprocessableEntity(
                title='Bad parameter value {}'.format(code),
                description='Invalid code {}'.format(code))
        self.get_details()
        doc = {'code': self.code, 'rgb': self.rgb}
        resp.body = json.dumps(doc)
        resp.status = falcon.HTTP_200
Ejemplo n.º 2
0
def test_parse_query_string_ok(client):
    '''Test valid query string'''
    query_string = 'foo=value1&bar=value2'
    valid_params = {'foo': '', 'bar': ''}
    expected_query_parameters = {'foo': 'value1', 'bar': 'value2'}
    actual_query_parameters = parse_query_string(query_string, valid_params)
    assert expected_query_parameters == actual_query_parameters
Ejemplo n.º 3
0
def test_parse_query_string_bogus(client):
    '''Test bogus query string'''
    query_string = 'bogus=oh_yes'
    valid_params = {'foo': '', 'bar': ''}

    with pytest.raises(falcon.HTTPError):
        actual_query_parameters = parse_query_string(
            query_string=query_string, valid_query_parameters=valid_params)
        del actual_query_parameters
Ejemplo n.º 4
0
    def on_get(self, req, resp):
        '''
        Return angular diameter of object diameter <diameter>
        at range <distance>
        GET /misc/angdia?distance=<distance>&diameter=<diameter>

        Returns
        {
            "ang_dia_deg": <angular diameter (degrees)>,
            "ang_dia_rad": <angular diameter (radians)>,
            "diameter": <diameter>,
            "distance": <distance>
        }
        '''
        self.query_parameters = {'distance': None, 'diameter': None}
        LOGGER.debug('query_string = %s', req.query_string)
        self.query_parameters = parse_query_string(req.query_string,
                                                   self.query_parameters)
        try:
            distance = float(self.query_parameters['distance'])
            diameter = float(self.query_parameters['diameter'])
        except ValueError as err:
            raise falcon.HTTPUnprocessableEntity(
                title='Bad parameter value',
                description='Invalid parameter in {}'.format(req.query_string))

        angdia_deg = round(atan2(diameter, distance) * 180 / pi, 3)
        angdia_rad = round(atan2(diameter, distance), 3)
        doc = {
            'ang_dia_deg': angdia_deg,
            'ang_dia_rad': angdia_rad,
            'diameter': diameter,
            'distance': distance
        }
        resp.body = json.dumps(doc)
        resp.status = falcon.HTTP_200