コード例 #1
0
async def test_update_ok_filter_radius(aresponses, event_loop):
    """Test updating feed is ok with filter radius."""
    home_coordinates = (-31.0, 151.0)
    aresponses.add(
        "localhost:8754",
        "/flights.json",
        "get",
        aresponses.Response(
            text=load_fixture("fr24feed-flights-1.json"),
            content_type="application/json",
            status=200,
        ),
    )

    async with aiohttp.ClientSession(loop=event_loop) as websession:
        feed = FlightradarFlightsFeed(home_coordinates, websession, filter_radius=300)
        assert (
            repr(feed) == "<FlightradarFlightsFeed("
            "home=(-31.0, 151.0), "
            "url=http://localhost:8754/flights.json, "
            "radius=300)>"
        )
        status, entries = await feed.update()
        assert status == UPDATE_OK
        assert entries is not None
        assert len(entries) == 2
コード例 #2
0
    async def test_update_ok(self, mock_aioresponse):
        """Test updating feed is ok."""
        home_coordinates = (-31.0, 151.0)
        mock_aioresponse.get('http://localhost:8754/flights.json',
                             status=200,
                             body=load_fixture('fr24feed-flights-1.json'))

        async with aiohttp.ClientSession() as session:
            feed = FlightradarFlightsFeed(home_coordinates, session)
            assert repr(feed) == "<FlightradarFlightsFeed(" \
                                 "home=(-31.0, 151.0), " \
                                 "url=http://localhost:8754/flights.json, " \
                                 "radius=None)>"
            status, entries = await feed.update()
            assert status == UPDATE_OK
            self.assertIsNotNone(entries)
            assert len(entries) == 6

            feed_entry = entries['7C1469']
            assert feed_entry.external_id == "7C1469"
            assert feed_entry.coordinates == (-33.7779, 151.1324)
            self.assertAlmostEqual(feed_entry.distance_to_home, 309.1, 1)
            assert feed_entry.altitude == 2950
            assert feed_entry.callsign == "QFA456"
            assert feed_entry.updated \
                == datetime.datetime(2018, 10, 26, 7, 39, 51,
                                     tzinfo=datetime.timezone.utc)
            assert feed_entry.speed == 183
            assert feed_entry.track == 167
            assert feed_entry.squawk == "4040"
            assert feed_entry.vert_rate == -64

            assert repr(feed_entry) == "<FeedEntry(id=7C1469)>"
コード例 #3
0
async def test_update_custom_url(aresponses, event_loop):
    """Test updating feed is ok with custom url."""
    home_coordinates = (-31.0, 151.0)
    custom_url = "http://something:9876/foo/bar.json"
    aresponses.add(
        "something:9876",
        "/foo/bar.json",
        "get",
        aresponses.Response(
            text=load_fixture("fr24feed-flights-1.json"),
            content_type="application/json",
            status=200,
        ),
        match_querystring=True,
    )

    async with aiohttp.ClientSession(loop=event_loop) as websession:
        feed = FlightradarFlightsFeed(home_coordinates, websession, url=custom_url)
        assert (
            repr(feed) == "<FlightradarFlightsFeed("
            "home=(-31.0, 151.0), "
            "url=http://something:9876/foo/bar.json, "
            "radius=None)>"
        )
        status, entries = await feed.update()
        assert status == UPDATE_OK
        assert entries is not None
        assert len(entries) == 6

        feed_entry = entries["7C1469"]
        assert feed_entry.external_id == "7C1469"
コード例 #4
0
    async def test_missing_session(self, mock_aioresponse):
        """Test updating feed without supplying client session."""
        home_coordinates = (-31.0, 151.0)
        mock_aioresponse.get('http://localhost:8754/flights.json',
                             status=200,
                             body=load_fixture('fr24feed-flights-1.json'))

        async with aiohttp.ClientSession() as session:
            with self.assertRaises(FlightradarException):
                feed = FlightradarFlightsFeed(home_coordinates, None)
コード例 #5
0
    async def test_update_with_timeout_error(self, mock_aioresponse):
        """Test updating feed raises exception."""
        home_coordinates = (-31.0, 151.0)
        mock_aioresponse.get('http://localhost:8754/flights.json',
                             exception=asyncio.TimeoutError())

        async with aiohttp.ClientSession() as session:
            feed = FlightradarFlightsFeed(home_coordinates, session)
            status, entries = await feed.update()
            assert status == UPDATE_ERROR
            self.assertIsNone(entries)
コード例 #6
0
    async def test_update_error(self, mock_aioresponse):
        """Test updating feed results in error."""
        loop = asyncio.get_event_loop()
        home_coordinates = (-31.0, 151.0)
        mock_aioresponse.get('http://localhost:8754/flights.json',
                             status=500,
                             body='ERROR')

        async with aiohttp.ClientSession() as session:
            feed = FlightradarFlightsFeed(home_coordinates, session)
            status, entries = await feed.update()
            assert status == UPDATE_ERROR
