-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from TheJacksonLaboratory/task/prepare-for-0-3…
…-0-release Task/prepare for 0 3 0 release
- Loading branch information
Showing
13 changed files
with
243 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Tests for the project query module.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Tests for the publication query generation functions.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |