예제 #1
0
class WeatherDataLoadingTester(unittest.TestCase):
    def setUp(self):
        self.weatherUtil = MSGWeatherDataUtil()
        self.logger = SEKLogger(__name__, 'DEBUG')
        self.dbConnector = MSGDBConnector()
        self.cursor = self.dbConnector.conn.cursor()
        self.configer = MSGConfiger()


    def testLoadDataSinceLastLoaded(self):
        """
        Data should be loaded since the last data present in the database.
        """
        pass


    def testRetrieveDataSinceLastLoaded(self):
        """
        Data since the last loaded date is retrieved.
        """
        pass


    def testGetLastLoadedDate(self):
        myDate = self.weatherUtil.getLastDateLoaded(self.cursor).strftime(
            "%Y-%m-%d %H:%M:%S")
        pattern = '^(\d+-\d+-\d+\s\d+:\d+:\d+)$'
        match = re.match(pattern, myDate)
        assert match and (match.group(1) == myDate), "Date format is valid."


    def testWeatherDataPattern(self):
        myPattern = self.configer.configOptionValue('Weather Data',
                                                    'weather_data_pattern')
        testString = """<A HREF="someURL">QCLCD201208.zip</A>"""

        match = re.match(myPattern, testString)
        self.logger.log("pattern = %s" % myPattern, 'info')
        if match:
            self.logger.log("match = %s" % match)
            self.logger.log("match group = %s" % match.group(1))
        else:
            self.logger.log("match not found")
        assert match and match.group(
            1) == 'QCLCD201208.zip', "Download filename was matched."


    def testWeatherDataURL(self):
        myURL = self.configer.configOptionValue('Weather Data',
                                                'weather_data_url')
        pass
    fp.close()


if __name__ == '__main__':

    dbConnector = MSGDBConnector()
    cursor = dbConnector.conn.cursor()
    weatherUtil = MSGWeatherDataUtil()
    timeUtil = MSGTimeUtil()

    msg = "Downloading NOAA weather data (%s)." % timeUtil.conciseNow()
    print msg
    MSG_BODY = '%s\n' % msg

    msg = "Last loaded date is %s." % weatherUtil.datePart(
        datetime = weatherUtil.getLastDateLoaded(cursor))
    print msg
    MSG_BODY += '%s\n' % msg

    retriever = MSGWeatherDataRetriever()
    configer = MSGConfiger()
    WEATHER_DATA_PATH = configer.configOptionValue('Weather Data',
                                                   'weather_data_path')

    msg = "Using URL %s." % weatherDataURL
    print msg
    MSG_BODY += '%s\n' % msg

    msg = "Using pattern %s." % weatherDataPattern
    print msg
    MSG_BODY += '%s\n' % msg
    fp.write(MSG_BODY)
    fp.close()


if __name__ == "__main__":

    dbConnector = MSGDBConnector()
    cursor = dbConnector.conn.cursor()
    weatherUtil = MSGWeatherDataUtil()
    timeUtil = MSGTimeUtil()

    msg = "Downloading NOAA weather data (%s)." % timeUtil.conciseNow()
    print msg
    MSG_BODY = "%s\n" % msg

    msg = "Last loaded date is %s." % weatherUtil.datePart(datetime=weatherUtil.getLastDateLoaded(cursor))
    print msg
    MSG_BODY += "%s\n" % msg

    retriever = MSGWeatherDataRetriever()
    configer = MSGConfiger()
    WEATHER_DATA_PATH = configer.configOptionValue("Weather Data", "weather_data_path")

    msg = "Using URL %s." % weatherDataURL
    print msg
    MSG_BODY += "%s\n" % msg

    msg = "Using pattern %s." % weatherDataPattern
    print msg
    MSG_BODY += "%s\n" % msg
    fp.close()


if __name__ == '__main__':

    dbConnector = MSGDBConnector()
    cursor = dbConnector.conn.cursor()
    weatherUtil = MSGWeatherDataUtil()
    timeUtil = MSGTimeUtil()

    msg = "Downloading NOAA weather data (%s)." % timeUtil.conciseNow()
    print msg
    MSG_BODY = '%s\n' % msg

    msg = "Last loaded date is %s." % weatherUtil.datePart(
        datetime=weatherUtil.getLastDateLoaded(cursor))
    print msg
    MSG_BODY += '%s\n' % msg

    retriever = MSGWeatherDataRetriever()
    configer = MSGConfiger()
    WEATHER_DATA_PATH = configer.configOptionValue('Weather Data',
                                                   'weather_data_path')

    msg = "Using URL %s." % weatherDataURL
    print msg
    MSG_BODY += '%s\n' % msg

    msg = "Using pattern %s." % weatherDataPattern
    print msg
    MSG_BODY += '%s\n' % msg