Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_home(self):
"""Test the home page."""
rv = self.app.get('/')
self.assertEqual(rv.status_code, 200)
html = BeautifulSoup(rv.data.decode('utf-8'), 'html.parser')
for group_key, group_value in taxonomy.definitions.GROUPS.items():
if group_key == 'grp_test':
continue
auths_elmt = html.find('h2', text=group_value['name'])
self.assertTrue(auths_elmt, f"{group_value['name']} in h2 element")
self.assertFalse(html.find('h2', text='Test'),
"'Test' group should not be shown on homepage")
def get_home_page() -> Response:
"""Get the data needed to generated the home page."""
response_data: Dict[str, Any] = {}
response_headers: Dict[str, Any] = {}
try:
response_data['document_count'] = _get_document_count()
except Exception as ex:
logger.warning(f'Could not get abs page data: {ex}')
raise InternalServerError from ex
response_data['groups'] = taxonomy.definitions.GROUPS
response_data['archives'] = taxonomy.definitions.ARCHIVES_ACTIVE
response_data['categories'] = taxonomy.definitions.CATEGORIES_ACTIVE
return response_data, status.HTTP_200_OK, response_headers
add_sciencewise_ping = _check_sciencewise_ping(abs_meta.arxiv_id_v)
response_data['formats'] = metadata.get_dissemination_formats(
abs_meta,
download_format_pref,
add_sciencewise_ping)
# Following are less critical and template must display without them
# try:
_non_critical_abs_data(abs_meta, arxiv_identifier, response_data)
# except Exception:
# logger.warning("Error getting non-critical abs page data",
# exc_info=app.debug)
except AbsNotFoundException:
if arxiv_identifier.is_old_id and arxiv_identifier.archive \
in taxonomy.definitions.ARCHIVES:
archive_name = taxonomy.definitions.ARCHIVES[arxiv_identifier.archive]['name']
raise AbsNotFound(data={'reason': 'old_id_not_found',
'arxiv_id': arxiv_id,
'archive_id': arxiv_identifier.archive,
'archive_name': archive_name})
raise AbsNotFound(data={'reason': 'not_found', 'arxiv_id': arxiv_id})
except AbsVersionNotFoundException:
raise AbsNotFound(data={'reason': 'version_not_found',
'arxiv_id': arxiv_identifier.idv,
'arxiv_id_latest': arxiv_identifier.id})
except AbsDeletedException as e:
raise AbsNotFound(data={'reason': 'deleted',
'arxiv_id_latest': arxiv_identifier.id,
'message': e})
except IdentifierIsArchiveException as e:
raise AbsNotFound(data={'reason': 'is_archive',
def __init__(self, arxiv_id: str) -> None:
"""Attempt to validate the provided arXiv ID.
Parse constituent parts.
"""
self.ids = arxiv_id
"""The ID as specified."""
self.id: str = arxiv_id
self.archive: Optional[str] = None
self.filename: Optional[str] = None
self.year: Optional[int] = None
self.month: Optional[int] = None
self.is_old_id: Optional[bool] = None
if self.ids in taxonomy.definitions.ARCHIVES:
raise IdentifierIsArchiveException(
taxonomy.definitions.ARCHIVES[self.ids]['name'])
for subtup in SUBSTITUTIONS:
arxiv_id = re.sub(subtup[0],
subtup[1],
arxiv_id,
count=subtup[2],
flags=subtup[3])
self.version = 0
parse_actions = ((RE_ARXIV_OLD_ID, self._parse_old_id),
(RE_ARXIV_NEW_ID, self._parse_new_id))
id_match = None
for regex, parse_action in parse_actions:
def category_taxonomy() -> Any:
"""Display the arXiv category taxonomy."""
response = {
'groups': taxonomy.definitions.GROUPS,
'archives': taxonomy.definitions.ARCHIVES_ACTIVE,
'categories': taxonomy.definitions.CATEGORIES_ACTIVE
}
return render_template('category_taxonomy.html', **response), \
status.HTTP_200_OK, None
def get_home_page() -> Response:
"""Get the data needed to generated the home page."""
response_data: Dict[str, Any] = {}
response_headers: Dict[str, Any] = {}
try:
response_data['document_count'] = _get_document_count()
except Exception as ex:
logger.warning(f'Could not get abs page data: {ex}')
raise InternalServerError from ex
response_data['groups'] = taxonomy.definitions.GROUPS
response_data['archives'] = taxonomy.definitions.ARCHIVES_ACTIVE
response_data['categories'] = taxonomy.definitions.CATEGORIES_ACTIVE
return response_data, status.HTTP_200_OK, response_headers
-------
Dict of values to add to response_data
"""
# Set up the context
context = None
if ('context' in request.args and (
request.args['context'] == 'arxiv'
or request.args['context'] in taxonomy.definitions.CATEGORIES
or request.args['context'] in taxonomy.definitions.ARCHIVES)):
context = request.args['context']
elif primary_category:
pc = primary_category.canonical or primary_category
if not arxiv_identifier.is_old_id: # new style IDs
context = pc.id
else: # Old style id
if pc.id in taxonomy.definitions.ARCHIVES:
context = pc.id
else:
context = arxiv_identifier.archive
else:
context = None
response_data['browse_context'] = context
next_url = None
prev_url = None
if arxiv_identifier.is_old_id or context == 'arxiv':
# Revert to hybrid approach per ARXIVNG-2080
next_id = metadata.get_next_id(arxiv_identifier)
if next_id:
next_url = url_for('browse.abstract',
arxiv_id=next_id.id,