def test_delete_news(self): news = News() news.put() self.assertEqual(1, News.all().count()) path = "/news/delete/" + str(news.key().id()) self.testapp.get(path) self.assertEqual(0, News.all().count())
def test_new_news(self): params = { 'title': "Event", 'short_description': "Short description", 'description': "Description" } self.testapp.post('/news/new', params) self.assertEqual(1, News.all().count())
def test_edit_news(self): news = News(title="News", short_description="Short Description", description="Description1") news.put() ident = news.key().id() params = { 'title': "News", 'short_description': "Short Description", 'description': "Description2" } path = "/news/edit/" + str(news.key().id()) response = self.testapp.post(path, params) news = News.get_by_id(ident) self.assertEqual(1, News.all().count()) self.assertEqual(302, response.status_int) self.assertEqual("Description2", str(news.description))
def get(self): self.response.headers['Content-Type'] = 'application/json' query = News.all().order("-created_at") newsData = [] for news in query: data = { "id": news.key().id(), "title": news.title, "short_description": news.short_description, "description": news.description, "created_at": news.created_at.strftime('%d-%m-%Y'), "image": base64.b64encode(str(news.image)) } newsData.append(data) jsonEventsData = json.dumps(newsData) self.response.write(jsonEventsData)
def getAllNews(self): query = News.all().order("-created_at") news = [] for n in query: jsonEventInfo = {} jsonEventInfo['title'] = n.title jsonEventInfo['short_description'] = n.short_description jsonEventInfo['description'] = n.description jsonEventInfo['date'] = n.created_at.strftime('%d-%m-%Y') currentUrl = self.request.url; jsonEventInfo['delete_link'] = currentUrl + '/delete/' + str(n.key().id()) jsonEventInfo['edit_link'] = currentUrl + '/edit/' + str(n.key().id()) jsonEventInfo['direct_link'] = currentUrl + '/' + str(n.key().id()) news.append(jsonEventInfo) return news