Exemple #1
0
class TestSilence(unittest.TestCase):

    document = load_fixture('kaldi_small_doc.json')
    empty_document = load_fixture('kaldi_empty_doc.json')

    def test_compose(self):
        composer = Silence(self.document)
        actual = composer.compose()
        expected = {
            'text':
            'Silence...',
            'phrases': [{
                'text': '<PAUSE>',
                'start': 0.2,
                'end': 13.39
            }, {
                'text': '<PAUSE>',
                'start': 16.29,
                'end': 34.18
            }]
        }
        self.assertEqual(actual, expected)

    def test_find_empty(self):
        composer = Silence(self.empty_document)
        expected = {'text': 'Silence...', 'phrases': []}
        actual = composer.compose()
        self.assertEqual(actual, expected)
Exemple #2
0
 def setUp(self):
     super(ConfirmEmailTestCase, self).setUp()
     load_fixture("provision-data")
     self.createUser()
     user = User.objects.get(id=1)
     user.confirmedEmail = False
     user.save()
    async def test_feed_aggregator(self, mock_aioresponse):
        """Test updating feed through feed aggregator."""
        home_coordinates = (-31.0, 151.0)

        async with aiohttp.ClientSession() as session:
            feed_aggregator = FlightradarFlightsFeedAggregator(
                home_coordinates, session)
            assert repr(feed_aggregator) == "<FlightradarFlightsFeed" \
                                            "Aggregator" \
                                            "(feed=<FlightradarFlightsFeed(" \
                                            "home=(-31.0, 151.0), " \
                                            "url=http://localhost:8754/" \
                                            "flights.json, " \
                                            "radius=None)>)>"

            # Update 1
            mock_aioresponse.get('http://localhost:8754/flights.json',
                                 status=200,
                                 body=load_fixture('fr24feed-flights-1.json'))
            status, entries = await feed_aggregator.update()
            assert status == UPDATE_OK
            self.assertIsNotNone(entries)
            assert len(entries) == 5

            feed_entry = entries['7C6B28']
            assert feed_entry.external_id == "7C6B28"
            assert feed_entry.coordinates == (-32.5470, 150.9698)
            assert feed_entry.altitude == 22175
            assert feed_entry.callsign == "JST423"
            self.assertIsNotNone(feed_entry.statistics)
            assert feed_entry.statistics.success_ratio() == 1.0

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

            # Update 2
            mock_aioresponse.get('http://localhost:8754/flights.json',
                                 status=200,
                                 body=load_fixture('fr24feed-flights-2.json'))
            status, entries = await feed_aggregator.update()
            assert status == UPDATE_OK
            self.assertIsNotNone(entries)
            assert len(entries) == 5

            feed_entry = entries['7C6B28']
            assert feed_entry.external_id == "7C6B28"
            assert feed_entry.coordinates == (-32.5470, 150.9698)
            assert feed_entry.altitude == 22175
            assert feed_entry.callsign == "JST423"
Exemple #4
0
    async def test_feed_aggregator(self, mock_aioresponse):
        """Test updating feed through feed aggregator."""
        home_coordinates = (-31.0, 151.0)

        async with aiohttp.ClientSession() as session:
            feed_aggregator = Dump1090AircraftsFeedAggregator(
                home_coordinates, session)
            assert repr(feed_aggregator) == "<Dump1090AircraftsFeed" \
                                            "Aggregator" \
                                            "(feed=<Dump1090AircraftsFeed(" \
                                            "home=(-31.0, 151.0), " \
                                            "url=http://localhost:8888/" \
                                            "data/aircraft.json, " \
                                            "radius=None)>)>"

            # Update 1
            mock_aioresponse.get(
                'http://localhost:8888/data/aircraft.json',
                status=200,
                body=load_fixture('dump1090-aircrafts-1.json'))
            status, entries = await feed_aggregator.update()
            assert status == UPDATE_OK
            self.assertIsNotNone(entries)
            assert len(entries) == 4

            feed_entry = entries['7c6b28']
            assert feed_entry.external_id == "7c6b28"
            assert feed_entry.coordinates == (-32.819840, 151.124735)
            assert feed_entry.altitude == 26000
            assert feed_entry.callsign == "JST423"

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

            # Update 2
            mock_aioresponse.get(
                'http://localhost:8888/data/aircraft.json',
                status=200,
                body=load_fixture('dump1090-aircrafts-2.json'))
            status, entries = await feed_aggregator.update()
            assert status == UPDATE_OK
            self.assertIsNotNone(entries)
            assert len(entries) == 5

            feed_entry = entries['7c6b28']
            assert feed_entry.external_id == "7c6b28"
            assert feed_entry.coordinates == (-32.819840, 151.124735)
            assert feed_entry.altitude == 26000
            assert feed_entry.callsign == "JST423"
