Skip to content

Commit

Permalink
Merge pull request #95 from ehenneken/Python3
Browse files Browse the repository at this point in the history
Python3
  • Loading branch information
marblestation committed Jan 19, 2021
2 parents a1948f6 + 7b9ebbc commit 8216bb5
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*.py[co]

*.bak
# Packages
*.egg
*.egg-info
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: python

python:
- "2.7"
- "3.8"

install:
- "pip install --upgrade setuptools pip"
Expand Down
15 changes: 9 additions & 6 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
pytest==2.8.2
coveralls==1.1.0
httpretty==0.8.10
mock==1.3.0
coverage==4.3.4
pytest-cov==2.2.0
coveralls==1.8.2
coverage==4.5.4
Flask-Testing==0.8.0
httpretty==0.8.10; python_version < '3.0'
httpretty==1.0.5; python_version > '3.0'
mock==1.3.0
pytest==2.8.2; python_version < '3.0'
pytest==5.1.0; python_version > '3.0'
pytest-cov==2.2.0; python_version < '3.0'
pytest-cov==2.7.1; python_version > '3.0'
3 changes: 2 additions & 1 deletion graphics_service/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import absolute_import
from flask import Flask
from werkzeug.serving import run_simple
from views import Graphics
from .views import Graphics
from flask_restful import Api
from flask_discoverer import Discoverer
from adsmutils import ADSFlask
Expand Down
6 changes: 3 additions & 3 deletions graphics_service/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
@author: ehenneken
'''
from __future__ import absolute_import
import sys
import os
import simplejson as json
import random
from flask import current_app
#from models import AlchemyEncoder, GraphicsModel
from models import get_graphics_record
from .models import get_graphics_record
#from sqlalchemy.orm.exc import NoResultFound

thumb_link = '<a href="%s" target="_new" border=0>' + \
Expand All @@ -36,8 +37,7 @@ def get_graphics(bibcode):
source = results.get('source', 'NA')
results['ADSlink'] = []
if not eprint:
results['figures'] = filter(
lambda a: a['figure_label'] != None, results['figures'])
results['figures'] = [a for a in results['figures'] if a['figure_label'] != None]
display_figure = random.choice(results['figures'])
results['pick'] = ''
results['number'] = 0
Expand Down
2 changes: 1 addition & 1 deletion graphics_service/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ def get_graphics_record(bibcode):
res = execute_SQL_query(bibcode)
except NoResultFound:
res = {'Error': 'Unable to get results!', 'Error Info': 'No database entry found for %s' % bibcode}
except Exception, err:
except Exception as err:
res = {'Error': 'Unable to get results!', 'Error Info': 'Graphics query failed for %s: %s'%(bibcode, err)}
return res
8 changes: 5 additions & 3 deletions graphics_service/tests/test_endpoint.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import print_function
from builtins import map
import sys
import os
from flask_testing import TestCase
Expand Down Expand Up @@ -54,9 +56,9 @@ def test_data_model(self):
bc = Column(Boolean)
jc = Column(postgresql.JSON)
dc = Column(DateTime)
cols_expect = map(
cols_expect = list(map(
type, [ic.type, sc.type, sc.type, sc.type, bc.type,
jc.type, dc.type])
jc.type, dc.type]))
self.assertEqual([type(c.type)
for c in GraphicsModel.__table__.columns],
cols_expect)
Expand Down Expand Up @@ -112,7 +114,7 @@ def test_query_no_record(self, mock_execute_SQL_query):
r = self.client.get(url)
self.assertTrue(r.status_code == 200)
expected = {u'Error Info': u'No database entry found for foo', u'Error': u'Unable to get results!'}
print r.json
print(r.json)
self.assertTrue(r.json == expected)

@mock.patch('graphics_service.models.execute_SQL_query', return_value={'Error': 'error', 'Error Info': 'info'})
Expand Down
3 changes: 2 additions & 1 deletion graphics_service/tests/test_webservices.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from past.builtins import basestring
import sys
import os
from flask_testing import TestCase
Expand Down Expand Up @@ -38,7 +39,7 @@ def test_ResourcesRoute(self):

for expected_field, _type in {'scopes': list, 'methods': list,
'description': basestring,
'rate_limit': list}.iteritems():
'rate_limit': list}.items():
# Assert each resource is described has the expected_field
[self.assertIn(expected_field, v) for v in r.json.values()]
# Assert every expected_field has the proper type
Expand Down
3 changes: 2 additions & 1 deletion graphics_service/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import absolute_import
from flask import current_app
from flask_restful import Resource
from flask_discoverer import advertise
from graphics import get_graphics
from .graphics import get_graphics
import time

class Graphics(Resource):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
git+https://github.com/adsabs/ADSMicroserviceUtils.git@v1.1.9
alembic==0.8.9
future==0.18.2
psycopg2==2.8.3
simplejson==3.10.0

0 comments on commit 8216bb5

Please sign in to comment.