Esempio n. 1
0
    def test__collect_missing_query_parameter(self):
        """
        Should log the missing parameter(s) in data.
        :return:
        """
        excpeted_data = "Could not load query. " \
                        "Error: ''TemperatureFromOpenWeatherDotCom' object has no attribute 'city''."
        collector = TemperatureFromOpenWeatherDotCom(parameters={
            'countrycode':
            'ger',
            'apikey':
            '123456789abcdefghijkl1234567890a'
        },
                                                     parent=None)

        collector._collect()

        self.assertEqual(excpeted_data, collector.data[0].collecteddata)
Esempio n. 2
0
    def test__collect_openweathermap_returns_invalid_json(self):
        """
        Should log invalid state of json in "collected" data as string.
        :return:
        """
        excpeted_data = \
            "'https://api.openweathermap.org/data/2.5/weather?q=Munich,ger" \
            "&units=Metric&&APPID=123456789abcdefghijkl1234567890a' " \
                        "returned invalid weather data."
        collector = TemperatureFromOpenWeatherDotCom(parameters={
            'countrycode': 'ger',
            'apikey': '123456789abcdefghijkl1234567890a',
            'city': 'Munich'
        },
                                                     parent=None)
        collector._apikey = '123456789abcdefghijkl1234567890a'

        collector._collect()

        self.assertEqual(excpeted_data, collector.data[0].collecteddata)
Esempio n. 3
0
    def test__collect_openweathermap_not_reachable(self):
        """
        Should log unreachability in the "collected" data as string.
        :return:
        """
        excpeted_data = "Could not query http://plumbumm.ich.bin.nicht.da.haha." \
                        "\n<urlopen error [Errno 8] nodename nor servname provided, or not known>"
        if platform.system() == "Windows":
            excpeted_data = "Could not query http://plumbumm.ich.bin.nicht.da.haha." \
                            "\n<urlopen error [Errno 11001] getaddrinfo failed>"
        collector = TemperatureFromOpenWeatherDotCom(parameters={
            'countrycode': 'ger',
            'apikey': '123456789abcdefghijkl1234567890a',
            'city': 'Munich'
        },
                                                     parent=None)

        collector._collect()

        self.assertEqual(excpeted_data, collector.data[0].collecteddata)