Skip to content

Commit

Permalink
fix: resolve 404 error.
Browse files Browse the repository at this point in the history
  • Loading branch information
hamed-valiollahi committed Dec 31, 2024
1 parent d62ab2a commit 1399ddf
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 30 deletions.
12 changes: 9 additions & 3 deletions backend/lcfs/tests/audit_log/test_audit_log_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,15 @@ async def test_get_audit_logs_paginated_no_data(audit_log_service, mock_repo):
pagination = PaginationRequestSchema(page=1, size=10, filters=[], sort_orders=[])
mock_repo.get_audit_logs_paginated.return_value = ([], 0)

# Act & Assert
with pytest.raises(DataNotFoundException):
await audit_log_service.get_audit_logs_paginated(pagination)
# Act
result = await audit_log_service.get_audit_logs_paginated(pagination)

# Assert
assert result.audit_logs == [], "Should return an empty list of audit logs"
assert result.pagination.total == 0, "Total should be zero if no records"
assert result.pagination.page == pagination.page
assert result.pagination.size == pagination.size
assert result.pagination.total_pages == 0


@pytest.mark.anyio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,30 @@ async def test_get_compliance_reports_paginated_success(
async def test_get_compliance_reports_paginated_not_found(
compliance_report_service, mock_repo
):
# Arrange
pagination_mock = AsyncMock()
pagination_mock.page = 1
pagination_mock.size = 10
pagination_mock.filters = []
pagination_mock.sort_orders = []

# Mock the repository to return no records
mock_repo.get_reports_paginated.return_value = ([], 0)

with pytest.raises(DataNotFoundException):
await compliance_report_service.get_compliance_reports_paginated(
pagination_mock
)
# Act
result = await compliance_report_service.get_compliance_reports_paginated(
pagination_mock
)

# Assert: Verify the service returns an empty list and correct pagination metadata
assert result.reports == [], "Expected no compliance reports to be returned"
assert result.pagination.total == 0, "Expected total=0 when there are no records"
assert result.pagination.page == 1, "Page should match the requested page"
assert result.pagination.size == 10, "Size should match the requested size"
assert result.pagination.total_pages == 0, "0 records should yield 0 total_pages"

# Also verify our repo was called exactly once
mock_repo.get_reports_paginated.assert_called_once()


@pytest.mark.anyio
Expand Down
3 changes: 0 additions & 3 deletions backend/lcfs/web/api/audit_log/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ async def get_audit_logs_paginated(
offset, limit, conditions, pagination.sort_orders
)

if not audit_logs:
raise DataNotFoundException("No audit logs found")

processed_audit_logs = []
for audit_log in audit_logs:
# Extract the changed_fields as a comma-separated string
Expand Down
5 changes: 1 addition & 4 deletions backend/lcfs/web/api/compliance_report/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,7 @@ async def get_compliance_reports_paginated(
pagination, organization_id
)

if not reports:
raise DataNotFoundException("No compliance reports found.")

if bceid_user:
if bceid_user and reports:
reports = self._mask_report_status(reports)

return ComplianceReportListSchema(
Expand Down
9 changes: 3 additions & 6 deletions backend/lcfs/web/api/notification/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ def _apply_notification_filters(
)
)
elif filter.field == "transaction_id":
field = get_field_for_filter(NotificationMessage, 'related_transaction_id')
field = get_field_for_filter(
NotificationMessage, "related_transaction_id"
)
conditions.append(
apply_filter_conditions(
field, filter_value, filter_option, filter_type
Expand Down Expand Up @@ -353,11 +355,6 @@ async def get_notification_channel_subscriptions_by_user(
result = await self.db.execute(query)
subscriptions = result.scalars().all()

if not subscriptions:
raise DataNotFoundException(
f"Channel subscriptions not found for user id: '{user_profile_id}'"
)

return subscriptions

@repo_handler
Expand Down
5 changes: 1 addition & 4 deletions backend/lcfs/web/api/organization/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def apply_transaction_filters(self, pagination, conditions):
# For non-date filters, use the standard filter value
filter_value = filter.filter

if field.description == 'transaction_type':
if field.description == "transaction_type":
filter_value = filter_value.replace(" ", "").lower()

filter_option = filter.type
Expand Down Expand Up @@ -169,9 +169,6 @@ async def get_transactions_paginated(
)
)

if not transactions:
raise DataNotFoundException("Transactions not found")

return {
"transactions": [
TransactionViewSchema.model_validate(transaction)
Expand Down
3 changes: 0 additions & 3 deletions backend/lcfs/web/api/organizations/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,6 @@ async def get_organizations(
offset, limit, conditions, pagination
)

if not organizations:
raise DataNotFoundException("Organizations not found")

return OrganizationListSchema(
organizations=organizations,
pagination=PaginationResponseSchema(
Expand Down
3 changes: 0 additions & 3 deletions backend/lcfs/web/api/transaction/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ async def get_transactions_paginated(
offset, limit, conditions, pagination.sort_orders, None
)

if not transactions:
raise DataNotFoundException("Transactions not found")

return {
"transactions": [
TransactionViewSchema.model_validate(transaction)
Expand Down

0 comments on commit 1399ddf

Please sign in to comment.