feat: add KYCAS#148
Conversation
aditeyabaral
left a comment
There was a problem hiding this comment.
Looks good, cannot comment on whether it functionally works. Please test thoroughly once it is deployed to dev. Make the following cosmetic changes and respond to the questions I've posted.
You should also update all the documentation in the README to include this feature.
| "profile": True, | ||
| }, | ||
| }, | ||
| "auth_with_class_and_section": { |
There was a problem hiding this comment.
Lets rename to auth_with_kycas
| }, | ||
| }, | ||
| "authentication_with_kycas": { | ||
| "summary": "Authentication with KYCAS", |
| }, | ||
| "auth_with_class_and_section": { | ||
| "summary": "Authentication with KYCAS", | ||
| "description": "Authentication with Know Your Class and Section data", |
There was a problem hiding this comment.
Maybe add a "..." (quotes) to emphasize the phrase
| }, | ||
| }, | ||
| "kycas_fetch_error": { | ||
| "summary": "KYCAS page fetching failed", |
There was a problem hiding this comment.
Expand the acronym (all expansions should have quotes)
| }, | ||
| }, | ||
| "auth_with_class_and_section": { | ||
| "summary": "Authentication with KYCAS", |
There was a problem hiding this comment.
Where does the summary field show up? If it is user-facing, use the expansion with quotes
| class KYCASModel(BaseModel): | ||
| """Model representing the Know Your Class and Section data.""" | ||
|
|
||
| model_config = ConfigDict(populate_by_name=True) |
There was a problem hiding this comment.
Why do we not use model_config = ConfigDict(strict=True) like other models?
| validation_alias="class", | ||
| serialization_alias="class", | ||
| title="Class", | ||
| description="Class of the user.", |
There was a problem hiding this comment.
Fix grammar. User belongs to a class, user does not have a class. Same for section, department. (follow the template for section).
| cycle: str | None = Field( | ||
| None, | ||
| title="Cycle", | ||
| description="Cycle of the user.", | ||
| json_schema_extra={"example": "NA"}, | ||
| ) | ||
| department: str | None = Field( | ||
| None, | ||
| title="Department", | ||
| description="Department of the user.", | ||
| json_schema_extra={"example": "Computer Science and Engineering"}, | ||
| ) |
| institute_name: str | None = Field( | ||
| None, | ||
| title="Institute Name", | ||
| description="Institute name of the user.", |
| username (str): The username of the user, usually their PRN/email/phone number. | ||
| password (str): The password of the user. | ||
| profile (bool, optional): Whether to fetch the profile information or not. Defaults to False. | ||
| know_your_class_and_section (bool, optional): Whether to fetch the class and section |
📌 Description
Re-introduce Know Your Class and Section (KYCAS) data into the PESUAuth API by restoring the old
get_know_your_class_and_section()helper, adapted to use the new authenticated PESU Academy endpointPOST /Academy/a/getStudentClassInfo.The previous public endpoint (
/Academy/getStudentClassInfo) was deprecated by PESU Academy and now returns 404. The new endpoint requires an authenticated session (JSESSIONID + CSRF token) that the login step already provides. This PR uses that authenticated session transparently — no additional API parameter or round-trip is needed from the user's perspective.know_your_class_and_sectionboolean parameter back to theauthenticate()method (defaultfalse)know_your_class_and_sectionkey in the responsePOST /Academy/a/getStudentClassInforequirescontrollerMode=370,actionType=174, andloginId=<SRN>, all of which are handled internallyfieldsparam) applies to bothprofileandknow_your_class_and_sectionindependently, matching the original behaviorKYCASFetchError(HTTP 502) with the same error-handling pattern as other upstream failures🧱 Type of Change
🧪 How Has This Been Tested?
tests/unit/)tests/functional/)tests/integration/)✅ Checklist
scripts/run_tests.py)pre-commit run --all-files).envvars updated (if applicable)scripts/benchmark/benchmark_requests.py)🛠️ Affected API Behaviour
app/app.py– Modified/authenticateroute logicapp/pesu.py– Updated scraping or authentication handling🧩 Models
app/models/request.py– Input validation or request schema changesapp/models/response.py– Authentication response formattingapp/models/profile.py– Profile extraction logicapp/models/kycas.py– New KYCAS response model🐳 DevOps & Config
Dockerfile– Changes to base image or build process.github/workflows/*.yaml– CI/CD pipeline or deployment updatespyproject.toml/requirements.txt– Dependency version changes.pre-commit-config.yaml– Linting or formatting hook changes📊 Benchmarks & Analysis
scripts/benchmark_auth.py– Performance or latency measurement changesscripts/analyze_benchmark.py– Benchmark result analysis changesscripts/run_tests.py– Custom test runner logic or behavior updates📸 Screenshots / API Demos
🧠 Additional Notes
Implementation details
get_know_your_class_and_section()usedBeautifulSoup; the new version usesselectolax.HTMLParserfor consistency with the rest of the codebaseKYCASModelusesvalidation_alias="class"/serialization_alias="class"becauseclassis a Python reserved keyword, accessed internally asclass_fieldmodel_dump(by_alias=True)was added inapp.pyto ensureclass_fieldserializes as"class"in JSON output (no-op forProfileModelsince it has no aliases)Files changed
app/exceptions/authentication.pyKYCASFetchError(HTTP 502)app/models/kycas.pyapp/models/__init__.pyKYCASModelapp/models/request.pyknow_your_class_and_section: boolfieldapp/models/response.pyknow_your_class_and_section: KYCASModelfieldapp/pesu.pyKYCAS_HEADER_TO_KEY_MAP,get_know_your_class_and_section()method,know_your_class_and_sectionparam onauthenticate(), updatedDEFAULT_FIELDSapp/app.pyby_alias=Trueinmodel_dumpapp/docs/authenticate.py