Skip to content

Commit

Permalink
Merge pull request #10 from kapsh/api_info
Browse files Browse the repository at this point in the history
Add informational requests into json API
  • Loading branch information
supakeen committed Jul 8, 2019
2 parents 9e12ab2 + fa5203b commit 43b18cb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pinnwand/http.py
Expand Up @@ -238,6 +238,18 @@ async def post(self) -> None:
)


class APILexers(Base):
async def get(self) -> None:
self.write(utility.list_languages())


class APIExpiries(Base):
async def get(self) -> None:
self.write(
{name: str(delta) for name, delta in utility.expiries.items()}
)


class RemovalPage(Base):
"""Serve the removal page."""

Expand Down Expand Up @@ -273,6 +285,8 @@ def make_application() -> tornado.web.Application:
(r"/json/new", APINew),
(r"/json/remove", APIRemove),
(r"/json/show/(.*)", APIShow),
(r"/json/lexers", APILexers),
(r"/json/expiries", APIExpiries),
(
r"/static/(.*)",
tornado.web.StaticFileHandler,
Expand Down
13 changes: 13 additions & 0 deletions test/test_http.py
Expand Up @@ -7,6 +7,7 @@

from pinnwand import http
from pinnwand import database
from pinnwand import utility


class WebsiteTestCase(tornado.testing.AsyncHTTPTestCase):
Expand Down Expand Up @@ -149,3 +150,15 @@ def test_api_remove(self) -> None:
response = self.fetch(f"/json/show/{data['paste_id']}")

assert response.code == 404

def test_api_get_lexers(self) -> None:
response = self.fetch("/json/lexers", method="GET")

assert response.code == 200
assert json.loads(response.body) == utility.list_languages()

def test_api_get_expiries(self) -> None:
response = self.fetch("/json/expiries", method="GET")

assert response.code == 200
assert json.loads(response.body).keys() == utility.expiries.keys()

0 comments on commit 43b18cb

Please sign in to comment.