Exemple #5
0
    def test_complex_3(self):
        """Test parsing various actual XML files."""
        xml_parser = XmlParser()
        xml = load_fixture('xml_parser_complex_3.xml')
        feed = xml_parser.parse(xml)
        self.assertIsNotNone(feed)

        self.assertIsNone(feed.title)
        self.assertIsNone(feed.subtitle)
        self.assertIsNone(feed.description)
        self.assertIsNone(feed.language)
        self.assertIsNone(feed.published_date)
        self.assertIsNone(feed.last_build_date)
        self.assertIsNone(feed.ttl)
        assert feed.rights == "Feed Rights 1"
        self.assertIsNone(feed.image)

        self.assertIsNotNone(feed.entries)
        assert len(feed.entries) == 2

        feed_entry = feed.entries[0]
        self.assertIsNone(feed_entry.title)
        self.assertIsNone(feed_entry.published_date)
        self.assertIsNone(feed_entry.geometry)

        feed_entry = feed.entries[1]
        self.assertIsNone(feed_entry.title)
        self.assertIsNone(feed_entry.geometry)
Exemple #6
0
    def test_complex_2(self):
        """Test parsing various actual XML files."""
        xml_parser = XmlParser()
        xml = load_fixture('xml_parser_complex_2.xml')
        feed = xml_parser.parse(xml)
        self.assertIsNotNone(feed)

        assert feed.title == "Feed Title 1"
        assert feed.subtitle == "Feed Subtitle 1"
        assert feed.ttl == "INVALID"
        assert feed.author == "Author 1"
        assert feed.last_build_date \
            == datetime.datetime(2018, 12, 9, 9, 0,
                                 tzinfo=datetime.timezone.utc)
        assert feed.updated_date \
            == datetime.datetime(2018, 12, 9, 9, 0,
                                 tzinfo=datetime.timezone.utc)
        assert feed.copyright == "Feed Rights 1"
        assert feed.rights == "Feed Rights 1"
        assert feed.generator == "Feed Generator 1"
        self.assertIsNotNone(feed.image)
        assert feed.image.title == "Image Title 1"
        assert feed.image.url == "http://image.url/image.png"
        assert feed.image.link == "http://feed.link/feed.rss"
        self.assertIsNone(feed.image.description)
        self.assertIsNone(feed.image.width)
        self.assertIsNone(feed.image.height)
        self.assertIsNone(feed.docs)

        self.assertIsNotNone(feed.entries)
        assert len(feed.entries) == 1

        feed_entry = feed.entries[0]
        assert feed_entry.title == "Title 6"
        self.assertIsNone(feed_entry.published_date)
Exemple #7
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
Exemple #8
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"
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
async def test_update_ok_feed_2(aresponses, event_loop):
    """Test updating feed is ok."""
    aresponses.add(
        "test.url",
        "/testpath",
        "get",
        aresponses.Response(text=load_fixture("generic_feed_2.xml"), status=200),
    )

    async with aiohttp.ClientSession(loop=event_loop) as websession:

        feed = MockGeoRssFeed(
            websession, HOME_COORDINATES_1, "http://test.url/testpath"
        )
        status, entries = await feed.update()
        assert status == UPDATE_OK
        assert entries is not None
        assert len(entries) == 1

        feed_entry = entries[0]
        assert feed_entry.title == "Title 1"
        assert feed_entry.external_id == "1234"
        assert feed_entry.category == "Category 1"
        assert feed_entry.coordinates == (-37.2345, 149.1234)
        assert round(abs(feed_entry.distance_to_home - 714.4), 1) == 0
