def test_0040_start_and_end_interval(self): app = Flask(__name__) with self.mocked_date(datetime.date(2000, 1, 10)): with app.test_request_context('/bubble', query_string='start=1010617200&end=1015714800', method="GET"): interval = EventInterval() self.assertEqual(interval.start, datetime.datetime(2002, 1, 9, 0, 0, tzinfo=datetime.timezone.utc)) self.assertEqual(interval.end, datetime.datetime(2002, 3, 9, 0, 0, tzinfo=datetime.timezone.utc))
def test_0010_default_interval(self): app = Flask(__name__) with self.mocked_date(datetime.date(2000, 1, 10)): with app.test_request_context('/bubble', query_string='', method="GET"): interval = EventInterval() self.assertEqual(interval.start, datetime.datetime(2000, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)) self.assertEqual(interval.end, datetime.datetime(2000, 2, 1, 0, 0, tzinfo=datetime.timezone.utc))
def get(self, category=None): interval = EventInterval() print("%s, %s" % (interval.start, interval.end)) event_qry = mapping.DbEvents.query_between(interval.start, interval.end) event_qry = event_qry.options( joinedload(mapping.DbEvents.topic).joinedload( mapping.DbTopics.forum)) event_qry = event_qry.options(joinedload(mapping.DbEvents.location)) if category is not None: event_qry = event_qry.filter( mapping.DbEvents.category == category.id) event_list = [] for event in event_qry: if not event.topic.forum.can_read( authorization.current_user.perm_masks): continue event_list.extend( event.instances_between(interval.start, interval.end)) return limit_list(event_list)
def test_0050_interval_too_long(self): app = Flask(__name__) with self.mocked_date(datetime.date(2000, 1, 10)): with app.test_request_context('/bubble', query_string='start=1010617200&end=1019343600', method="GET"): interval = EventInterval() self.assertRaises(BadRequest, interval._parse)