forked from inspirehep/inspire-classifier
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request inspirehep#9 from vbalbp/use_flask_restful
Use flask restful
- Loading branch information
Showing
10 changed files
with
163 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,26 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of INSPIRE. | ||
# Copyright (C) 2014-2018 CERN. | ||
# | ||
# INSPIRE is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# INSPIRE is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with INSPIRE. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
# In applying this license, CERN does not waive the privileges and immunities | ||
# granted to it by virtue of its status as an Intergovernmental Organization | ||
# or submit itself to any jurisdiction. | ||
|
||
sudo: required | ||
|
||
language: python | ||
|
||
dist: trusty | ||
services: | ||
- docker | ||
|
||
python: | ||
- 3.6 | ||
|
||
env: | ||
global: | ||
- DOCKER_DATA=/tmp/data | ||
|
||
before_install: | ||
- travis_retry pip install --upgrade pip setuptools | ||
- travis_retry pip install coveralls | ||
|
||
- travis_retry pip install --upgrade pip setuptools | ||
- travis_retry pip install coveralls | ||
install: | ||
- travis_retry pip install -e .[tests] | ||
|
||
script: | ||
- chmod +x *.sh | ||
- ./run-tests.sh | ||
|
||
- "./run-tests.sh" | ||
deploy: | ||
provider: pypi | ||
user: # | ||
user: inspirehep | ||
password: | ||
secure: | ||
secure: QSPeMz4iQOMwqvLUwWpeJsvsTx7OdhdGVnvDClaMzb9nB2rYcXVY9j9rr/0jg+ocYPcv4yxIa7yxHPf/w0Gv2J3l6A1KWsuk94ZfMnAHvDspytTb4KSt/pqZ/QUoLjUn8SvmnJR3ifZeBi55PFwTpoS/iMI1VuRRi9kFNkNodavct/f8MPMVDvpoqHp8IfA/WSIZ8w0HXLYAia1HI9qVnZzs9OeMfpWVkfPbh2F1VJpDzkFnP9989+21FlpoluKiRAGZzC3kfqNCtPTujXqvsroToe/LR4XEnk27YDdZ4KEXKE8g23/wtou//PZV1Ohd5nz4cPaada7y76mHHhdr76O7OMlaFzY6UZdZe0dqpyfRk5HISQm3/BgjlMSdus8dSc8iakQduX8gHuf1vSDga2aJKespL6lPd46YWAH/y+lZKZ18DEdIEJIBxLcWS8Q1sEE6lUrVnP6ykI5R1FCZoJ7tNKNwaxCcGEqYf1WtYbpcFt5uEij13DErFVDWomauvfXcWN7qPOqLxNfA9IBcPHdm9k+GDVq6AcujcYbMQzi8n40/K5n7D7Ij2xZqp6F1obGE/3GM0t61f6fdeo2dCmcgUjhaiMsftixmi2xLqmUFezvDUBQ92Lq19MiQmFAkX21iH3jaGd/vwFKENGMfw5eD9WDBaMRtCDGA8dTHEKo= | ||
on: | ||
branch: master | ||
|
||
after_deploy: | ||
- ./deploy_to_openshift.sh | ||
- "./deploy_to_openshift.sh" | ||
env: | ||
global: | ||
#DEPLOY_TOKEN | ||
- secure: iE2eL+kq5mddntryu73RI1eLSH4yjGSMzm4BmDPasZHJWlzcTn25wUPQpTD+xF5n52DuKzbuEqTYmJVbiHt2gLPkFfRKRg7ZJcjNfzV47sduerwehRqXW7LJHBHtW4Zwsy2i5k4Ha5wDLLHzr3HL7hwu3Mu2TF2VKm2bGx1IIk63RN0HrawHKkoi/biKA88DCsMCXz4LlblvWEARgAorzxF7at+om4BrQaCdrOz3f036dUuC+z0ITDH2hM8HFlNkb+vvyEvYyWExqqpBC7YXe1X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GKgzFEFDwWoeavU/pDywTNbvf/rt+1kqDJ2c= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/bin/bash -xe | ||
curl -X POST "${DEPLOY_URL}" \ | ||
-F token=${DEPLOY_TOKEN} \ | ||
-F ref=qa \ | ||
-F ref=master \ | ||
-F "variables[CACHE_DATE]=$(date +%Y-%m-%d:%H:%M:%S)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of INSPIRE. | ||
# Copyright (C) 2014-2017 CERN. | ||
# | ||
# INSPIRE is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# INSPIRE is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with INSPIRE. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
# In applying this license, CERN does not waive the privileges and immunities | ||
# granted to it by virtue of its status as an Intergovernmental Organization | ||
# or submit itself to any jurisdiction. | ||
|
||
from __future__ import absolute_import, division, print_function | ||
|
||
import pytest | ||
from inspire_classifier.app import create_app | ||
|
||
|
||
@pytest.fixture(autouse=True, scope='session') | ||
def app(): | ||
app = create_app() | ||
with app.app_context(): | ||
yield app | ||
|
||
|
||
# TODO: all fixtures using ``app`` must be replaced by ones that use ``isolated_app``. | ||
@pytest.fixture() | ||
def app_client(app): | ||
"""Flask test client for the application. | ||
See: http://flask.pocoo.org/docs/0.12/testing/#keeping-the-context-around. | ||
""" | ||
with app.test_client() as client: | ||
yield client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of INSPIRE. | ||
# Copyright (C) 2014-2018 CERN. | ||
# | ||
# INSPIRE is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# INSPIRE is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with INSPIRE. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
# In applying this license, CERN does not waive the privileges and immunities | ||
# granted to it by virtue of its status as an Intergovernmental Organization | ||
# or submit itself to any jurisdiction. | ||
|
||
from __future__ import absolute_import, division, print_function | ||
|
||
import json | ||
|
||
|
||
def test_health_check(app_client): | ||
assert app_client.get('/api/health').status_code == 200 | ||
|
||
|
||
def test_classifier_accepts_only_post(app_client): | ||
assert app_client.post('/api/classifier', data=dict(title='foo bar', abstract='foobar foobar')).status_code == 200 | ||
assert app_client.get('/api/classifier').status_code == 405 | ||
|
||
|
||
def test_classifier(app_client): | ||
response = app_client.post('/api/classifier', data=dict(title='foo bar', abstract='foobar foobar')) | ||
|
||
result = json.loads(response.data) | ||
|
||
expected = { | ||
"prediction": "core", | ||
"score1": 0.1, | ||
"score2": 0.2, | ||
"score3": 0.7, | ||
} | ||
|
||
assert response.status_code == 200 | ||
assert expected == result | ||
|
||
|
||
def test_classifier_serializes_input(app_client): | ||
assert app_client.post('/api/classifier', data=dict(title='foo bar')).status_code == 422 | ||
assert app_client.post('/api/classifier', data=dict(abstract='foo bar')).status_code == 422 | ||
|
||
|
||
def test_classifier_accepts_extra_fields(app_client): | ||
assert app_client.post('/api/classifier', data=dict(title='foo bar', abstract='foo bar', author='foo')).status_code == 200 |
Oops, something went wrong.