Updated tests for online help

This commit is contained in:
Nimisha Asthagiri
2014-05-16 16:05:49 -04:00
parent 27ff0db57b
commit 73275eeb82
10 changed files with 62 additions and 46 deletions

View File

@@ -12,7 +12,7 @@ config = ConfigParser.ConfigParser()
config.readfp(config_file)
def doc_url(request=None):
def doc_url(request=None): # pylint: disable=unused-argument
"""
This function is added in the list of TEMPLATE_CONTEXT_PROCESSORS, which is a django setting for
a tuple of callables that take a request object as their argument and return a dictionary of items
@@ -25,7 +25,7 @@ def doc_url(request=None):
May be used in the future for determining the language of choice.
"""
def get_online_help_info(page_token):
def get_online_help_info(page_token=None):
"""
Args:
page_token: A string that identifies the page for which the help information is requested.
@@ -38,7 +38,14 @@ def doc_url(request=None):
* "pdf_url" - a string with the url corresponding to the location of the PDF help file.
"""
def get_config_value(section_name, option, default_option="default"):
def get_config_value_with_default(section_name, option, default_option="default"):
"""
Args:
section_name: name of the section in the configuration from which the option should be found
option: name of the configuration option
default_option: name of the default configuration option whose value should be returned if the
requested option is not found
"""
try:
return config.get(section_name, option)
except (ConfigParser.NoOptionError, AttributeError):
@@ -46,23 +53,28 @@ def doc_url(request=None):
return config.get(section_name, default_option)
def get_doc_url():
"""
Returns:
The URL for the documentation
"""
return "{url_base}/{language}/{version}/{page_path}".format(
url_base=config.get("help_settings", "url_base"),
language=language_dir,
language=get_config_value_with_default("locales", settings.LANGUAGE_CODE),
version=config.get("help_settings", "version"),
page_path=page_path,
page_path=get_config_value_with_default("pages", page_token),
)
def get_pdf_url():
"""
Returns:
The URL for the PDF document using the pdf_settings and the help_settings (version) in the configuration
"""
return "{pdf_base}/{version}/{pdf_file}".format(
pdf_base=config.get("pdf_settings", "pdf_base"),
version=config.get("help_settings", "version"),
pdf_file=config.get("pdf_settings", "pdf_file"),
)
language_dir = get_config_value("locales", settings.LANGUAGE_CODE)
page_path = get_config_value("pages", page_token)
return {
"doc_url": get_doc_url(),
"pdf_url": get_pdf_url(),