async def test_update_ok_then_error(aresponses, event_loop):
    """Test updating feed goes fine, followed by an error."""
    aresponses.add(
        "test.url",
        "/testpath",
        "get",
        aresponses.Response(text=load_fixture("generic_feed_1.xml"), status=200),
    )

    async with aiohttp.ClientSession(loop=event_loop) as websession:

        feed = MockGeoRssFeed(
            websession, HOME_COORDINATES_1, "http://test.url/testpath"
        )
        assert (
            repr(feed) == "<MockGeoRssFeed(home=(-31.0, 151.0), "
            "url=http://test.url/testpath, radius=None, "
            "categories=None)>"
        )
        status, entries = await feed.update()
        assert status == UPDATE_OK
        assert entries is not None
        assert len(entries) == 5
        assert feed.last_timestamp is not None

        aresponses.add("test.url", "/testpath", "get", aresponses.Response(status=404))

        status, entries = await feed.update()
        assert status == UPDATE_ERROR
        assert feed.last_timestamp is None
async def test_update_ok_with_categories(aresponses, event_loop):
    """Test updating feed is ok, filtered by category."""
    home_coordinates = (-31.0, 151.0)
    aresponses.add(
        'data.livetraffic.com',
        '/traffic/hazards/flood-open.json',
        'get',
        aresponses.Response(text=load_fixture('flood-open.json'), status=200),
        match_querystring=True,
    )

    async with aiohttp.ClientSession(loop=event_loop) as websession:

        feed = NswTransportServiceIncidentsFeed(websession,
                                                home_coordinates,
                                                hazard="flood-open",
                                                filter_categories=['Flooding'])
        assert repr(feed) == "<NswTransportServiceIncidentsFeed(" \
                             "home=(-31.0, 151.0), " \
                             "url=http://data.livetraffic.com/traffic/hazards/flood-open.json, " \
                             "radius=None, categories=['Flooding'])>"
        status, entries = await feed.update()
        assert status == UPDATE_OK
        assert entries is not None
        assert len(entries) == 5

        feed_entry = entries[0]
        assert feed_entry is not None
        assert feed_entry.title == "FLOODING"
        assert feed_entry.category == "Flooding"
        assert repr(feed_entry) == "<NswTransportServiceIncidents" \
                                   "FeedEntry(id=53718)>"
Exemple #13
0
def test_get_charging_current_deprecated(test_charger, requests_mock, fixture,
                                         expected):
    requests_mock.get(test_charger._url, text=load_fixture(fixture))
    with pytest.deprecated_call():
        current = test_charger.getChargingCurrent()
    assert current == expected
    assert type(current) == float
Exemple #14
0
    def test_update_ok_feed_3(self, mock_session, mock_request):
        """Test updating feed is ok."""
        mock_session.return_value.__enter__.return_value.send\
            .return_value.ok = True
        mock_session.return_value.__enter__.return_value.send\
            .return_value.text = load_fixture('generic_feed_3.xml')

        feed = MockGeoRssFeed(HOME_COORDINATES_1, None)
        status, entries = feed.update()
        assert status == UPDATE_OK
        self.assertIsNotNone(entries)
        assert len(entries) == 3

        feed_entry = entries[0]
        assert feed_entry.external_id == "1234"
        assert feed_entry.coordinates == (-34.93728111547821,
                                          148.59710883878262)
        self.assertAlmostEqual(feed_entry.distance_to_home, 491.7, 1)

        feed_entry = entries[1]
        assert feed_entry.external_id == "2345"
        assert feed_entry.coordinates == (-34.937170989, 148.597182317)
        self.assertAlmostEqual(feed_entry.distance_to_home, 491.8, 1)

        feed_entry = entries[2]
        assert feed_entry.external_id == "3456"
        assert feed_entry.coordinates == (-29.962746645660683,
                                          152.43090880416074)
        self.assertAlmostEqual(feed_entry.distance_to_home, 176.5, 1)
Exemple #15
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_empty_feed(aresponses, event_loop):
    """Test updating feed is ok when feed does not contain any entries."""
    home_coordinates = (-41.2, 174.7)
    aresponses.add(
        '192.168.0.200',
        '/FlightAirMap/live/geojson',
        'get',
        aresponses.Response(text=load_fixture('flights-2.json'), status=200),
        match_querystring=True,
    )

    async with aiohttp.ClientSession(loop=event_loop) as websession:

        feed = FlightAirMapFeed(
            websession,
            url="http://192.168.0.200/FlightAirMap/live/geojson",
            home_coordinates=home_coordinates)
        assert repr(feed) == "<FlightAirMapFeed(" \
                             "home=(-41.2, 174.7), " \
                             "url=http://192.168.0.200" \
                             "/FlightAirMap/live/geojson, " \
                             "radius=None)>"
        status, entries = await feed.update()
        assert status == UPDATE_OK
        assert entries is not None
        assert len(entries) == 0
        assert feed.last_timestamp is None
