Skip to content

Commit e6f068e

Browse files
committed
add tests
1 parent 775e7fb commit e6f068e

6 files changed

Lines changed: 50 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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
test:
2+
pytest tests
3+
14
lint:
25
flake8 examples scitran_client
36

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)