예제 #1
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:8888/data/aircraft.json',
                             status=200,
                             body=load_fixture('dump1090-aircrafts-1.json'))

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

            feed_entry = entries['7c6d9a']
            assert feed_entry.external_id == "7c6d9a"
            assert feed_entry.coordinates == (-34.234888, 150.533009)
            self.assertAlmostEqual(feed_entry.distance_to_home, 362.4, 1)
            assert feed_entry.altitude == 13075
            assert feed_entry.callsign == "QLK231D"
            assert feed_entry.updated \
                == datetime.datetime(2018, 10, 26, 7, 35, 51, 400000,
                                     tzinfo=datetime.timezone.utc)
            assert feed_entry.speed == 357
            assert feed_entry.track == 61
            assert feed_entry.squawk == "7201"
            assert feed_entry.vert_rate == -1600

            assert repr(feed_entry) == "<FeedEntry(id=7c6d9a)>"
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:8888",
        "/data/aircraft.json",
        "get",
        aresponses.Response(
            text=load_fixture("dump1090-aircrafts-1.json"),
            content_type="application/json",
            status=200,
        ),
        match_querystring=True,
    )

    async with aiohttp.ClientSession(loop=event_loop) as websession:
        feed = Dump1090AircraftsFeed(home_coordinates,
                                     websession,
                                     filter_radius=300)
        assert (repr(feed) == "<Dump1090AircraftsFeed("
                "home=(-31.0, 151.0), "
                "url=http://localhost:8888/data/"
                "aircraft.json, "
                "radius=300)>")
        status, entries = await feed.update()
        assert status == UPDATE_OK
        assert entries is not None
        assert len(entries) == 1
예제 #3
0
    async def test_update_with_client_error(self, mock_aioresponse):
        """Test updating feed raises exception."""
        home_coordinates = (-31.0, 151.0)
        mock_aioresponse.get('http://localhost:8888/data/aircraft.json',
                             exception=aiohttp.ClientError())

        async with aiohttp.ClientSession() as session:
            feed = Dump1090AircraftsFeed(home_coordinates, session)
            status, entries = await feed.update()
            assert status == UPDATE_ERROR
            self.assertIsNone(entries)
async def test_update_error(aresponses, event_loop):
    """Test updating feed results in error."""
    home_coordinates = (-31.0, 151.0)
    aresponses.add(
        "localhost:8888",
        "/data/aircraft.json",
        "get",
        aresponses.Response(text="ERROR", status=500),
        match_querystring=True,
    )

    async with aiohttp.ClientSession(loop=event_loop) as websession:
        feed = Dump1090AircraftsFeed(home_coordinates, websession)
        status, entries = await feed.update()
        assert status == UPDATE_ERROR
        assert entries is None
async def test_update_with_timeout_error(aresponses, event_loop):
    """Test updating feed raises exception."""
    home_coordinates = (-31.0, 151.0)
    aresponses.add(
        "localhost:8888",
        "/data/aircraft.json",
        "get",
        asyncio.TimeoutError(),
        match_querystring=True,
    )

    async with aiohttp.ClientSession(loop=event_loop) as websession:
        feed = Dump1090AircraftsFeed(home_coordinates, websession)
        status, entries = await feed.update()
        assert status == UPDATE_ERROR
        assert entries is None
예제 #6
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:8888/data/aircraft.json',
                             status=200,
                             body=load_fixture('dump1090-aircrafts-1.json'))

        async with aiohttp.ClientSession() as session:
            feed = Dump1090AircraftsFeed(home_coordinates,
                                         session,
                                         filter_radius=300)
            assert repr(feed) == "<Dump1090AircraftsFeed(" \
                                 "home=(-31.0, 151.0), " \
                                 "url=http://localhost:8888/data/" \
                                 "aircraft.json, " \
                                 "radius=300)>"
            status, entries = await feed.update()
            assert status == UPDATE_OK
            self.assertIsNotNone(entries)
            assert len(entries) == 1
async def test_update_ok(aresponses, event_loop):
    """Test updating feed is ok."""
    home_coordinates = (-31.0, 151.0)
    aresponses.add(
        "localhost:8888",
        "/data/aircraft.json",
        "get",
        aresponses.Response(
            text=load_fixture("dump1090-aircrafts-1.json"),
            content_type="application/json",
            status=200,
        ),
        match_querystring=True,
    )

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

        feed_entry = entries["7c6d9a"]
        assert feed_entry.external_id == "7c6d9a"
        assert feed_entry.coordinates == (-34.234888, 150.533009)
        assert feed_entry.distance_to_home == pytest.approx(362.4, 0.1)
        assert feed_entry.altitude == 13075
        assert feed_entry.callsign == "QLK231D"
        assert feed_entry.updated == datetime.datetime(
            2018, 10, 26, 7, 35, 51, 400000, tzinfo=datetime.timezone.utc)
        assert feed_entry.speed == 357
        assert feed_entry.track == 61
        assert feed_entry.squawk == "7201"
        assert feed_entry.vert_rate == -1600

        assert repr(feed_entry) == "<FeedEntry(id=7c6d9a)>"