Skip to content

Commit

Permalink
Merge 6756d7f into 638937b
Browse files Browse the repository at this point in the history
  • Loading branch information
golnazads committed Feb 22, 2021
2 parents 638937b + 6756d7f commit 703c1fb
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: python
python:
- "2.7"
- "3.8"
install:
- pip install --upgrade pip
- pip install -r requirements.txt
Expand Down
1 change: 1 addition & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
ADS_TWO_POINT_OH_MIRROR = 'adsabs.harvard.edu'

SQLALCHEMY_DATABASE_URI = ""
SQLALCHEMY_TRACK_MODIFICATIONS = True

HARBOUR_EXPORT_SERVICE_URL = 'http://fakeapi.adsabs.harvard.edu/v1/export'
HARBOUR_EXPORT_TYPES = ['zotero', 'mendeley']
Expand Down
25 changes: 15 additions & 10 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
pytest==2.8.2
coveralls==1.8.2
coverage==4.5.4
flask-testing==0.8.1
httmock==1.4.0
httpretty==0.8.10; python_version < '3.0'
httpretty==1.0.5; python_version > '3.0'
mock==1.3.0
moto==1.3.16
nose==1.3.7
pytest==2.8.2; python_version < '3.0'
pytest==5.1.0; python_version > '3.0'
pytest-cache==1.0
pytest-cov==2.2.0
pytest-cov==2.2.0; python_version < '3.0'
pytest-cov==2.7.1; python_version > '3.0'
pytest-pep8==1.0.6
moto==0.4.22
mock==2.0.0
nose==1.3.7
coveralls==1.2.0
requests==2.9.1
httmock==1.2.3
testing.postgresql==1.2.1
Flask-Testing==0.8.0
requests==2.25.1
testing.postgresql==1.3.0
10 changes: 6 additions & 4 deletions harbour/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
Application factory
"""

from future import standard_library
standard_library.install_aliases()
import json
import boto3
import logging.config

from flask import Flask
from flask.ext.watchman import Watchman
from flask_watchman import Watchman
from flask_restful import Api
from flask_discoverer import Discoverer
from views import AuthenticateUserClassic, AuthenticateUserTwoPointOh, \
from harbour.views import AuthenticateUserClassic, AuthenticateUserTwoPointOh, \
AllowedMirrors, ClassicLibraries, ClassicUser, TwoPointOhLibraries, \
ExportTwoPointOhLibraries, ClassicMyADS

from StringIO import StringIO
from io import BytesIO
from adsmutils import ADSFlask


Expand Down Expand Up @@ -85,7 +87,7 @@ def load_s3(app):
)
body = bucket.get()['Body']

user_data = StringIO()
user_data = BytesIO()
for chunk in iter(lambda: body.read(1024), b''):
user_data.write(chunk)

Expand Down
3 changes: 2 additions & 1 deletion harbour/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from builtins import object
import requests
from flask import current_app, request

Expand All @@ -6,7 +7,7 @@
client = lambda: Client(current_app.config)


class Client:
class Client(object):
"""
The Client class is a thin wrapper around requests; Use it as a centralized
place to set application specific parameters, such as the oauth2
Expand Down
6 changes: 3 additions & 3 deletions harbour/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
os.path.join(os.path.dirname(__file__), '..'))
sys.path.append(PROJECT_HOME)

from flask.ext.script import Manager, Command
from flask.ext.migrate import Migrate, MigrateCommand
from models import Base
from flask_script import Manager, Command
from flask_migrate import Migrate, MigrateCommand
from harbour.models import Base
from harbour.app import create_app

# Load the app with the factory
Expand Down
2 changes: 1 addition & 1 deletion harbour/tests/unit_tests/stub_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

from httmock import urlmatch
from stub_data import stub_classic_success, stub_classic_unknown_user, \
from harbour.tests.unit_tests.stub_data import stub_classic_success, stub_classic_unknown_user, \
stub_classic_wrong_password, stub_classic_no_cookie, \
stub_classic_libraries_success, stub_export_success, \
stub_export_success_no_keyword, stub_classic_myads_success
Expand Down
2 changes: 1 addition & 1 deletion harbour/tests/unit_tests/test_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Tests the methods within the flask-script file manage.py
"""

from base import TestBaseDatabase
from harbour.tests.unit_tests.base import TestBaseDatabase
from harbour.manage import CreateDatabase
from harbour.models import Base, Users
from sqlalchemy import create_engine
Expand Down
15 changes: 8 additions & 7 deletions harbour/tests/unit_tests/test_webservices.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@
import unittest

from moto import mock_s3
from base import TestBaseDatabase
from flask import url_for

from harbour.models import Users
from harbour.http_errors import CLASSIC_AUTH_FAILED, CLASSIC_DATA_MALFORMED, \
CLASSIC_TIMEOUT, CLASSIC_BAD_MIRROR, CLASSIC_NO_COOKIE, \
CLASSIC_UNKNOWN_ERROR, NO_CLASSIC_ACCOUNT, NO_TWOPOINTOH_LIBRARIES, \
NO_TWOPOINTOH_ACCOUNT, TWOPOINTOH_AWS_PROBLEM, EXPORT_SERVICE_FAIL, \
TWOPOINTOH_WRONG_EXPORT_TYPE
from stub_response import ads_classic_200, ads_classic_unknown_user, \
from harbour.tests.unit_tests.base import TestBaseDatabase
from harbour.tests.unit_tests.stub_response import ads_classic_200, ads_classic_unknown_user, \
ads_classic_wrong_password, ads_classic_no_cookie, ads_classic_fail, \
ads_classic_libraries_200, export_success, export_success_no_keyword, \
ads_classic_myads_200
from httmock import HTTMock
from zipfile import ZipFile
from StringIO import StringIO
from io import BytesIO
from requests.exceptions import Timeout


Expand Down Expand Up @@ -133,7 +134,7 @@ def test_user_authentication_success(self):
user.classic_mirror,
self.stub_user_data['classic_mirror']
)
self.assertIsInstance(user.classic_cookie, unicode)
self.assertIsInstance(user.classic_cookie, str)

def test_user_authentication_success_if_user_already_exists(self):
"""
Expand Down Expand Up @@ -180,7 +181,7 @@ def test_user_authentication_success_if_user_already_exists(self):
r_user.classic_mirror,
self.stub_user_data['classic_mirror']
)
self.assertIsInstance(r_user.classic_cookie, unicode)
self.assertIsInstance(r_user.classic_cookie, str)

