Skip to content

Commit

Permalink
rearrange file layout
Browse files Browse the repository at this point in the history
  • Loading branch information
mfenner committed Oct 7, 2023
1 parent 4854ee2 commit b0d8435
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 384 deletions.
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11.5
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# TODO: Modify this Procfile to fit your needs
web: hypercorn -b 0.0.0.0:$PORT app:rogue_scholar
web: hypercorn -b 0.0.0.0:$PORT rogue_scholar_api:run
11 changes: 11 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os

basedir = os.path.abspath(os.path.dirname(__file__))


class Config:
SECRET_KEY = os.environ.get('SECRET_KEY')
SUPABASE_URL = os.environ.get("SUPABASE_URL")
SUPABASE_ANON_KEY = os.environ.get("SUPABASE_ANON_KEY")
TYPESENSE_API_KEY = os.environ.get("TYPESENSE_API_KEY")
TYPESENSE_HOST = os.environ.get("TYPESENSE_HOST")
390 changes: 18 additions & 372 deletions poetry.lock

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ readme = "README.md"
packages = [{include = "rogue_scholar_api"}]

[tool.poetry.dependencies]
python = "^3.9"
python = "^3.11"
Quart = "^0.19.2"
tox = "^4.11.3"
hypercorn = "^0.14.4"
Expand All @@ -21,11 +21,12 @@ commonmeta-py = "^0.8.4"


[tool.poetry.group.dev.dependencies]
pytest = "^7.4.2"
coverage = "*"
pytest = "^7.2.0"
pytest-cov = "^4.1.0"
pytest-recording = "^0.13.0"
ruff = "^0.0.292"
black = "^23.9.1"
pytest-asyncio = "^0.21.1"

[build-system]
requires = ["poetry-core"]
Expand All @@ -51,9 +52,15 @@ legacy_tox_ini = """
deps =
pytest
pytest-cov
commands = pytest --cov=commonmeta --cov-report=xml
commands = pytest --cov=rogue_scholar_api --cov-report=xml
[coverage:run]
relative_files = True
branch = True
"""

[tool.pytest.ini_options]
asyncio_mode = "auto"

[tool.poetry.scripts]
start = "rogue_scholar_api:run"
13 changes: 6 additions & 7 deletions rogue_scholar_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import os
from dotenv import load_dotenv
from uuid import UUID
from dotenv import load_dotenv
from supabase import create_client, Client as SupabaseClient
from quart import Quart, request, jsonify
import typesense as ts

from rogue_scholar_api.utils import get_doi_metadata_from_ra

# from typesense.exceptions import TypesenseClientError


app = Quart(__name__)

load_dotenv()
url: str = os.environ.get("SUPABASE_URL")
key: str = os.environ.get("SUPABASE_ANON_KEY")
Expand All @@ -35,6 +34,10 @@
)


def run() -> None:
app.run()


@app.route("/")
def default():
return "This is the Rogue Scholar API."
Expand Down Expand Up @@ -174,7 +177,3 @@ async def post(slug, suffix=None):
return jsonify(response.data)
except ValueError:
return {"error": "Not a valid uuid."}, 400


if __name__ == "__main__":
app.run()
24 changes: 24 additions & 0 deletions tests/test-routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from rogue_scholar_api import app
import pytest # noqa: F401
import pytest_asyncio # noqa: F401

pytestmark = pytest.mark.asyncio


async def test_index_route():
test_client = app.test_client()
response = await test_client.get("/")
assert response.status_code == 200
result = await response.data
print(result)
assert result == b"This is the Rogue Scholar API."


async def test_blogs_route():
test_client = app.test_client()
response = await test_client.get("/blogs")
assert response.status_code == 200
result = await response.get_json()
assert len(result) == 60
assert result[0]["title"] == "A blog by Ross Mounce"
assert result[0]["slug"] == "rossmounce"

0 comments on commit b0d8435

Please sign in to comment.