Exemple #17
0
def test_get_ir_temperature_deprecated(test_charger, requests_mock):
    requests_mock.get(test_charger._url,
                      text=load_fixture('v1_responses/temperature_values.txt'))
    with pytest.deprecated_call():
        temperature = test_charger.getIRTemperature()
    assert temperature == 23.0
    assert type(temperature) == float
Exemple #18
0
def test_get_usage_total_deprecated(test_charger, requests_mock, fixture,
                                    expected):
    requests_mock.get(test_charger._url, text=load_fixture(fixture))
    with pytest.deprecated_call():
        usage = test_charger.getUsageTotal()
    assert usage == expected
    assert type(usage) == float
async def test_update_ok_with_categories(aresponses, event_loop):
    """Test updating feed is ok, filtered by category."""
    home_coordinates = (-31.0, 151.0)
    aresponses.add(
        "www.rfs.nsw.gov.au",
        "/feeds/majorIncidents.json",
        "get",
        aresponses.Response(text=load_fixture("incidents-1.json"), status=200),
        match_querystring=True,
    )

    async with aiohttp.ClientSession(loop=event_loop) as websession:

        feed = NswRuralFireServiceIncidentsFeed(
            websession, home_coordinates, filter_categories=["Category 1"])
        assert (repr(feed) == "<NswRuralFireServiceIncidentsFeed("
                "home=(-31.0, 151.0), "
                "url=https://www.rfs.nsw.gov.au"
                "/feeds/majorIncidents.json, "
                "radius=None, categories=['Category 1'])>")
        status, entries = await feed.update()
        assert status == UPDATE_OK
        assert entries is not None
        assert len(entries) == 1

        feed_entry = entries[0]
        assert feed_entry is not None
        assert feed_entry.title == "Title 1"
        assert feed_entry.category == "Category 1"
        assert repr(feed_entry
                    ) == "<NswRuralFireServiceIncidents" "FeedEntry(id=1234)>"
Exemple #20
0
def test_get_ir_threshold_v3(test_charger_json, requests_mock):
    requests_mock.get(
        test_charger_json._url,
        text=load_fixture('v3_responses/temperature_settings.txt'))
    threshold = test_charger_json.ir_threshold
    assert threshold == 0.0
    assert type(threshold) == float
Exemple #21
0
def test_get_charging_voltage_deprecated(test_charger, requests_mock, fixture,
                                         expected):
    requests_mock.get(test_charger._url, text=load_fixture(fixture))
    with pytest.deprecated_call():
        voltage = test_charger.getChargingVoltage()
    assert voltage == expected
    assert type(voltage) == float
Exemple #22
0
def test_get_auto_service_level_enabled_deprecated(test_charger,
                                                   requests_mock):
    requests_mock.get(test_charger._url,
                      text=load_fixture('v1_responses/settings.txt'))
    with pytest.deprecated_call():
        enabled = test_charger.getAutoServiceLevelEnabled()
    assert enabled is False
Exemple #23
0
    def test_update_ok(self, mock_session, mock_request):
        """Test updating feed is ok."""
        home_coordinates = (-31.0, 151.0)
        mock_session.return_value.__enter__.return_value.send.return_value.ok = True
        mock_session.return_value.__enter__.return_value.send.return_value.text = (
            load_fixture("usgs_earthquake_hazards_program_feed.json"))

        feed = UsgsEarthquakeHazardsProgramFeed(
            home_coordinates, "past_hour_significant_earthquakes")
        assert (repr(feed) == "<UsgsEarthquakeHazardsProgramFeed("
                "home=(-31.0, 151.0), "
                "url=https://earthquake.usgs.gov/earthquakes/"
                "feed/v1.0/summary/significant_hour.geojson, "
                "radius=None, magnitude=None)>")
        status, entries = feed.update()
        assert status == UPDATE_OK
        self.assertIsNotNone(entries)
        assert len(entries) == 3

        feed_entry = entries[0]
        assert feed_entry.title == "Title 1"
        assert feed_entry.external_id == "1234"
        assert feed_entry.coordinates == (-32.2345, 149.1234)
        self.assertAlmostEqual(feed_entry.distance_to_home, 224.5, 1)
        assert feed_entry.place == "Place 1"
        assert feed_entry.magnitude == 3.0
        assert feed_entry.time == datetime.datetime(
            2018, 9, 22, 8, 0, tzinfo=datetime.timezone.utc)
        assert feed_entry.updated == datetime.datetime(
            2018, 9, 22, 8, 30, tzinfo=datetime.timezone.utc)
        assert feed_entry.alert == "Alert 1"
        assert feed_entry.type == "Type 1"
        assert feed_entry.status == "Status 1"
        assert feed_entry.attribution == "Feed Title"
    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)>"
