示例#1
0
class AQICNTest(TestCase):
    """
    Tests the dataqs.aqicn module.  Since each processor is highly
    dependent on a running GeoNode instance for most functions, only
    independent functions are tested here.
    """

    def setUp(self):
        self.processor = AQICNProcessor()
        httpretty.enable()

    def tearDown(self):
        httpretty.disable()

    def test_download(self):
        """
        Verify that the master url is retrieved.
        """
        httpretty.register_uri(
            httpretty.GET,
            self.processor.base_url,
            body=get_mock_response('test_aqicn_cities.html'),
            content_type='text/html')
        content = self.processor.download()
        self.assertIn(
            '<title>Air Pollution in the World - aqicn.org</title>', content)

    def test_getCities(self):
        """
        Verify that the processor creates a correct cities dictionary structure
        """
        self.processor.getCities()
        cities = self.processor.cities
        self.assertIsNotNone(cities)
        for city in cities:
            self.assertIsNotNone(city['city'], city)
            self.assertIsNotNone(city['country'], city)
            self.assertIsNotNone(city['url'], city)

    @patch('dataqs.aqicn.aqicn.AQICNWorker.__init__', mock_worker_init)
    @patch('dataqs.aqicn.aqicn.AQICNWorker.save_data', mock_saveData)
    def test_handleCity(self):
        """
        Verify that the correct AQI for a city is returned.
        """
        boston = u'http://aqicn.org/city/boston/'
        httpretty.register_uri(
            httpretty.GET,
            boston,
            body=get_mock_response('test_aqicn_boston.html'),
            content_type='text/html')
        cities = [{'city': u'Boston', 'country': u'USA', 'url': boston}]
        worker = dataqs.aqicn.aqicn.AQICNWorker('aqicn', cities)
        worker.handle_city(0, cities[0])
        with open(tmpfile) as jsonfile:
            city_json = json.load(jsonfile)
            self.assertEquals(city_json['data']['cur_aqi'], u'25')
            self.assertEquals(city_json['data']['cur_pm25'], u'25')
            self.assertEquals(city_json['data']['cur_o3'], u'11')
            self.assertEquals(city_json['data']['cur_so2'], u'2')
示例#2
0
 def setUp(self):
     self.processor = AQICNProcessor()
     httpretty.enable()
示例#3
0
文件: tasks.py 项目: mbertrand/dataqs
def aqicn_task(countries):
    processor = AQICNProcessor(countries=countries)
    processor.run()
示例#4
0
def aqicn_task(countries):
    processor = AQICNProcessor(countries=countries)
    processor.run()