Skip to content
Open
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
12 changes: 0 additions & 12 deletions app/models/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,6 @@ class ProfileModel(BaseModel):
description="Section the user belongs to.",
json_schema_extra={"example": "C"},
)
email: str | None = Field(
None,
title="Email",
description="Email address registered with PESU.",
json_schema_extra={"example": "johndoe@gmail.com"},
)
phone: str | None = Field(
None,
title="Phone Number",
description="Phone number registered with PESU.",
json_schema_extra={"example": "1234567890"},
)
campus_code: Literal[1, 2] | None = Field(
None,
title="Campus Code",
Expand Down
2 changes: 1 addition & 1 deletion app/models/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class RequestModel(BaseModel):
None,
title="Profile Fields",
description="List of profile fields to fetch. If omitted, all default fields will be returned.",
json_schema_extra={"example": ["name", "email", "campus", "branch", "semester"]},
json_schema_extra={"example": ["name", "campus", "branch", "semester"]},
)

@field_validator("username")
Expand Down
19 changes: 2 additions & 17 deletions app/pesu.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ class PESUAcademy:
"branch",
"semester",
"section",
"email",
"phone",
"campus_code",
"campus",
]
Expand Down Expand Up @@ -122,7 +120,7 @@ async def _get_client_with_csrf_token(self) -> tuple[httpx.AsyncClient, str]:
# Return a dedicated client/token for this request
return client_to_use, token_to_use

def _extract_and_update_profile(self, node: Node, idx: int, profile: dict) -> None:
async def _extract_and_update_profile(self, node: Node, idx: int, profile: dict) -> None:
"""Extract the profile data from a node and update the profile dictionary.

Args:
Expand Down Expand Up @@ -217,22 +215,9 @@ async def get_profile_information(
# Extract the profile information from the profile page
profile: dict[str, Any] = {}
for i in range(7):
self._extract_and_update_profile(details_nodes[i], i, profile)
await self._extract_and_update_profile(details_nodes[i], i, profile)

# Get the email and phone number from the profile page
if (
(email_node := soup.css_first("#updateMail"))
and (email_value := email_node.attributes.get("value"))
and isinstance(email_value, str)
):
profile["email"] = email_value.strip()

if (
(phone_node := soup.css_first("#updateContact"))
and (phone_value := phone_node.attributes.get("value"))
and isinstance(phone_value, str)
):
profile["phone"] = phone_value.strip()

# If username starts with PES1, then they are from RR campus, else if it is PES2, then EC campus
if profile.get("prn") and (campus_code_match := re.match(r"PES(\d)", profile["prn"])):
Expand Down
6 changes: 2 additions & 4 deletions tests/functional/test_authenticate_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ async def test_authenticate_with_all_profile_fields(pesu_academy: PESUAcademy):
"branch",
"semester",
"section",
"email",
"phone",
"campus_code",
"campus",
]
Expand All @@ -148,8 +146,8 @@ async def test_authenticate_with_all_profile_fields(pesu_academy: PESUAcademy):
assert profile["branch"] == branch
assert profile["semester"] == semester
assert profile["section"] == section
assert profile["email"] == email
assert profile["phone"] == phone
#assert profile["email"] == email
#assert profile["phone"] == phone
assert profile["campus_code"] == campus_code
assert profile["campus"] == campus

Expand Down
15 changes: 6 additions & 9 deletions tests/integration/test_app_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def client():
with TestClient(app, raise_server_exceptions=False) as client:
yield client


'''
@pytest.mark.secret_required
def test_integration_authenticate_success_username_email(client):
payload = {
Expand All @@ -38,7 +38,7 @@ def test_integration_authenticate_success_username_email(client):
assert "profile" not in data
assert "timestamp" in data
assert data["message"] == "Login successful."

'''

@pytest.mark.secret_required
def test_integration_authenticate_success_username_prn(client):
Expand All @@ -56,7 +56,7 @@ def test_integration_authenticate_success_username_prn(client):
assert "timestamp" in data
assert data["message"] == "Login successful."


'''
@pytest.mark.secret_required
def test_integration_authenticate_success_username_phone(client):
payload = {
Expand All @@ -72,7 +72,7 @@ def test_integration_authenticate_success_username_phone(client):
assert "profile" not in data
assert "timestamp" in data
assert data["message"] == "Login successful."

'''

@pytest.mark.secret_required
def test_integration_authenticate_with_specific_profile_fields(client):
Expand Down Expand Up @@ -132,7 +132,6 @@ def test_integration_authenticate_with_all_profile_fields(client):
campus = os.getenv("TEST_CAMPUS")

assert name is not None, "TEST_NAME environment variable not set"
assert email is not None, "TEST_EMAIL environment variable not set"
assert password is not None, "TEST_PASSWORD environment variable not set"
assert prn is not None, "TEST_PRN environment variable not set"
assert branch is not None, "TEST_BRANCH environment variable not set"
Expand All @@ -153,8 +152,6 @@ def test_integration_authenticate_with_all_profile_fields(client):
"branch",
"semester",
"section",
"email",
"phone",
"campus_code",
"campus",
]
Expand Down Expand Up @@ -182,8 +179,8 @@ def test_integration_authenticate_with_all_profile_fields(client):
assert profile["branch"] == branch
assert profile["semester"] == semester
assert profile["section"] == section
assert profile["email"] == email
assert profile["phone"] == phone
#assert profile["email"] == email
#assert profile["phone"] == phone
assert profile["campus_code"] == campus_code
assert profile["campus"] == campus

Expand Down
6 changes: 0 additions & 6 deletions tests/unit/test_pesu.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,13 @@ async def test_authenticate_with_profile_field_filtering(
mock_get_profile.return_value = {
"name": "Test User",
"prn": "PES12345",
"email": "test@example.com",
"branch": "Computer Science",
"campus": "RR",
}
result = await pesu.authenticate("testuser", "testpass", profile=True, fields=["name", "email"])
assert result["status"] is True
assert "profile" in result
assert "name" in result["profile"]
assert "email" in result["profile"]
assert "prn" not in result["profile"]
assert "branch" not in result["profile"]
assert "campus" not in result["profile"]
Expand Down Expand Up @@ -283,8 +281,6 @@ def css_first(selector):
assert profile["prn"] == "PES3XXXXX"
assert profile["name"] == "Test User"
assert profile["branch"] == "Computer Science and Engineering"
assert profile["email"] == "test@example.com"
assert profile["phone"] == "1234567890"
assert any(
"Unknown campus code: 3 parsed from PRN=PES3XXXXX for user=testuser" in record.message
for record in caplog.records
Expand Down Expand Up @@ -485,7 +481,5 @@ def test_default_fields_is_list():
assert "branch" in PESUAcademy.DEFAULT_FIELDS
assert "semester" in PESUAcademy.DEFAULT_FIELDS
assert "section" in PESUAcademy.DEFAULT_FIELDS
assert "email" in PESUAcademy.DEFAULT_FIELDS
assert "phone" in PESUAcademy.DEFAULT_FIELDS
assert "campus_code" in PESUAcademy.DEFAULT_FIELDS
assert "campus" in PESUAcademy.DEFAULT_FIELDS
4 changes: 2 additions & 2 deletions tests/unit/test_request_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def test_validate_fields_multiple_invalid_fields():


def test_validate_fields_valid_fields():
model = RequestModel(username="testuser", password="testpass", fields=["name", "email"])
assert model.fields == ["name", "email"]
model = RequestModel(username="testuser", password="testpass", fields=["name"])
assert model.fields == ["name"]


def test_validate_fields_none():
Expand Down