Exemple #25
0
    def test_update_ok_with_radius_and_category_filtering(
            self, mock_session, mock_request):
        """Test updating feed is ok."""
        mock_session.return_value.__enter__.return_value.send\
            .return_value.ok = True
        mock_session.return_value.__enter__.return_value.send\
            .return_value.text = load_fixture('generic_feed_1.xml')

        feed = MockGeoRssFeed(HOME_COORDINATES_2,
                              None,
                              filter_radius=90.0,
                              filter_categories=['Category 2'])
        status, entries = feed.update()
        assert status == UPDATE_OK
        self.assertIsNotNone(entries)
        assert len(entries) == 1
        self.assertAlmostEqual(entries[0].distance_to_home, 77.0, 1)

        feed = MockGeoRssFeed(HOME_COORDINATES_2,
                              None,
                              filter_radius=90.0,
                              filter_categories=['Category 4'])
        status, entries = feed.update()
        assert status == UPDATE_OK
        self.assertIsNotNone(entries)
        assert len(entries) == 0
Exemple #26
0
def test_get_protocol_version_deprecated(test_charger, requests_mock):
    requests_mock.get(test_charger._url,
                      text=load_fixture('v1_responses/version.txt'))
    with pytest.deprecated_call():
        version = test_charger.getProtocolVersion()
    assert version == '1.0.3'
    assert type(version) == str
Exemple #27
0
def test_get_ir_threshold_deprecated(test_charger, requests_mock):
    requests_mock.get(
        test_charger._url,
        text=load_fixture('v1_responses/temperature_settings.txt'))
    with pytest.deprecated_call():
        threshold = test_charger.getIRThreshold()
    assert threshold == 0.0
    assert type(threshold) == float
Exemple #28
0
 def test_simple_2(self):
     """Test parsing various actual XML files."""
     xml_parser = XmlParser()
     xml = load_fixture('xml_parser_simple_2.xml')
     feed = xml_parser.parse(xml)
     self.assertIsNotNone(feed)
     self.assertIsNotNone(feed.entries)
     assert len(feed.entries) == 1
async def test_update_ok(aresponses, event_loop):
    """Test updating feed is ok."""
    home_coordinates = (-31.0, 151.0)
    aresponses.add(
        "www.rfs.nsw.gov.au",
        "/feeds/majorIncidents.json",
        "get",
        aresponses.Response(text=load_fixture("incidents-1.json"), status=200),
        match_querystring=True,
    )

    async with aiohttp.ClientSession(loop=event_loop) as websession:

        feed = NswRuralFireServiceIncidentsFeed(websession, home_coordinates)
        assert (repr(feed) == "<NswRuralFireServiceIncidentsFeed("
                "home=(-31.0, 151.0), "
                "url=https://www.rfs.nsw.gov.au"
                "/feeds/majorIncidents.json, "
                "radius=None, categories=None)>")
        status, entries = await feed.update()
        assert status == UPDATE_OK
        assert entries is not None
        assert len(entries) == 4

        feed_entry = entries[0]
        assert feed_entry.title == "Title 1"
        assert feed_entry.category == "Category 1"
        assert feed_entry.external_id == "1234"
        assert feed_entry.coordinates == (-37.2345, 149.1234)
        assert round(abs(feed_entry.distance_to_home - 714.4), 1) == 0
        assert repr(feed_entry
                    ) == "<NswRuralFireServiceIncidents" "FeedEntry(id=1234)>"
        assert feed_entry.publication_date == datetime.datetime(
            2018, 9, 21, 6, 30, tzinfo=datetime.timezone.utc)
        assert feed_entry.location == "Location 1"
        assert feed_entry.council_area == "Council 1"
        assert feed_entry.status == "Status 1"
        assert feed_entry.type == "Type 1"
        assert feed_entry.fire
        assert feed_entry.size == "10 ha"
        assert feed_entry.responsible_agency == "Agency 1"
        assert feed_entry.attribution == ATTRIBUTION

        feed_entry = entries[1]
        assert feed_entry is not None
        assert feed_entry.title == "Title 2"
        assert feed_entry.category == "Category 2"
        assert not feed_entry.fire

        feed_entry = entries[2]
        assert feed_entry.title == "Title 3"
        assert feed_entry.category is None

        feed_entry = entries[3]
        assert feed_entry.title == "Badja Forest Rd, Countegany"
        assert feed_entry.geometries is not None
        assert len(feed_entry.geometries) == 4
        assert round(abs(feed_entry.distance_to_home - 578.5), 1) == 0
    def test_geojson_query_obj(self):
        form_data = load_fixture('deck_geojson_form_data.json')
        datasource = {'type': 'table'}
        test_viz_deckgl = viz.DeckGeoJson(datasource, form_data)
        results = test_viz_deckgl.query_obj()

        assert results['metrics'] == []
        assert results['groupby'] == []
        assert results['columns'] == ['test_col']
