Skip to content

Commit 5299370

Browse files
authored
Merge pull request #5 from scitran/tests
add tests
2 parents 775e7fb + d569d3a commit 5299370

7 files changed

Lines changed: 54 additions & 1 deletion

File tree

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ install:
77
- "pip install --upgrade pip"
88
- "pip install -r requirements.txt"
99

10-
script: "make lint"
10+
script:
11+
- "make lint"
12+
- "make test"

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
test:
2+
# hack to avoid needing to install this package
3+
# from http://stackoverflow.com/a/34140498
4+
python -m pytest tests
5+
16
lint:
27
flake8 examples scitran_client
38

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ urllib3==1.15.1
3333
websocket-client==0.37.0
3434
flake8==3.0.4
3535
pdoc==0.3.2
36+
pytest==3.0.6
37+
requests-mock==1.3.0

tests/fixtures/test.csv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
condition,onset
2+
red,0
3+
blue,3
4+
red,6

tests/test_query_builder.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from scitran_client import query, Projects, Sessions, Groups
2+
3+
4+
def test_query():
5+
assert query(Sessions).filter(
6+
Projects.label.match('ADHD cuing task'),
7+
Groups.label.match('ADHDLab'),
8+
) == dict(
9+
path='sessions',
10+
projects=dict(filtered=dict(filter={'and': [
11+
dict(query=dict(match=dict(label='ADHD cuing task'))),
12+
]})),
13+
groups=dict(filtered=dict(filter={'and': [
14+
dict(query=dict(match=dict(label='ADHDLab'))),
15+
]})),
16+
)

tests/test_st_auth.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import requests_mock
2+
from scitran_client.st_auth import _is_valid_token
3+
4+
host = 'https://flywheel.io'
5+
6+
7+
@requests_mock.mock()
8+
def test_is_valid_token(mock):
9+
mock.get('{}/api/users/self'.format(host), status_code=200)
10+
assert _is_valid_token(host, 'yep')
11+
12+
13+
@requests_mock.mock()
14+
def test_is_valid_token_invalid(mock):
15+
mock.get('{}/api/users/self'.format(host), status_code=401)
16+
assert not _is_valid_token(host, 'yep')

tests/test_st_client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from scitran_client import compute_file_hash
2+
import os
3+
4+
5+
def test_compute_file_hash():
6+
assert compute_file_hash(
7+
os.path.join(os.path.dirname(__file__), 'fixtures/test.csv')
8+
) == 'v0-sha384-301d915f78736ff43dd396b5607cade4dffc0cd31c94bb2b80aff005cac042d8826a0a766c5dc2884a942cf960177378'

0 commit comments

Comments
 (0)