コード例 #7
0
async def test_update_error(aresponses, event_loop):
    """Test updating feed results in error."""
    home_coordinates = (-31.0, 151.0)
    aresponses.add(
        "localhost:8754",
        "/flights.json",
        "get",
        aresponses.Response(text="ERROR", status=500),
        match_querystring=True,
    )

    async with aiohttp.ClientSession(loop=event_loop) as websession:
        feed = FlightradarFlightsFeed(home_coordinates, websession)
        status, entries = await feed.update()
        assert status == UPDATE_ERROR
コード例 #8
0
async def test_update_with_timeout_error(aresponses, event_loop):
    """Test updating feed raises exception."""
    home_coordinates = (-31.0, 151.0)
    aresponses.add(
        "localhost:8754",
        "/flights.json",
        "get",
        asyncio.TimeoutError(),
        match_querystring=True,
    )

    async with aiohttp.ClientSession(loop=event_loop) as websession:
        feed = FlightradarFlightsFeed(home_coordinates, websession)
        status, entries = await feed.update()
        assert status == UPDATE_ERROR
        assert entries is None
コード例 #9
0
async def test_missing_session(aresponses, event_loop):
    """Test updating feed without supplying client session."""
    home_coordinates = (-31.0, 151.0)
    aresponses.add(
        "localhost:8754",
        "/flights.json",
        "get",
        aresponses.Response(
            text=load_fixture("fr24feed-flights-1.json"),
            content_type="application/json",
            status=200,
        ),
        match_querystring=True,
    )

    async with aiohttp.ClientSession(loop=event_loop):
        with pytest.raises(FlightradarException):
            FlightradarFlightsFeed(home_coordinates, None)
コード例 #10
0
    async def test_update_ok_filter_radius(self, mock_aioresponse):
        """Test updating feed is ok with filter radius."""
        home_coordinates = (-31.0, 151.0)
        mock_aioresponse.get('http://localhost:8754/flights.json',
                             status=200,
                             body=load_fixture('fr24feed-flights-1.json'))

        async with aiohttp.ClientSession() as session:
            feed = FlightradarFlightsFeed(home_coordinates,
                                          session,
                                          filter_radius=300)
            assert repr(feed) == "<FlightradarFlightsFeed(" \
                                 "home=(-31.0, 151.0), " \
                                 "url=http://localhost:8754/flights.json, " \
                                 "radius=300)>"
            status, entries = await feed.update()
            assert status == UPDATE_OK
            self.assertIsNotNone(entries)
            assert len(entries) == 2
コード例 #11
0
async def test_update_ok(aresponses, event_loop):
    """Test updating feed is ok."""
    home_coordinates = (-31.0, 151.0)
    aresponses.add(
        "localhost:8754",
        "/flights.json",
        "get",
        aresponses.Response(
            text=load_fixture("fr24feed-flights-1.json"),
            content_type="application/json",
            status=200,
        ),
        match_querystring=True,
    )

    async with aiohttp.ClientSession(loop=event_loop) as websession:
        feed = FlightradarFlightsFeed(home_coordinates, websession)
        assert (
            repr(feed) == "<FlightradarFlightsFeed("
            "home=(-31.0, 151.0), "
            "url=http://localhost:8754/flights.json, "
            "radius=None)>"
        )
        status, entries = await feed.update()
        assert status == UPDATE_OK
        assert entries is not None
        assert len(entries) == 6

        feed_entry = entries["7C1469"]
        assert feed_entry.external_id == "7C1469"
        assert feed_entry.coordinates == (-33.7779, 151.1324)
        assert feed_entry.distance_to_home == pytest.approx(309.1, rel=0.1)
        assert feed_entry.altitude == 2950
        assert feed_entry.callsign == "QFA456"
        assert feed_entry.updated == datetime.datetime(
            2018, 10, 26, 7, 39, 51, tzinfo=datetime.timezone.utc
        )
        assert feed_entry.speed == 183
        assert feed_entry.track == 167
        assert feed_entry.squawk == "4040"
        assert feed_entry.vert_rate == -64

        assert repr(feed_entry) == "<FeedEntry(id=7C1469)>"
コード例 #12
0
    async def test_update_custom_url(self, mock_aioresponse):
        """Test updating feed is ok with custom url."""
        loop = asyncio.get_event_loop()
        home_coordinates = (-31.0, 151.0)
        custom_url = 'http://something:9876/foo/bar.json'
        mock_aioresponse.get(custom_url,
                             status=200,
                             body=load_fixture('fr24feed-flights-1.json'))

        async with aiohttp.ClientSession() as session:
            feed = FlightradarFlightsFeed(home_coordinates,
                                          session,
                                          url=custom_url)
            assert repr(feed) == "<FlightradarFlightsFeed(" \
                                 "home=(-31.0, 151.0), " \
                                 "url=http://something:9876/foo/bar.json, " \
                                 "radius=None)>"
            status, entries = await feed.update()
            assert status == UPDATE_OK
            self.assertIsNotNone(entries)
            assert len(entries) == 6

            feed_entry = entries['7C1469']
            assert feed_entry.external_id == "7C1469"