async def test_update_ok_feed_3(aresponses, event_loop):
    """Test updating feed is ok."""
    aresponses.add(
        "test.url",
        "/testpath",
        "get",
        aresponses.Response(text=load_fixture("generic_feed_3.xml"), status=200),
    )

    async with aiohttp.ClientSession(loop=event_loop) as websession:
        feed = MockGeoRssFeed(
            websession, HOME_COORDINATES_1, "http://test.url/testpath"
        )
        status, entries = await feed.update()
        assert status == UPDATE_OK
        assert entries is not None
        assert len(entries) == 5

        feed_entry = entries[0]
        assert feed_entry.external_id == "1234"
        assert len(feed_entry.geometries) == 1
        assert isinstance(feed_entry.geometries[0], Polygon)
        assert feed_entry.coordinates == (-34.93728111547821, 148.59710883878262)
        assert round(abs(feed_entry.distance_to_home - 491.7), 1) == 0

        feed_entry = entries[1]
        assert feed_entry.external_id == "2345"
        assert len(feed_entry.geometries) == 2
        assert isinstance(feed_entry.geometries[0], Point)
        assert isinstance(feed_entry.geometries[1], Polygon)
        assert feed_entry.coordinates == (-34.937170989, 148.597182317)
        assert round(abs(feed_entry.distance_to_home - 491.7), 1) == 0

        feed_entry = entries[2]
        assert feed_entry.external_id == "3456"
        assert len(feed_entry.geometries) == 2
        assert isinstance(feed_entry.geometries[0], Polygon)
        assert isinstance(feed_entry.geometries[1], Polygon)
        assert feed_entry.coordinates == (-29.962746645660683, 152.43090880416074)
        assert round(abs(feed_entry.distance_to_home - 176.5), 1) == 0

        feed_entry = entries[3]
        assert feed_entry.external_id == "4567"
        assert len(feed_entry.geometries) == 2
        assert isinstance(feed_entry.geometries[0], Point)
        assert isinstance(feed_entry.geometries[1], Point)
        assert feed_entry.coordinates == (-33.2345, 154.789)
        assert round(abs(feed_entry.distance_to_home - 172.3), 1) == 0

        feed_entry = entries[4]
        assert feed_entry.external_id == "5678"
        assert len(feed_entry.geometries) == 2
        assert isinstance(feed_entry.geometries[0], Point)
        assert isinstance(feed_entry.geometries[1], Polygon)
        assert feed_entry.coordinates == (-31.2345, 152.789)
        assert round(abs(feed_entry.distance_to_home - 172.3), 1) == 0
Exemple #32
0
 def setUp(self):
     super(SignUpTestCase, self).setUp()
     load_fixture("provision-data")
Exemple #33
0
 def setUp(self):
     super(LogoutTestCase, self).setUp()
     load_fixture("provision-data")
     self.createUser()
Exemple #34
0
 def setUp(self):
     super(EditSubjectsTestCase, self).setUp()
     load_fixture("provision-data")
     self.createUser()
Exemple #35
0
 def setUp(self):
     super(RecoverPasswordTestCase, self).setUp()
     load_fixture("provision-data")
     self.createUser()
Exemple #36
0
 def setUp(self):
     load_fixture("provision-data")