def setUp(self): app = get_application() self.client = Client(app, BaseResponse) self.test_values = { 'date': datetime.datetime(2016, 5, 20, 15, 0), 'title': 'THIS IS TITLE', 'description': 'THIS IS TITLE', } eve = Event( event_date=self.test_values['date'], title=self.test_values['title'], description=self.test_values['description'], ) eve.put() events = Event.all().fetch(100) self.assertEquals(len(events), 1) self.assertEquals(events[0].title, 'THIS IS TITLE') self.event_key = str(events[0].key())
def event_feed(request): try: theyear_themonth = request.args['month'].split('-') theyear = int(theyear_themonth[0]) themonth = int(theyear_themonth[1]) feed_title = 'Events of: %s %d' % (calendar.month_name[themonth], theyear) if themonth < 1 or themonth > 12: raise ValueError except: now = datetime.now() theyear = now.year themonth = now.month feed_title = _('Upcoming Event') first_day_of_themonth = datetime(theyear, themonth, 1) + timedelta(days=-1) three_month_after = add_months(first_day_of_themonth, 2) results = Event.all().filter(u'event_date >=', first_day_of_themonth).filter( u'event_date <', three_month_after).order('event_date').fetch(1000) events = [ {'date': r.event_date.strftime('%Y-%m-%d %H:%M'), 'title': r.title, 'description': r.description, 'key': str(r.key())} for r in results] return render_json_response({'events': events, 'title': feed_title}, mimetype='application/json')