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

Add informational requests into json API #10

Merged
merged 2 commits into from
Jul 8, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pinnwand/http.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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()