예제 #1
0
 def test_derive_airport_not_found(self, get_nearest_airport):
     '''
     Attribute is not set when airport is not found.
     '''
     get_nearest_airport.side_effect = api.NotFoundError('Not Found.')
     lat = KPV(name='Latitude At Liftoff', items=[
         KeyPointValue(index=12, value=4.0),
         KeyPointValue(index=32, value=6.0),
     ])
     lon = KPV(name='Longitude At Liftoff', items=[
         KeyPointValue(index=12, value=3.0),
         KeyPointValue(index=32, value=9.0),
     ])
     afr_apt = A(name='AFR Takeoff Airport', value={'id': 25})
     apt = self.node_class()
     apt.set_flight_attr = Mock()
     # Check that no attribute is created if not found via API:
     apt.derive(lat, lon, None)
     apt.set_flight_attr.assert_called_once_with(None)
     apt.set_flight_attr.reset_mock()
     get_nearest_airport.assert_called_once_with(4.0, 3.0)
     get_nearest_airport.reset_mock()
     # Check that the AFR airport was used if not found via API:
     apt.derive(lat, lon, afr_apt)
     apt.set_flight_attr.assert_called_once_with(afr_apt.value)
     apt.set_flight_attr.reset_mock()
     get_nearest_airport.assert_called_once_with(4.0, 3.0)
     get_nearest_airport.reset_mock()
예제 #2
0
    def get_nearest_airport(self, latitude, longitude):
        '''
        Returns the nearest airports to the provided latitude and longitude.

        :param latitude: latitude in decimal degrees.
        :type latitude: float
        :param longitude: longitude in decimal degrees.
        :type longitude: float
        :returns: airport info dictionary
        :rtype: dict
        :raises: api.NotFoundError -- if the aircraft cannot be found.
        '''
        data = self.request(settings.API_FILE_PATHS['airports'])
        airports = []
        for airport in data:
            if 'latitude' not in airport or 'longitude' not in airport:
                continue
            args = (latitude, longitude, airport['latitude'],
                    airport['longitude'])
            airport['distance'] = library.bearing_and_distance(*args)[1]
            airports.append(airport)
        try:
            return airports
        except:
            raise api.NotFoundError(
                'Airport not found using Local File API: %f,%f' %
                (latitude, longitude))
예제 #3
0
    def get_data_exports(self, aircraft):
        '''
        Returns details of data exports configuration for an aircraft.

        :param aircraft: aircraft tail number.
        :type aircraft: str
        :returns: data exports info dictionary
        :rtype: dict
        :raises: api.NotFoundError -- if the aircraft cannot be found.
        '''
        data = self.request(settings.API_FILE_PATHS['exports'])
        try:
            return data[aircraft]
        except (KeyError, TypeError):
            raise api.NotFoundError(
                'Aircraft not found using Local File API: %s' % aircraft)
예제 #4
0
    def get_aircraft(self, aircraft):
        '''
        Returns details of an aircraft matching the provided tail number.

        :param aircraft: aircraft tail number.
        :type aircraft: str
        :returns: aircraft info dictionary
        :rtype: dict
        :raises: api.NotFoundError -- if the aircraft cannot be found.
        '''
        data = self.request(settings.API_FILE_PATHS['aircraft'])
        try:
            return data[aircraft]
        except KeyError:
            raise api.NotFoundError(
                'Aircraft not found using Local File API: %s' % aircraft)
예제 #5
0
    def get_airport(self, code):
        '''
        Returns details of an airport matching the provided code.

        :param code: airport id, ICAO code or IATA code.
        :type code: int or str
        :returns: airport info dictionary
        :rtype: dict
        :raises: api.NotFoundError -- if the aircraft cannot be found.
        '''
        data = self.request(settings.API_FILE_PATHS['airports'])
        for airport in data:
            if code in (airport.get('id'), airport['code'].get('iata'),
                        airport['code'].get('icao')):
                return airport
        raise api.NotFoundError('Airport not found using Local File API: %s' %
                                code)