예제 #1
0
 def test_datetime_GT(self):
     bdt = datetime(2015, 11, 3, 1, 1, 1, tzinfo=timezone.utc)
     observed_range = query_pb2.TimestampField(value=utils.timestamp(bdt),
                                               rel_type=query_pb2.GT)
     stac_request = StacRequest(observed=observed_range)
     stac_item = search_one(stac_request)
     self.assertIsNotNone(stac_item)
     self.assertLessEqual(
         utils.timestamp(bdt).seconds, stac_item.datetime.seconds)
예제 #2
0
 def test_date_GT_OR_EQ(self):
     bd = date(2015, 11, 3)
     observed_range = query_pb2.TimestampField(value=utils.timestamp(bd),
                                               rel_type=query_pb2.GT_OR_EQ)
     stac_request = StacRequest(observed=observed_range)
     stac_item = search_one(stac_request)
     self.assertIsNotNone(stac_item)
     self.assertLessEqual(
         utils.timestamp(bd).seconds, stac_item.datetime.seconds)
예제 #3
0
 def test_datetime_not_range_desc(self):
     start = datetime(2013, 4, 1, 12, 45, 59, tzinfo=timezone.utc)
     end = datetime(2014, 4, 1, 12, 45, 59, tzinfo=timezone.utc)
     observed_range = query_pb2.TimestampField(
         start=utils.timestamp(start),
         stop=utils.timestamp(end),
         rel_type=query_pb2.NOT_BETWEEN,
         sort_direction=query_pb2.DESC)
     stac_request = StacRequest(observed=observed_range, limit=5)
     for stac_item in search(stac_request):
         print(
             datetime.fromtimestamp(stac_item.datetime.seconds,
                                    tz=timezone.utc))
         self.assertTrue(
             utils.timestamp(end).seconds < stac_item.datetime.seconds)
예제 #4
0
 def test_datetime_range(self):
     start = datetime(2013, 4, 1, 12, 45, 59, tzinfo=timezone.utc)
     end = datetime(2014, 4, 1, 12, 45, 59, tzinfo=timezone.utc)
     observed_range = query_pb2.TimestampField(start=utils.timestamp(start),
                                               stop=utils.timestamp(end),
                                               rel_type=query_pb2.BETWEEN)
     stac_request = StacRequest(observed=observed_range, limit=5)
     for stac_item in search(stac_request):
         print(
             datetime.fromtimestamp(stac_item.datetime.seconds,
                                    tz=timezone.utc))
         self.assertGreaterEqual(
             utils.timestamp(end).seconds, stac_item.datetime.seconds)
         self.assertLessEqual(
             utils.timestamp(start).seconds, stac_item.datetime.seconds)
예제 #5
0
    def test_durations(self):
        d = utils.duration(datetime(2016, 1, 1), datetime(2017, 1, 1))
        self.assertEquals(d.seconds, 31622400)
        d = utils.duration(date(2016, 1, 1), datetime(2017, 1, 1))
        self.assertEquals(d.seconds, 31622400)
        d = utils.duration(date(2016, 1, 1), date(2017, 1, 1))
        self.assertEquals(d.seconds, 31622400)
        d = utils.duration(datetime(2016, 1, 1), date(2017, 1, 1))
        self.assertEquals(d.seconds, 31622400)

        td = timedelta(seconds=d.seconds)
        d_end = datetime(2016, 1, 1) + td
        self.assertEquals(d_end.year, 2017)
        self.assertEquals(d_end.day, 1)
        self.assertEquals(d_end.month, 1)

        # FromDatetime for protobuf 3.6.1 throws "TypeError: can't subtract offset-naive and offset-aware datetimes"
        ts = utils.timestamp(datetime(2016, 1, 1, tzinfo=timezone.utc))
        self.assertIsNotNone(ts)

        d = utils.duration(datetime(2017, 1, 1),
                           datetime(2017, 1, 1, 0, 0, 59))
        self.assertEquals(d.seconds, 59)

        now_local = datetime.now().astimezone()
        now_utc = datetime.now(tz=timezone.utc)
        d = utils.duration(now_local, now_utc)
        self.assertLess(d.seconds, 1)

        ts = utils.timestamp(now_local)
        ts2 = timestamp_pb2.Timestamp()
        ts2.FromDatetime(now_local)
        self.assertEquals(ts.seconds, ts2.seconds)

        d = utils.duration(datetime(2016, 1, 1, 0, 0, 59, tzinfo=timezone.utc),
                           datetime(2016, 1, 1, 0, 1, 59, tzinfo=timezone.utc))
        self.assertEquals(d.seconds, 60)

        utc_now = now_local.astimezone(tz=timezone.utc)
        later_now = utc_now + timedelta(seconds=33)

        d = utils.duration(now_local, later_now)
        self.assertEquals(d.seconds, 33)
예제 #6
0
    def test_count_more(self):
        start = datetime(2014, 4, 1, 12, 45, 59, tzinfo=timezone.utc)
        end = datetime(2014, 4, 1, 12, 52, 59, tzinfo=timezone.utc)
        observed_range = query_pb2.TimestampField(start=utils.timestamp(start),
                                                  stop=utils.timestamp(end),
                                                  rel_type=query_pb2.BETWEEN)
        stac_request = StacRequest(observed=observed_range,
                                   limit=40,
                                   landsat=LandsatRequest())
        for stac_item in search(stac_request):
            self.assertEquals(Eo.LANDSAT, stac_item.eo.constellation)
            print(
                datetime.fromtimestamp(stac_item.datetime.seconds,
                                       tz=timezone.utc))
            self.assertGreaterEqual(
                utils.timestamp(end).seconds, stac_item.datetime.seconds)
            self.assertLessEqual(
                utils.timestamp(start).seconds, stac_item.datetime.seconds)

        self.assertEquals(12, count_items(stac_request))