Skip to content

Add health-check, operations (skeleton) endpoints and unit tests #3

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Muntaser-Abukhadijah
Copy link
Collaborator

No description provided.

@AliOsm
Copy link
Member

AliOsm commented May 3, 2025

We need to fix this:

‏لقطة الشاشة ٢٠٢٥-٠٥-٠٣ في ٨ ٤٥ ٤٦ ص

It should run either for push or pull, not booth of them.

@AliOsm
Copy link
Member

AliOsm commented May 3, 2025

Also, the project configs are not consistent. Make sure to update them and run the CI locally to check if it is passing.

‏لقطة الشاشة ٢٠٢٥-٠٥-٠٣ في ٨ ٤٦ ٣٥ ص

@router.get("/health", tags=["Health"])
async def health_check():
"""Simple health-check endpoint"""
return {"status": "ok", "version": "v1"}

Choose a reason for hiding this comment

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

What does "version" here represent?

Copy link
Member

Choose a reason for hiding this comment

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

I think we can remove the version from this endpoint.

@router.get("/health", tags=["Health"])
async def health_check():
"""Simple health-check endpoint"""
return {"status": "ok", "version": "v1"}
Copy link
Member

Choose a reason for hiding this comment

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

I think we can remove the version from this endpoint.


@router.get("/health", tags=["Health"])
async def health_check():
"""Simple health-check endpoint"""
Copy link
Member

Choose a reason for hiding this comment

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

No need for this comment.

)

app.include_router(health_router, prefix="/api")
app.include_router(operations_router, prefix="/api/v1")
Copy link
Member

Choose a reason for hiding this comment

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

Make sure to add a newline at the end of each file. @IbraheemTuffaha the template should implement such thing.

@@ -0,0 +1,16 @@
from fastapi import APIRouter, HTTPException, status

from app.v1.models.operations_request import OperationsRequest
Copy link
Member

Choose a reason for hiding this comment

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

You can simplify the imports by writing:

from app.v1.models import OperationRequest

If you add a file named __init__.py under app/v1/models and put the following inside it:

from app.v1.models.operation_request import OperationRequest


__all__ = ['OperationRequest']

This way you will have more simpler imports over the app.

Comment on lines +4 to +5
from app.v1.models.operations_response import OperationsResponse
router = APIRouter()
Copy link
Member

Choose a reason for hiding this comment

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

Make sure to split imports from global variables by 2 lines. @IbraheemTuffaha the template should handle such thing.

surah_number: int = Field(..., title="Surah Number",
description="Number of the Surah in the Quran.")
ayah_start: int = Field(..., title="Starting Ayah",
description="Ayah (verse) number where the match starts in the Surah.")
description="Ayah (ayah) number where the match starts in the Surah.")
Copy link
Member

Choose a reason for hiding this comment

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

(ayah) is duplicated, and the same comment from Correction model, I don't see a huge value from the title and description tbh.

Same applies for other models/attributes.

min_match: int = Field(3, title="Min Match Length",
description="Minimum word count for a valid match.")
description="Minimum word count for a valid match.")
return_json: bool = Field(False, title="Return JSON",
Copy link
Member

Choose a reason for hiding this comment

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

Sorry if I missed this from the design doc, but what is the difference between passing/not passing this argument? And why not always return the structured JSON?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wanted to maintain the output format to be same output as in original package.

Copy link
Member

Choose a reason for hiding this comment

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

I think the API is a special case, so let's return JSON always as it is the standard for API responses.

matches: Optional[list[AyahMatch]] = Field(
None, title="Detected Ayaht",
Copy link
Member

Choose a reason for hiding this comment

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

I think this is Ayat?

from app.v1.models.correction import Correction


def test_valid_correction():
Copy link
Member

Choose a reason for hiding this comment

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

Why not used correction_dict from conftest.py? tbh, I don't feel that having correction_dict and ayah_match_dict in the conftest.py is appropriate.

If you want to keep the fixtures in conftest.py, then let's make sure we are consistent and using this approach in all tests.

assert errors[0]["type"].startswith("enum")


@pytest.mark.parametrize("bad_pct, expected_type", [
Copy link
Member

Choose a reason for hiding this comment

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

Let's use full names, bad_percentage instead of bad_pct. Same applies for other places.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants