Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #5466: Added check to enforce that all name of controllers end with "Handler" or "Page" #5878

Merged
merged 12 commits into from
Nov 28, 2018
Merged
Prev Previous commit
Next Next commit
Modified render_downloadable test
  • Loading branch information
Rishav Chakraborty committed Nov 16, 2018
commit 67634f9823108264862f84b98cd6e8aa0dbd5e6d
20 changes: 10 additions & 10 deletions core/controllers/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,11 @@ def setUp(self):
def test_downloadable(self):
response = self.testapp.get('/mock')
self.assertEqual(response.status_int, 200)
self.assertTrue(response.content_disposition.startswith('attachment'))
self.assertEqual(
response.content_disposition,
'attachment; filename=example.pdf')
self.assertEqual(response.body, 'example')
self.assertEqual(response.content_type, 'text/plain')


class LogoutPageTest(test_utils.GenericTestBase):
Expand Down Expand Up @@ -541,7 +544,7 @@ def test_every_method_has_decorator(self):
handlers_checked = []

for route in main.URLS:
# URLS = MAPREDUCE_HANDLERS + other handers. MAPREDUCE_HANDLERS
# URLS = MAPREDUCE_HANDLERS + other handlers. MAPREDUCE_HANDLERS
# are tuples. So, below check is to handle them.
if isinstance(route, tuple):
continue
Expand Down Expand Up @@ -625,23 +628,20 @@ def test_controller_class_names(self):
"""This function checks that all controller class names end with
either 'Handler', 'Page' or 'FileDownloader'.
"""
allowed_handler_error_return_type = [feconf.HANDLER_TYPE_JSON,
feconf.HANDLER_TYPE_HTML,
feconf.HANDLER_TYPE_DOWNLOADABLE]
# A mapping of returned handler types to expected name endings.
handler_type_to_name_endings_dict = {
feconf.HANDLER_TYPE_HTML: 'Page',
feconf.HANDLER_TYPE_JSON: 'Handler',
feconf.HANDLER_TYPE_DOWNLOADABLE: 'FileDownloader',
}
handlers_checked = 0
num_handlers_checked = 0
for url in main.URLS:
# URLS = MAPREDUCE_HANDLERS + other handers. MAPREDUCE_HANDLERS
# URLS = MAPREDUCE_HANDLERS + other handlers. MAPREDUCE_HANDLERS
# are tuples. So, below check is to pick only those which have
# a RedirectRoute associated with it.
if isinstance(url, main.routes.RedirectRoute):
clazz = url.handler
handlers_checked += 1
num_handlers_checked += 1
all_base_classes = [base_class.__name__ for base_class in
(inspect.getmro(clazz))]
# Check that it is a subclass of 'BaseHandler'.
Expand All @@ -653,7 +653,7 @@ def test_controller_class_names(self):
if 'get' in clazz.__dict__.keys():
self.assertIn(
class_return_type,
allowed_handler_error_return_type)
handler_type_to_name_endings_dict)
class_name = clazz.__name__
file_name = inspect.getfile(clazz)
line_num = inspect.getsourcelines(clazz)[1]
Expand Down Expand Up @@ -684,4 +684,4 @@ def test_controller_class_names(self):
self.assertTrue(class_name.endswith('Handler'),
msg=error_message)

self.assertGreater(handlers_checked, 150)
self.assertGreater(num_handlers_checked, 150)
4 changes: 2 additions & 2 deletions core/controllers/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ def get(self, exploration_id):
width = int(self.request.get('width', default_value=80))

# If the title of the exploration has changed, we use the new title.
filename = 'oppia-%s-v%s%s' % (
utils.to_ascii(exploration.title.replace(' ', '')), version, '.zip')
filename = 'oppia-%s-v%s.zip' % (
utils.to_ascii(exploration.title.replace(' ', '')), version)

if output_format == feconf.OUTPUT_FORMAT_ZIP:
self.render_downloadable_file(
Expand Down