diff --git a/.gitignore b/.gitignore index 4c1bca00..07da4655 100644 --- a/.gitignore +++ b/.gitignore @@ -72,3 +72,4 @@ swagger-codegen-cli-2.3.1.jar # IDE .vscode +.idea diff --git a/indexd/index/drivers/alchemy.py b/indexd/index/drivers/alchemy.py index e38c545c..049507c1 100644 --- a/indexd/index/drivers/alchemy.py +++ b/indexd/index/drivers/alchemy.py @@ -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): """ diff --git a/requirements.txt b/requirements.txt index bdf0d4c8..d5674514 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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/indexclient.git@1.5.10#egg=indexclient -e git+https://github.com/uc-cdis/cdislogging.git@0.0.2#egg=cdislogging -e git+https://github.com/uc-cdis/doiclient.git@1.0.0#egg=doiclient diff --git a/test-requirements.txt b/test-requirements.txt index 0113ed43..fb66794c 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -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 diff --git a/tests/test_driver_alchemy_crud.py b/tests/test_driver_alchemy_crud.py index b74e6dfe..372f37f3 100644 --- a/tests/test_driver_alchemy_crud.py +++ b/tests/test_driver_alchemy_crud.py @@ -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()) @@ -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. diff --git a/tox.ini b/tox.ini index eb5afcf2..d3b530fe 100644 --- a/tox.ini +++ b/tox.ini @@ -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/}