Skip to content

Commit

Permalink
Cleanup of batch code and associated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bergsalex committed Dec 4, 2023
1 parent fb23582 commit 44b0668
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 64 deletions.
57 changes: 2 additions & 55 deletions src/geneweaver/api/schemas/batch.py
Original file line number Diff line number Diff line change
@@ -1,65 +1,12 @@
"""Module for defining schemas for batch endpoints."""
from typing import List, Optional

from pydantic import BaseModel, validator
from geneweaver.core.parse.score import parse_score
from typing import List

from geneweaver.api.schemas.messages import MessageResponse
from geneweaver.api.schemas.score import GenesetScoreType
from pydantic import BaseModel


class BatchResponse(BaseModel):
"""Class for defining a response containing batch results."""

genesets: List[int]
messages: MessageResponse


class Publication(BaseModel):
authors: str
title: str
abstract: str
journal: str
volume: str
pages: str
month: str
year: str
pubmed: str


class GenesetValueInput(BaseModel):
symbol: str
value: float


class GenesetValue(BaseModel):
ode_gene_id: str
value: float
ode_ref_id: str
threshold: bool


class BatchUploadGeneset(BaseModel):
score: GenesetScoreType
# TODO: Use enum from core
species: str
gene_id_type: str
pubmed_id: str
private: bool = True
curation_id: Optional[int] = None
abbreviation: str
name: str
description: str
values: List[GenesetValueInput]

@validator("score", pre=True)
def initialize_score(cls, v):
return parse_score(v)

@validator("private", pre=True)
def private_to_bool(cls, v):
return v.lower() != "public"

@validator("curation_id", pre=True)
def curation_id_to_int(cls, v, values):
return 5 if values["private"] else 4
16 changes: 8 additions & 8 deletions src/geneweaver/api/services/parse/batch.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
"""Functions for processing batch files.
Most of the functionality for processing batch files is contained in the
geneweaver.core module. This module contains functions for reading the contents
of a file and passing those contents to the core module for processing.
"""
from typing import List, Tuple
from fastapi import UploadFile

from fastapi import UploadFile
from geneweaver.api.services.io import read_file_contents
from geneweaver.core.parse import batch
from geneweaver.core.schema.messages import SystemMessage, UserMessage


from geneweaver.api.services.io import read_file_contents


async def process_batch_file(
# TODO: Add the database session to the function signature.
# db: Session,
Expand Down Expand Up @@ -38,10 +42,6 @@ async def process_batch_file(
print(geneset, "\n")

# TODO: Add the genesets to the database
# results = [
# batch_geneset_for_user(db, user_id, geneset)
# for geneset in genesets
# ]

# TODO: Return the correct values.
return [10], [], []
5 changes: 4 additions & 1 deletion tests/services/parse/batch/conftest.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
"""Pytest fixtures for the batch parsing service tests."""
from unittest.mock import AsyncMock

import pytest
from fastapi import UploadFile

from tests.api.unit.services.parse.batch import const
from tests.services.parse.batch import const


# Create a pytest fixture for the mocked UploadFile
@pytest.fixture()
def mock_upload_file():
"""Provide a mocked UploadFile object."""
mock_file = AsyncMock(spec=UploadFile)
return mock_file # provide the mock object to the test

Expand All @@ -23,4 +25,5 @@ def mock_upload_file():
]
)
def example_batch_file_contents(request) -> str:
"""Provide the contents of the example batch file."""
return request.param
1 change: 1 addition & 0 deletions tests/services/parse/batch/const.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Constants for batch parsing tests."""
# ruff: noqa: E501
EXAMPLE_BATCH_FILE = """
# This is an example batch upload file for GeneWeaver.
Expand Down
1 change: 1 addition & 0 deletions tests/services/parse/batch/test_parse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Test for the parsing service."""

0 comments on commit 44b0668

Please sign in to comment.