Skip to content

Commit

Permalink
DEV-46 fix _stats endpoint. add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anmaxvl committed Feb 13, 2020
1 parent 2515601 commit de1ac6e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,4 @@ swagger-codegen-cli-2.3.1.jar

# IDE
.vscode
.idea
4 changes: 2 additions & 2 deletions indexd/index/drivers/alchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1090,10 +1090,10 @@ def totalbytes(self):
Total number of bytes of data represented in the index.
"""
with self.session as session:
result = session.execute(select([func.sum(IndexRecord.size)])).scalar()
result = session.query(func.sum(IndexRecord.size)).scalar()
if result is None:
return 0
return long(result)
return int(result)

def len(self):
"""
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ sqlalchemy==1.3.3
sqlalchemy-utils>=0.32.21
psycopg2>=2.7
future==0.18.1
Werkzeug~=0.16.0
-e git+https://github.com/NCI-GDC/[email protected]#egg=indexclient
-e git+https://github.com/uc-cdis/[email protected]#egg=cdislogging
-e git+https://github.com/uc-cdis/[email protected]#egg=doiclient
Expand Down
5 changes: 3 additions & 2 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mock
pytest==3.0.6
pytest-flask==0.8.1
pytest~=3.10.1
pytest-flask~=0.15.0
pytest-cov
PyYAML
swagger_spec_validator
17 changes: 17 additions & 0 deletions tests/test_driver_alchemy_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,21 @@
from indexd.index.errors import NoRecordFound, RevisionMismatch
from tests.util import make_sql_statement


#TODO check if pytest has utilities for meta-programming of tests


@pytest.fixture(params=([], [1, 2, 3], [20, 10000000000000000]))
def records_with_size(request, index_driver):
with index_driver.session as sxn:
for s in request.param:
record = IndexRecord(did=str(uuid.uuid4()), baseid=str(uuid.uuid4()),
rev=str(uuid.uuid4())[:8], size=s)
sxn.add(record)

return request.param


def insert_base_data(database_conn):
did = str(uuid.uuid4())
baseid = str(uuid.uuid4())
Expand All @@ -24,6 +36,11 @@ def insert_base_data(database_conn):
return did, baseid, rev, form


def test_get_total_bytes(index_driver, records_with_size):
"""Test that totalbytes return expected results"""
assert sum(records_with_size) == index_driver.totalbytes()


def test_driver_init_does_not_create_records(index_driver, database_conn):
"""
Tests for creation of records after driver init.
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ commands=
wget https://oss.sonatype.org/content/repositories/releases/io/swagger/swagger-codegen-cli/2.3.1/swagger-codegen-cli-2.3.1.jar
java -jar swagger-codegen-cli-2.3.1.jar generate -i openapis/swagger.yaml -l python -o swagger_client
bash -ec "cd swagger_client/; python setup.py install; cd .."
py.test {posargs: -lvv tests/}
py.test {posargs: --cov=indexd -lvv tests/}

0 comments on commit de1ac6e

Please sign in to comment.