Coverage for src/usaspending/queries/award_query.py: 95%
21 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-03 17:15 -0700
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-03 17:15 -0700
1from typing import TYPE_CHECKING
2from .single_resource_base import SingleResourceBase
3from ..exceptions import ValidationError
4from ..client import USASpending
5from ..logging_config import USASpendingLogger
7if TYPE_CHECKING:
8 from ..models.award import Award
10logger = USASpendingLogger.get_logger(__name__)
13class AwardQuery(SingleResourceBase):
14 """Retrieve a single-award from the USAspending API."""
16 def __init__(self, client: USASpending):
17 super().__init__(client)
18 logger.debug("AwardQuery initialized with client: %s", client)
20 @property
21 def _endpoint(self) -> str:
22 """Base endpoint for single award retrieval."""
23 return "/awards/"
25 def find_by_id(self, award_id: str) -> "Award":
26 """Filter by unique award identifier."""
27 return self.find_by_generated_id(award_id)
29 def find_by_generated_id(self, award_id: str) -> "Award":
30 """Filter by USASpending's internally generated unique award identifier."""
31 if not award_id:
32 raise ValidationError("award_id is required")
34 # Make API request
35 response = self._get_resource(award_id)
37 # Create model instance using factory
38 from ..models.award_factory import create_award
40 return create_award(response, client=self._client)