Skip to content

Commit

Permalink
Merge pull request #40 from poldracklab/oesteban-patch-1
Browse files Browse the repository at this point in the history
[FIX] Do not pin versions
  • Loading branch information
oesteban authored Jul 19, 2018
2 parents f5fce8d + 69504a3 commit cd79e94
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 81 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
working_directory: /home/circleci/mriqcwebapi

machine:
image: circleci/classic:201711-01
image: circleci/classic:latest

environment:
- SECRET_KEY: CI
Expand All @@ -28,7 +28,7 @@ jobs:
touch dockereve-master/nginx/.ssl/mriqcep.crt
touch dockereve-master/nginx/.ssl/mriqcep.key
docker pull mongo:latest
docker pull swaggerapi/swagger-ui:v3.0.12
docker pull swaggerapi/swagger-ui:latest
docker pull nginx:latest
docker-compose -f dockereve-master/docker-compose.yml build
- run:
Expand Down
2 changes: 1 addition & 1 deletion dockereve-master/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ nginx:
- swagger_ui:swagger_ui

swagger_ui:
image: swaggerapi/swagger-ui:v3.0.12
image: swaggerapi/swagger-ui:latest
env_file: .env

eve:
Expand Down
4 changes: 2 additions & 2 deletions dockereve-master/eve-app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM python:3.4-onbuild
FROM python:3.6-onbuild

WORKDIR /usr/src/app

ADD . /usr/src/app

RUN pip3 install -r requirements.txt
RUN pip3 install pytest
RUN sed -i 's/\[scheme\]/\["https"\]/' /usr/local/lib/python3.4/site-packages/eve_swagger/objects.py
RUN sed -i 's/\[scheme\]/\["https"\]/' /usr/local/lib/python3.6/site-packages/eve_swagger/objects.py

#EXPOSE 5000
#CMD ["python3", "server.py"]
Expand Down
17 changes: 10 additions & 7 deletions dockereve-master/eve-app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@

API_TOKEN = os.environ.get("API_TOKEN")


class TokenAuth(TokenAuth):
def check_auth(self, token, allowed_roles, resource, method):
return token == API_TOKEN


