-
Notifications
You must be signed in to change notification settings - Fork 8
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 #61 from cul-it/develop
Pre-release merge for v0.8.1
- Loading branch information
Showing
25 changed files
with
374 additions
and
235 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 |
---|---|---|
|
@@ -3,4 +3,4 @@ omit = | |
app.py | ||
setup.py | ||
docs/* | ||
test* | ||
*test* |
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
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -4,32 +4,43 @@ | |
|
||
SERVER_NAME = None | ||
|
||
ARXIV_TWITTER_URL = os.environ.get('ARXIV_TWITTER_URL', | ||
'https://twitter.com/arxiv') | ||
ARXIV_SEARCH_BOX_URL = os.environ.get('SEARCH_BOX_URL', '/search') | ||
ARXIV_SEARCH_ADVANCED_URL = os.environ.get('ARXIV_SEARCH_ADVANCED_URL', | ||
'/search/advanced') | ||
ARXIV_ACCOUNT_URL = os.environ.get('ACCOUNT_URL', '/user') | ||
ARXIV_LOGIN_URL = os.environ.get('LOGIN_URL', '/user/login') | ||
ARXIV_LOGOUT_URL = os.environ.get('LOGOUT_URL', '/user/logout') | ||
ARXIV_HOME_URL = os.environ.get('ARXIV_HOME_URL', 'https://arxiv.org') | ||
ARXIV_HELP_URL = os.environ.get('ARXIV_HELP_URL', '/help') | ||
ARXIV_CONTACT_URL = os.environ.get('ARXIV_CONTACT_URL', '/help/contact') | ||
ARXIV_BLOG_URL = os.environ.get('ARXIV_BLOG_URL', | ||
"https://blogs.cornell.edu/arxiv/") | ||
ARXIV_WIKI_URL = os.environ.get( | ||
'ARXIV_WIKI_URL', | ||
"https://confluence.cornell.edu/display/arxivpub/arXiv+Public+Wiki" | ||
) | ||
ARXIV_ACCESSIBILITY_URL = os.environ.get( | ||
'ARXIV_ACCESSIBILITY_URL', | ||
"mailto:[email protected]" | ||
) | ||
ARXIV_LIBRARY_URL = os.environ.get('ARXIV_LIBRARY_URL', | ||
'https://library.cornell.edu') | ||
ARXIV_ACKNOWLEDGEMENT_URL = os.environ.get( | ||
'ARXIV_ACKNOWLEDGEMENT_URL', | ||
"https://confluence.cornell.edu/x/ALlRF" | ||
) | ||
EXTERNAL_URLS = [ | ||
("twitter", os.environ.get("ARXIV_TWITTER_URL", | ||
"https://twitter.com/arxiv")), | ||
("blog", os.environ.get("ARXIV_BLOG_URL", | ||
"https://blogs.cornell.edu/arxiv/")), | ||
("wiki", os.environ.get("ARXIV_WIKI_URL", | ||
"https://confluence.cornell.edu/display/arxivpub/" | ||
"arXiv+Public+Wiki")), | ||
("accessibility", os.environ.get("ARXIV_ACCESSIBILITY_URL", | ||
"mailto:[email protected]")), | ||
("library", os.environ.get("ARXIV_LIBRARY_URL", | ||
"https://library.cornell.edu")), | ||
("acknowledgment", os.environ.get( | ||
"ARXIV_ACKNOWLEDGEMENT_URL", | ||
"https://confluence.cornell.edu/x/ALlRF" | ||
)), | ||
] | ||
"""External URLs, configurable via environment variables.""" | ||
|
||
ARXIV_BUSINESS_TZ = os.environ.get('ARXIV_BUSINESS_TZ', 'US/Eastern') | ||
ARXIV_URLS = [ | ||
("help", "/help"), | ||
("contact", "/help/contact"), | ||
("search_box", "/search"), | ||
("search_advanced", "/search/advanced"), | ||
("account", "/user"), | ||
("login", "/user/login"), | ||
("logout", "/user/logout"), | ||
("home", "/"), | ||
("pdf", "/pdf/<arxiv:paper_id>"), | ||
] | ||
""" | ||
URLs for other services, for use with :func:`flask.url_for`. | ||
This only works for services at the same hostname, since Flask uses the | ||
hostname on the request to generate the full URL. For addresses at a different | ||
hostname, use :func:`arxiv.base.urls.config_url`, which relies on | ||
``EXTERNAL_URLS`` in this configuration file. | ||
""" | ||
|
||
ARXIV_BUSINESS_TZ = os.environ.get("ARXIV_BUSINESS_TZ", "US/Eastern") |
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,23 +1,9 @@ | ||
"""Context processors for the base application.""" | ||
|
||
from typing import Dict, Callable | ||
from flask import current_app | ||
from arxiv.base import config | ||
from arxiv.base.exceptions import ConfigurationError | ||
from arxiv.base.urls import config_url | ||
|
||
|
||
def config_url_builder() -> Dict[str, Callable]: | ||
"""Inject a configurable URL factory.""" | ||
def config_url(target: str) -> str: | ||
"""Generate a URL from this app's configuration.""" | ||
target = target.upper() | ||
# Look for the URL on the config of the current app (this will *not* be | ||
# base); fall back to the base config if not found. | ||
try: | ||
url: str = current_app.config.get(f'ARXIV_{target}_URL') | ||
if url is None: | ||
url = getattr(config, f'ARXIV_{target}_URL') | ||
except AttributeError as e: | ||
raise ConfigurationError(f'URL for {target} not set') from e | ||
return url | ||
"""Inject :func:`.config_url` into the template rendering context.""" | ||
return dict(config_url=config_url) |
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,91 @@ | ||
"""Tests for :mod:`arxiv.base.urls`.""" | ||
|
||
from unittest import TestCase, mock | ||
from flask import Flask | ||
from arxiv.base.urls import config_url | ||
from arxiv.base.exceptions import ConfigurationError | ||
|
||
|
||
class TestConfigURL(TestCase): | ||
"""Tests for :func:`arxiv.base.urls.config_url`.""" | ||
|
||
def test_config_url_key_exists(self): | ||
"""config_url() is called for an URL that is configured on the app.""" | ||
app = Flask('foo') | ||
app.config['EXTERNAL_URLS'] = { | ||
'foo': 'https://foo.arxiv.org' | ||
} | ||
with app.app_context(): | ||
url = config_url('foo') | ||
|
||
self.assertEqual(url, 'https://foo.arxiv.org', | ||
"Should return configured URL") | ||
|
||
@mock.patch('base.urls.config') | ||
def test_config_url_key_not_on_current_app(self, mock_base_config): | ||
"""config_url() is called for an URL that is not on the current app.""" | ||
mock_base_config.EXTERNAL_URLS = {} | ||
mock_base_config.EXTERNAL_URLS['foo'] = 'https://bar.arxiv.org' | ||
app = Flask('foo') | ||
with app.app_context(): | ||
url = config_url('foo') | ||
|
||
self.assertEqual(url, 'https://bar.arxiv.org', | ||
"Should return URL configured in arxiv base") | ||
|
||
@mock.patch('base.urls.config') | ||
def test_config_url_key_not_set_anywhere(self, mock_base_config): | ||
"""config_url() is called for an URL that is not configured.""" | ||
app = Flask('foo') | ||
mock_base_config.EXTERNAL_URLS = {} | ||
with app.app_context(): | ||
with self.assertRaises(ConfigurationError): | ||
config_url('foo') | ||
|
||
@mock.patch('base.urls.config') | ||
def test_config_url_with_format_parameter(self, mock_base_config): | ||
"""URL requires a parameter, which is provided.""" | ||
mock_base_config.EXTERNAL_URLS = { | ||
'foo': 'https://bar.arxiv.org/{foo}' | ||
} | ||
app = Flask('foo') | ||
with app.app_context(): | ||
url = config_url('foo', {'foo': 'bar'}) | ||
|
||
self.assertEqual(url, 'https://bar.arxiv.org/bar', | ||
"Should return URL configured in arxiv base") | ||
|
||
@mock.patch('base.urls.config') | ||
def test_config_url_with_parameter_not_provided(self, mock_base_config): | ||
"""URL requires a parameter, which is not provided.""" | ||
mock_base_config.EXTERNAL_URLS = { | ||
'foo': 'https://bar.arxiv.org/{foo}' | ||
} | ||
app = Flask('foo') | ||
with app.app_context(): | ||
with self.assertRaises(ValueError): | ||
config_url('foo') | ||
|
||
def test_config_url_with_get_param(self): | ||
"""Request parameters are included.""" | ||
app = Flask('foo') | ||
app.config['EXTERNAL_URLS'] = { | ||
'foo': 'https://foo.arxiv.org' | ||
} | ||
with app.app_context(): | ||
url = config_url('foo', params={'baz': 'bat'}) | ||
|
||
self.assertEqual(url, 'https://foo.arxiv.org?baz=bat', | ||
"Should return configured URL") | ||
|
||
def test_config_url_with_extra_get_param(self): | ||
"""Request parameters are included in addition to those present.""" | ||
app = Flask('foo') | ||
app.config['EXTERNAL_URLS'] = { | ||
'foo': 'https://foo.arxiv.org?yes=no' | ||
} | ||
with app.app_context(): | ||
url = config_url('foo', params={'baz': 'bat'}) | ||
|
||
self.assertEqual(url, 'https://foo.arxiv.org?baz=bat&yes=no', | ||
"Should return configured URL") |
Oops, something went wrong.