Skip to content

Commit

Permalink
Merge pull request #30 from TheJacksonLaboratory/task/prepare-for-0-3…
Browse files Browse the repository at this point in the history
…-0-release

Task/prepare for 0 3 0 release
  • Loading branch information
bergsalex authored Apr 22, 2024
2 parents 425a921 + 13a664c commit a133dec
Show file tree
Hide file tree
Showing 13 changed files with 243 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/geneweaver/db/query/geneset/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ def get(
return query, params


def shared_with_user(
user_id: int,
limit: Optional[int] = None,
offset: Optional[int] = None,
with_publication_info: bool = True,
) -> Tuple[Composed, dict]:
"""Get Genesets that are shared with a user.
NOTE: NOT IMPLEMENTED
"""
raise NotImplementedError()


def by_project_id(
project_id: int,
limit: Optional[int] = None,
Expand Down
46 changes: 46 additions & 0 deletions src/geneweaver/db/query/project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Query generation functions for projects."""

from typing import Optional, Tuple

from psycopg.sql import Composed


def get(
project_id: Optional[int] = None,
owner_id: Optional[int] = None,
name: Optional[str] = None,
starred: Optional[bool] = None,
search_text: Optional[str] = None,
limit: Optional[int] = None,
offset: Optional[int] = None,
) -> Tuple[Composed, dict]:
"""Get projects by any filtering criteria.
NOTE: NOT IMPLEMENTED
"""
raise NotImplementedError()


def shared_with_user(
user_id: int,
limit: Optional[int] = None,
offset: Optional[int] = None,
) -> Tuple[Composed, dict]:
"""Get project that are shared with a user.
NOTE: NOT IMPLEMENTED
"""
raise NotImplementedError()


def add(
user_id: int,
name: str,
notes: str,
starred: bool = False,
) -> Tuple[Composed, dict]:
"""Add a new publication.
NOTE: NOT IMPLEMENTED
"""
raise NotImplementedError()
22 changes: 22 additions & 0 deletions src/geneweaver/db/query/publication.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,28 @@
)


def get(
pub_id: Optional[int] = None,
authors: Optional[str] = None,
title: Optional[str] = None,
abstract: Optional[str] = None,
journal: Optional[str] = None,
volume: Optional[str] = None,
pages: Optional[str] = None,
month: Optional[str] = None,
year: Optional[str] = None,
pubmed: Optional[str] = None,
search_text: Optional[str] = None,
limit: Optional[int] = None,
offset: Optional[int] = None,
) -> Tuple[Composed, dict]:
"""Get publications by some criteria.
NOTE: NOT IMPLEMENTED
"""
raise NotImplementedError()


def by_id(pub_id: int) -> Optional[rows.Row]:
"""Create a psycopg query to get a publication by ID.
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/query/geneset/test_shared_with_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""Test the geneset.shared_with_user query function."""

import pytest
from geneweaver.db.query.geneset.read import shared_with_user


def test_shared_with_user_raises_not_implemented():
"""Test that the shared_with_user function raises a NotImplementedError."""
with pytest.raises(NotImplementedError):
_ = shared_with_user(user_id=1)
1 change: 1 addition & 0 deletions tests/unit/query/project/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Tests for the project query module."""
10 changes: 10 additions & 0 deletions tests/unit/query/project/test_add.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""Test the project.add query generation function."""

import pytest
from geneweaver.db.query.project import add


def test_add_raise_not_implemented():
"""Test that the add function raises a NotImplementedError."""
with pytest.raises(NotImplementedError):
_ = add(user_id=1, name="test", notes="notes", starred=True)
18 changes: 18 additions & 0 deletions tests/unit/query/project/test_get.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Test the project.get query generation function."""

import pytest
from geneweaver.db.query.project import get


def test_get_raise_not_implemented():
"""Test that the get function raises a NotImplementedError."""
with pytest.raises(NotImplementedError):
_ = get(
project_id=1,
owner_id=1,
name="test",
starred=True,
search_text="search",
limit=1,
offset=10,
)
14 changes: 14 additions & 0 deletions tests/unit/query/project/test_shared_with_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""Test the project.shared_with_user query generation function."""

import pytest
from geneweaver.db.query.project import shared_with_user


def test_shared_with_user_raise_not_implemented():
"""Test that the shared_with_user function raises a NotImplementedError."""
with pytest.raises(NotImplementedError):
_ = shared_with_user(
user_id=1,
limit=1,
offset=10,
)
1 change: 1 addition & 0 deletions tests/unit/query/publication/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Tests for the publication query generation functions."""
51 changes: 51 additions & 0 deletions tests/unit/query/publication/test_add.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""Test the publication.add query generation function."""

import pytest
from geneweaver.db.query.publication import add
from psycopg.sql import SQL, Composed, Identifier, Placeholder


@pytest.mark.parametrize(
"authors",
["Author 1", "Author 1, Author 2", "Author 1, Author 2, Author 3, et al."],
)
@pytest.mark.parametrize(
"title", ["Title 1", "Title 1: Subtitle", "Title 1: Subtitle, Part 2"]
)
@pytest.mark.parametrize(
"abstract",
[
"Abstract 1",
"Abstract 1: Subabstract",
"Abstract 1: Subabstract, Part 2",
"A very long abstract" * 100,
],
)
@pytest.mark.parametrize(
"journal", ["Journal 1", "Journal 1: Subjournal", "Journal 1: Subjournal, Part 2"]
)
@pytest.mark.parametrize(
"pubmed_id", ["12345678", "23456789", "34567890", "45678901", "1234"]
)
def test_add_types(authors, title, abstract, journal, pubmed_id):
"""Test the add query generation function."""
query, params = add(authors, title, abstract, journal, pubmed_id)
assert isinstance(query, Composed)
assert isinstance(params, dict)
for item in query:
assert any(
isinstance(item, t) for t in [SQL, Composed, Identifier, Placeholder]
)

for item in params.values():
if item is not None:
assert isinstance(item, str)
assert item in [authors, title, abstract, journal, pubmed_id]

values = [item for item in params.values() if item is not None]
assert len(values) == 5
assert authors in values
assert title in values
assert abstract in values
assert journal in values
assert pubmed_id in values
10 changes: 10 additions & 0 deletions tests/unit/query/publication/test_get.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""Test the publication.get query function."""

import pytest
from geneweaver.db.query.publication import get


def test_get_raises_not_implemented():
"""Test that the get function raises a NotImplementedError."""
with pytest.raises(NotImplementedError):
_ = get()
24 changes: 24 additions & 0 deletions tests/unit/query/publication/test_pub_insert_cols.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""Test the PUB_INSERT_COLS generated constant."""

from psycopg.sql import SQL, Identifier


def test_pub_insert_cols_types():
"""Test the PUB_INSERT_COLS generated constant."""
from geneweaver.db.query.publication import PUB_INSERT_COLS

for idx, value in enumerate(PUB_INSERT_COLS):
assert "pub_id" not in str(value)
if idx % 2 == 0:
assert isinstance(value, Identifier)
else:
assert isinstance(value, SQL)
assert value == SQL(",")


def test_pub_id_not_in_pub_insert_cols():
"""Test the PUB_INSERT_COLS generated constant."""
from geneweaver.db.query.publication import PUB_INSERT_COLS

for value in PUB_INSERT_COLS:
assert "pub_id" not in str(value)
23 changes: 23 additions & 0 deletions tests/unit/query/publication/test_pub_insert_vals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""Test the PUB_QUERY generated constant."""

from psycopg.sql import SQL, Placeholder


def test_pub_insert_vals_types():
"""Test the PUB_INSERT_COLS generated constant."""
from geneweaver.db.query.publication import PUB_INSERT_VALS

for idx, value in enumerate(PUB_INSERT_VALS):
if idx % 2 == 0:
assert isinstance(value, Placeholder)
else:
assert isinstance(value, SQL)
assert value == SQL(",")


def test_pub_id_not_in_pub_insert_vals():
"""Test that the pub_id is not in the PUB_INSERT_VALS constant."""
from geneweaver.db.query.publication import PUB_INSERT_VALS

for value in PUB_INSERT_VALS:
assert "pub_id" not in str(value)

0 comments on commit a133dec

Please sign in to comment.