def test_user_authentication_fails_when_user_already_exists(self):
"""
Expand Down Expand Up @@ -849,7 +850,7 @@ def test_get_zotero_export_successfully(self):
'attachment; filename=user_zotero.zip'
)

zip_file = ZipFile(StringIO(r.get_data()))
zip_file = ZipFile(BytesIO(r.get_data()))
zip_content = {name: zip_file.read(name) for name in zip_file.namelist()}
self.assertEqual(
zip_content.keys(),
Expand Down Expand Up @@ -898,7 +899,7 @@ def test_get_zotero_export_successfully_when_no_keyword(self):
'attachment; filename=user_zotero.zip'
)

zip_file = ZipFile(StringIO(r.get_data()))
zip_file = ZipFile(BytesIO(r.get_data()))
zip_content = {name: zip_file.read(name) for name in zip_file.namelist()}
self.assertEqual(
zip_content.keys(),
Expand Down
2 changes: 1 addition & 1 deletion harbour/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def get_post_data(request, types={}):

if types and isinstance(post_data, dict):
for expected_key in types:
if expected_key not in post_data.keys():
if expected_key not in list(post_data.keys()):
continue

if not isinstance(post_data[expected_key],
Expand Down
17 changes: 9 additions & 8 deletions harbour/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@
"""
Views
"""
from future import standard_library
standard_library.install_aliases()
import re
import json
import boto3
import requests
import traceback

from utils import get_post_data, err
from flask import current_app, request, send_file
from flask_restful import Resource
from flask_discoverer import advertise
from client import client
from models import Users
from zipfile import ZipFile
from StringIO import StringIO
from http_errors import CLASSIC_AUTH_FAILED, CLASSIC_DATA_MALFORMED, \
from io import BytesIO
from sqlalchemy.orm.exc import NoResultFound

from harbour.utils import get_post_data, err
from harbour.models import Users
from harbour.http_errors import CLASSIC_AUTH_FAILED, CLASSIC_DATA_MALFORMED, \
CLASSIC_TIMEOUT, CLASSIC_BAD_MIRROR, CLASSIC_NO_COOKIE, \
CLASSIC_UNKNOWN_ERROR, NO_CLASSIC_ACCOUNT, NO_TWOPOINTOH_ACCOUNT, \
NO_TWOPOINTOH_LIBRARIES, TWOPOINTOH_AWS_PROBLEM, EXPORT_SERVICE_FAIL, \
TWOPOINTOH_WRONG_EXPORT_TYPE
from sqlalchemy.orm.exc import NoResultFound

USER_ID_KEYWORD = 'X-Adsws-Uid'

Expand Down Expand Up @@ -154,7 +155,7 @@ def get_s3_library(library_file_name):
library_file_name
)
body = bucket.get()['Body']
library_data = StringIO()
library_data = BytesIO()
for chunk in iter(lambda: body.read(1024), b''):
library_data.write(chunk)

Expand Down
17 changes: 9 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
git+https://github.com/adsabs/ADSMicroserviceUtils.git@v1.1.9
flask-consulate==0.1.2
Flask-Script==2.0.5
Flask-Migrate==1.6.0
psycopg2==2.8.3
git+https://github.com/jonnybazookatone/flask-watchman@7d002bbba5babc5545f682045a2574b68908d0ce
boto3==1.1.1
boto==2.39.0
botocore==1.1.12
git+https://github.com/adsabs/flask-watchman.git@v1.0.0
boto==2.49.0
boto3==1.17.10
botocore==1.20.10
flask-consulate==0.2.0
flask-migrate==2.6.0
flask-script==2.0.6
future==0.18.2
psycopg2==2.8.3

0 comments on commit 703c1fb

Please sign in to comment.