Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added /ping to /api/v2 #147

Merged
merged 3 commits into from Mar 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/publisher/api_v2_urls.py
Expand Up @@ -2,6 +2,7 @@
from . import api_v2_views as views

urlpatterns = [
url(r'^ping$', views.ping, name='ping'),
url(r'articles$', views.article_list, name='article-list'),
url(r'articles/(?P<id>\d+)$', views.article, name='article'),
url(r'articles/(?P<id>\d+)/versions$', views.article_version_list, name='article-version-list'),
Expand Down
10 changes: 9 additions & 1 deletion src/publisher/api_v2_views.py
Expand Up @@ -3,7 +3,8 @@
from . import models, logic, fragment_logic
from .utils import ensure, isint, lmap
from rest_framework import status
from rest_framework.decorators import api_view
from rest_framework.decorators import api_view, renderer_classes
from rest_framework.renderers import StaticHTMLRenderer
from rest_framework.response import Response
from django.shortcuts import Http404
from django.conf import settings
Expand Down Expand Up @@ -56,6 +57,13 @@ def is_authenticated(request):
#LOG.info("authenticated? %s type %s" % (val, type(val)))
return val or False

@api_view(['GET'])
@renderer_classes((StaticHTMLRenderer,))
def ping(request):
"returns a test response for monitoring, *never* to be cached"

return Response('pong', content_type='text/plain; charset=UTF-8', headers={'Cache-Control': 'must-revalidate, no-cache, no-store, private'})

@api_view(['GET'])
def article_list(request):
"returns a list of snippets"
Expand Down
7 changes: 7 additions & 0 deletions src/publisher/tests/test_api_v2_views.py
Expand Up @@ -116,6 +116,13 @@ def setUp(self):
mware.CGROUPS: 'admin',
})

def test_ping(self):
resp = self.c.get(reverse('v2:ping'))
self.assertEqual(resp.status_code, 200)
self.assertEqual(resp.content_type, 'text/plain; charset=UTF-8')
self.assertEqual(resp['Cache-Control'], 'must-revalidate, no-cache, no-store, private')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, double handling if /ping cache headers are no different from regular caching headers.

self.assertEqual(resp.content.decode('utf-8'), 'pong')

def test_article_list(self):
"a list of published articles are returned to an unauthenticated response"
resp = self.c.get(reverse('v2:article-list'))
Expand Down