app = Eve(settings=settings, auth=TokenAuth)
app.register_blueprint(swagger, url_prefix='/docs/api')
app.add_url_rule('/docs/api', 'eve_swagger.index')
Expand All @@ -23,13 +25,14 @@ def check_auth(self, token, allowed_roles, resource, method):
app.config['SWAGGER_INFO'] = {
'title': 'MRIQC Web API',
'version': 'v1',
'description': """<a href="http://mriqc.org">MRIQC</a> is an open-source tool that extracts
no-reference image quality metrics from structural and
functional MRI data developed by the <a href="http://poldracklab.stanford.edu">
Poldrack Lab</a> at <a href="http://www.stanford.edu">Stanford University</a>.
This website provides an api to a crowdsourced repository of MRI quality
metrics contributed by users of MRIQC and hosted by
the <a href="http://cmn.nimh.nih.gov">Data Science and Sharing Team</a>
'description': """\
<a href="http://mriqc.org">MRIQC</a> is an open-source tool that extracts
no-reference image quality metrics from structural and
functional MRI data developed by the <a href="http://poldracklab.stanford.edu">
Poldrack Lab</a> at <a href="http://www.stanford.edu">Stanford University</a>.
This website provides an api to a crowdsourced repository of MRI quality
metrics contributed by users of MRIQC and hosted by
the <a href="http://cmn.nimh.nih.gov">Data Science and Sharing Team</a>
at the <a href="http://nimh.nih.gov">National Institute of Mental Health</a>.""",
}

Expand Down
6 changes: 3 additions & 3 deletions dockereve-master/eve-app/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
gunicorn==19.3.0
eve==0.7.4
eve-swagger==0.0.7
gunicorn
eve
eve-swagger
3 changes: 1 addition & 2 deletions dockereve-master/eve-app/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import re
from copy import deepcopy

bids_schema = {
Expand Down Expand Up @@ -553,7 +552,7 @@
'API_VERSION': 'v1',
'ALLOWED_FILTERS': ['*'],
'MONGO_HOST': os.environ.get('MONGODB_HOST', ''),
'MONGO_PORT': os.environ.get('MONGODB_PORT', ''),
'MONGO_PORT': int(os.environ.get('MONGODB_PORT', '')),
'MONGO_DBNAME': 'mriqc_api',
'PUBLIC_METHODS': ['GET'],
'PUBLIC_ITEM_METHODS': ['GET'],
Expand Down
63 changes: 32 additions & 31 deletions dockereve-master/eve-app/test_settings.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
from eve.tests import TestMinimal
import os
import re
from flask_pymongo import MongoClient

url = 'mriqc_api'
MONGO_HOST = os.environ.get("MONGODB_HOST", 'mongodb'),
MONGO_PORT = int(os.environ.get("MONGODB_PORT", 27017))
MONGO_DBNAME = 'test_DB'


class settingsTestCase(TestMinimal):
def setUp(self):
return super().setUp(settings_file = './settings.py')
def dropDB(self):
self.connection = MongoClient(MONGO_HOST,MONGO_PORT)
self.connection.drop_database(MONGO_DBNAME)
self.connection.close()
def setupDB(self):
self.connection = MongoClient(MONGO_HOST,MONGO_PORT)
self.connection.drop_database(MONGO_DBNAME)
def testGet(self):
return_json,return_code = self.get(url)
self.assert200(return_code)
def testPost(self):
return_json, return_code = self.post(url, {"cjv": 0.1231231})
self.assertFalse(self.domain)
self.assertFalse(return_json)
# self.assert200(return_code)

# class settingsTestCase(TestMinimal):
# def dropDB(self):
# self.connection = MongoClient(MONGO_HOST, MONGO_PORT)
# self.connection.drop_database(MONGO_DBNAME)
# self.connection.close()
def setUp(self):
return super().setUp(settings_file='./settings.py')

# def setupDB(self):
# self.connection = MongoClient(MONGO_HOST, MONGO_PORT)
# self.connection.drop_database(MONGO_DBNAME)
# def testPost():
# return_json, return_code = self.post(url,{"cjg":0.123123})
# print(return_json)
# print(return_code)
def dropDB(self):
self.connection = MongoClient(MONGO_HOST, MONGO_PORT)
self.connection.drop_database(MONGO_DBNAME)
self.connection.close()

def setupDB(self):
self.connection = MongoClient(MONGO_HOST, MONGO_PORT)
self.connection.drop_database(MONGO_DBNAME)

def testGet(self):
return_json, return_code = self.get(url)
self.assert200(return_code)

def testPost(self):
return_json, return_code = self.post(url, {"cjv": 0.1231231})
self.assertFalse(self.domain)
self.assertFalse(return_json)
# self.assert200(return_code)

# class settingsTestCase(TestMinimal):
# def dropDB(self):
# self.connection = MongoClient(MONGO_HOST, MONGO_PORT)
# self.connection.drop_database(MONGO_DBNAME)
# self.connection.close()

# def setupDB(self):
# self.connection = MongoClient(MONGO_HOST, MONGO_PORT)
# self.connection.drop_database(MONGO_DBNAME)
# def testPost():
# return_json, return_code = self.post(url,{"cjg":0.123123})
# print(return_json)
# print(return_code)
3 changes: 1 addition & 2 deletions test/T1w/missingField/sub-10159_T1w.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
"icvs_csf": 0.2430190456707652,
"PatientPosition": "HFS",
"SequenceName": "*tfl3d1_ns",
"summary_bg_p05": 0.0,
"ImageType": "ORIGINAL/PRIMARY/M/ND/NORM",
"summary_bg_p05": 0.0,
"qi_2": 0.0042996791690604694,
"qi_1": 5.289201412128623e-06,
"ImagingFrequency": 123249959,
Expand Down
11 changes: 1 addition & 10 deletions test/T1w/validData/sub-50785_T1w.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
{
"bids_meta": {
"modality": "T1w",
"subject_id": "50785",
"ImageType": [
"ORIGINAL",
"PRIMARY",
"M",
"MB",
"ND",
"NORM",
"MOSAIC"
]
"subject_id": "50785"
},
"cjv": 0.3881841572763748,
"cnr": 3.139893975583801,
Expand Down
26 changes: 5 additions & 21 deletions test/testGetPost.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def getRequest(post_resp, url):
return get_resp.json()


###### MAIN ######
# MAIN ######
header = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8'}
authenticated_header = header.copy()
authenticated_header['Authorization'] = os.environ.get('API_TOKEN', '<secret_token>')
Expand Down Expand Up @@ -62,8 +62,7 @@ def test_00_GETAllData(self):
input_count)
self.assertTrue(input_count == get_resp['_meta']['total'])


########## Testing Bold ############
# Testing Bold ############
def test_01_ConnectionStatus(self):
log = logging.getLogger("mriqcwebapi")

Expand All @@ -85,10 +84,7 @@ def test_01_ConnectionStatus(self):
log.debug('Response: %s', get_resp.json())
self.assertTrue(get_resp.raise_for_status() is None)


def test_02_MissingFieldInput(self):
log = logging.getLogger("mriqcwebapi")

for file_name in glob(boldMissingPattern):
with open(file_name) as fp:
input_data = json.load(fp)
Expand All @@ -99,8 +95,7 @@ def test_02_MissingFieldInput(self):
# print post_resp.status_code
self.assertTrue(post_resp.status_code == codeForInvalid)


########## Testing T1w ############
# Testing T1w ############
def test_03_ConnectionStatus(self):
log = logging.getLogger("mriqcwebapi")

Expand All @@ -122,10 +117,7 @@ def test_03_ConnectionStatus(self):
log.debug('Response: %s', get_resp.json())
self.assertTrue(get_resp.raise_for_status() is None)


def test_04_MissingFieldInput(self):
log = logging.getLogger("mriqcwebapi")

for file_name in glob(T1wMissingPattern):
with open(file_name) as fp:
input_data = json.load(fp)
Expand All @@ -136,11 +128,8 @@ def test_04_MissingFieldInput(self):
# print post_resp.status_code
self.assertTrue(post_resp.status_code == codeForInvalid)


########## Cross Testing: send data to wrong end point ############
# Cross Testing: send data to wrong end point ############
def test_05_boldDataToT1wEndPoint(self):
log = logging.getLogger("mriqcwebapi")

for file_name in glob(boldPattern):
with open(file_name) as fp:
input_data = json.load(fp)
Expand All @@ -150,10 +139,7 @@ def test_05_boldDataToT1wEndPoint(self):
headers=authenticated_header)
self.assertTrue(post_resp.status_code == codeForInvalid)


def test_06_T1wDataToBoldEndPoint(self):
log = logging.getLogger("mriqcwebapi")

for file_name in glob(T1wPattern):
with open(file_name) as fp:
input_data = json.load(fp)
Expand All @@ -163,7 +149,6 @@ def test_06_T1wDataToBoldEndPoint(self):
headers=authenticated_header)
self.assertTrue(post_resp.status_code == codeForInvalid)


def test_07_T1wDataValid(self):
for file_name in glob(T1wPattern):
with open(file_name) as fp:
Expand All @@ -182,7 +167,6 @@ def test_07_T1wDataValid(self):
# check key-value pair match
self.assertTrue(input_data[key] == queried_data[key])


def test_08_boldDataValid(self):
for file_name in glob(boldPattern):
with open(file_name) as fp:
Expand All @@ -203,7 +187,6 @@ def test_08_boldDataValid(self):
# check key-value pair match
self.assertTrue(input_data[key] == queried_data[key])


def test_09_failedAuth(self):
with open(glob(boldPattern)[0]) as fp:
inputData = json.load(fp)
Expand Down Expand Up @@ -234,6 +217,7 @@ def test_10_ratingDataValid(self):
if elem['_id'] == "bad":
self.assertTrue(elem['count'] == 1)


if __name__ == '__main__':
logging.basicConfig(stream=sys.stderr)
logging.getLogger("mriqcwebapi").setLevel(logging.DEBUG)
Expand Down

0 comments on commit cd79e94

Please sign in to comment.