Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianHymer committed Oct 15, 2024
1 parent c7347cc commit 456684b
Show file tree
Hide file tree
Showing 20 changed files with 166 additions and 2,358 deletions.
117 changes: 56 additions & 61 deletions api/passport/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
from registry.api.utils import aapi_key, check_rate_limit, is_valid_address
from registry.exceptions import InvalidAddressException
from registry.models import BatchModelScoringRequest, BatchRequestStatus
from scorer import settings
from scorer.settings import (
BULK_MODEL_SCORE_REQUESTS_RESULTS_FOLDER,
BULK_SCORE_REQUESTS_BUCKET_NAME,
)
from scorer.settings.model_config import MODEL_AGGREGATION_NAMES

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -80,6 +75,62 @@ class PassportAnalysisError(APIException):
default_detail = "Error retrieving Passport analysis"


class DataScienceApiKey(APIKeyHeader):
param_name = "AUTHORIZATION"

def authenticate(self, request, key):
if key == settings.DATA_SCIENCE_API_KEY:
return key
return None


data_science_auth = DataScienceApiKey()


class BatchResponse(Schema):
created_at: str
s3_url: Optional[str]
status: BatchRequestStatus
percentage_complete: int


@api.get(
"/analysis/batch",
auth=data_science_auth,
response={
200: list[BatchResponse],
400: ErrorMessageResponse,
500: ErrorMessageResponse,
},
summary="Retrieve batch scoring status and result",
description="Retrieve batch scoring status and result",
include_in_schema=False,
)
def get_batch_analysis_stats(request, limit: int = 10) -> list[BatchResponse]:
requests = BatchModelScoringRequest.objects.order_by("-created_at")[:limit]
return [
BatchResponse(
created_at=req.created_at.isoformat(),
s3_url=(
get_s3_client().generate_presigned_url(
"get_object",
Params={
"Bucket": settings.BULK_SCORE_REQUESTS_BUCKET_NAME,
"Key": f"{settings.BULK_MODEL_SCORE_REQUESTS_RESULTS_FOLDER}/{req.s3_filename}",
},
# 24 hrs
ExpiresIn=60 * 60 * 24,
)
if req.status == BatchRequestStatus.DONE
else None
),
status=req.status,
percentage_complete=req.progress,
)
for req in requests
]


@api.get(
"/analysis/{address}",
auth=aapi_key,
Expand Down Expand Up @@ -297,59 +348,3 @@ async def get_model_responses(models: List[str], checksummed_address: str):

payload = {"address": checksummed_address}
return await fetch_all(urls, payload)


class DataScienceApiKey(APIKeyHeader):
param_name = "AUTHORIZATION"

def authenticate(self, request, key):
if key == settings.DATA_SCIENCE_API_KEY:
return key
return None


data_science_auth = DataScienceApiKey()


class BatchResponse(Schema):
created_at: str
s3_url: Optional[str]
status: BatchRequestStatus
percentage_complete: int


@api.get(
"/analysis",
auth=data_science_auth,
response={
200: list[BatchResponse],
400: ErrorMessageResponse,
500: ErrorMessageResponse,
},
summary="Retrieve batch scoring status and result",
description="Retrieve batch scoring status and result",
include_in_schema=False,
)
def get_batch_analysis_stats(request, limit: int = 10) -> list[BatchResponse]:
requests = BatchModelScoringRequest.objects.order_by("-created_at")[:limit]
return [
BatchResponse(
created_at=req.created_at.isoformat(),
s3_url=(
get_s3_client().generate_presigned_url(
"get_object",
Params={
"Bucket": BULK_SCORE_REQUESTS_BUCKET_NAME,
"Key": f"{BULK_MODEL_SCORE_REQUESTS_RESULTS_FOLDER}/{req.s3_filename}",
},
# 24 hrs
ExpiresIn=60 * 60 * 24,
)
if req.status == BatchRequestStatus.DONE
else None
),
status=req.status,
percentage_complete=req.progress,
)
for req in requests
]
2 changes: 1 addition & 1 deletion api/passport/test/test_data_science_bulk_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def batch_requests():
return requests


api_url = "/passport/analysis"
api_url = "/passport/analysis/batch"


def test_get_batch_analysis_stats_success(client, batch_requests, mocker):
Expand Down
184 changes: 0 additions & 184 deletions api/registry/test/test_command_delete_user_data.py

This file was deleted.

Loading

0 comments on commit 456684b

Please sign in to comment.