def test_005_notAllTimesUnique(self):
     
     timeList = self.timeList
     timeList.append(self.timeList[0])
     
     builder = DateTimeOptionsBuilder(timeList)
     
     assert builder.buildOptions() == timeList
 def setUp(self):
     self.years  = ['1990','1991','1992','1993', '1994', '1995']
     self.months = ["%02i"%x for x in range(1,13)]
     self.days   = ["%02i"%x for x in range(1,31)]
     self.times  = ["09:30:00.0", "12:00:00.0", "15:45:00.0"]
     
     self.timeList = self.buildTimes(self.years, self.months, self.days, self.times)
     self.builder = DateTimeOptionsBuilder(self.timeList)        
 def test_004_notAllOptions(self):
     
     #check it spots not all combinations used
     timeList = ['2001-05-10T12:00:00.0',
                 '2002-06-10T12:00:00.0',
                 '2003-05-10T12:00:00.0',
                 '2004-06-11T12:00:00.0',
                 '2005-05-11T12:00:00.0',
                 '2006-06-11T12:00:00.0',
                 '2001-05-12T12:00:00.0',
                 '2002-06-12T12:00:00.0',
                 '2003-05-12T12:00:00.0',
                 '2004-06-13T12:00:00.0',
                 '2005-05-13T12:00:00.0',
                 '2006-06-13T12:00:00.0', ]
     
     builder = DateTimeOptionsBuilder(timeList)
     
     assert builder.buildOptions() == timeList
class TestDateTimeOptionsBuilder(unittest.TestCase):

    def setUp(self):
        self.years  = ['1990','1991','1992','1993', '1994', '1995']
        self.months = ["%02i"%x for x in range(1,13)]
        self.days   = ["%02i"%x for x in range(1,31)]
        self.times  = ["09:30:00.0", "12:00:00.0", "15:45:00.0"]
        
        self.timeList = self.buildTimes(self.years, self.months, self.days, self.times)
        self.builder = DateTimeOptionsBuilder(self.timeList)        
        
    def tearDown(self):
        pass

    def buildTimes(self, years, months, days, times, format="%(year)s-%(month)s-%(day)sT%(time)s"):
        
        tList = []
        
        for y in years:
            for m in months:
                for d in days:
                    for t in times:
                        tList.append(format % {'year':y, 'month':m, 'day':d, 'time':t})
                        
        return tList
                        
    def test_001_regexPatternMatchesValid(self):
        timeList = self.buildTimes(self.years, self.months, self.days, self.times)
        
        for ti in timeList:
            assert DateTimeOptionsBuilder.isoDateTimePattern.match(ti) != None
        
    def test_002_rexexPatternNotMatchesInvalid(self):
        l = ['1995-12-30 09:30:00.0','1995-12-30','1995-dec-30T15:45:00.0']
        
        for ti in l:
            assert DateTimeOptionsBuilder.isoDateTimePattern.match(ti) == None

    def test_003_repeatedAll(self):
        
        resTimeOpts = self.builder.buildOptions()
        
        assert resTimeOpts.__class__ == dict
        
        assert resTimeOpts['years'] == self.years
        assert resTimeOpts['months'] == self.months
        assert resTimeOpts['days'] == self.days
        assert resTimeOpts['times'] == self.times

    def test_004_notAllOptions(self):
        
        #check it spots not all combinations used
        timeList = ['2001-05-10T12:00:00.0',
                    '2002-06-10T12:00:00.0',
                    '2003-05-10T12:00:00.0',
                    '2004-06-11T12:00:00.0',
                    '2005-05-11T12:00:00.0',
                    '2006-06-11T12:00:00.0',
                    '2001-05-12T12:00:00.0',
                    '2002-06-12T12:00:00.0',
                    '2003-05-12T12:00:00.0',
                    '2004-06-13T12:00:00.0',
                    '2005-05-13T12:00:00.0',
                    '2006-06-13T12:00:00.0', ]
        
        builder = DateTimeOptionsBuilder(timeList)
        
        assert builder.buildOptions() == timeList

    def test_005_notAllTimesUnique(self):
        
        timeList = self.timeList
        timeList.append(self.timeList[0])
        
        builder = DateTimeOptionsBuilder(timeList)
        
        assert builder.buildOptions() == timeList
Esempio n. 5
0
    def index(self):
        """
        Default controller method to handle the initial requests to the page
        """
        st = time.time()
        params = self._getParams()

        # get the list of default WCS endpoints
        ep = EndpointConfigFileParser()
        endpointList = ep.buildEndpointList("wcsdown")
        wcsEPList = utils.filterEnpointList(endpointList, "WCS")
        # log.debug("wcsEPList = %s" % (pprint.pformat(wcsEPList),))

        c.defaultWCSEndpoints = utils.toJSON(wcsEPList)

        log.debug("params = %s" % (params,))

        endpoint = params.get("ENDPOINT", None)
        bbox = params.get("BBOX", None)
        c.time = params.get("TIME", None)
        c.time_end = params.get("TIME_END", None)
        layer = params.get("LAYER", None)
        format = params.get("FORMAT", None)
        crs = params.get("CRS", None)
        c.message = params.get("MESSAGE", "")
        c.singleTimePoint = params.get("SINGLE_TIME", "")

        layers = []
        supportedFormats = []
        supportedCRS = []
        bboxLimits = None
        timepositions = None

        if endpoint != None:

            st1 = time.time()
            wcs, layers = self._getWCSObj(endpoint)
            log.debug("retrieved wcs metadata in  = %s" % (time.time() - st1,))

            if layer != None:
                st1 = time.time()
                layerMetadata, bboxLimits, timepositions, supportedFormats, supportedCRS = self._getWCSMetadata(
                    wcs, layer
                )
                log.debug("retrieved layer metadata in  = %s" % (time.time() - st1,))

        if bbox != None:
            c.selected_bbox = bbox
        elif bboxLimits != None:
            c.selected_bbox = bboxLimits
        else:
            c.selected_bbox = "-180.0,-90.0,180.0,90.0"

        log.debug("timepositions = %s" % (timepositions,))
        if timepositions != None and timepositions != [None]:
            builder = DateTimeOptionsBuilder(timepositions)
            options = builder.buildOptions()
            # log.debug("options = %s" % (options,))
            c.timedata = utils.toJSON(options)

        c.endpoint = endpoint

        c.selected_layer = layer
        c.layer_options = [(x, x) for x in layers]
        c.layer_options.insert(0, ("", ""))  # add an empty value at the start

        c.selected_format = format
        c.format_options = [(x, x) for x in supportedFormats]
        c.format_options.insert(0, ("", ""))  # add an empty value at the start

        c.selected_crs = crs
        c.crs_options = [(x, x) for x in supportedCRS]
        c.crs_options.insert(0, ("", ""))  # add an empty value at the start

        # get server information from config file
        g.server = config["app_conf"]["serverurl"]

        lp = OutlineLayersConfigParser()

        layersList = lp.getOutlineLayerList("wcsdown")
        log.debug("layerList = %s" % (layersList,))

        c.baseLayerJSON = utils.toJSON(layersList)

        log.debug("rendering template after %ss" % (time.time() - st,))
        return render("wcsdown.html")