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 part of #6550: Write tests for controllers/suggestion #6822

Merged
merged 10 commits into from
Jun 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions core/controllers/acl_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,11 @@ def test_can_resubmit_suggestion(self, suggestion_id, **kwargs):
UnauthorizedUserException: The user does not have
credentials to edit this suggestion.
"""
suggestion = suggestion_services.get_suggestion_by_id(suggestion_id)
if not suggestion:
raise self.InvalidInputException(
'No suggestion found with given suggestion id')

if suggestion_services.check_can_resubmit_suggestion(
suggestion_id, self.user_id):
return handler(self, suggestion_id, **kwargs)
Expand Down Expand Up @@ -1499,11 +1504,12 @@ def test_login(self, **kwargs):
def can_edit_topic(handler):
"""Decorator to check whether the user can edit given topic."""

def test_can_edit(self, topic_id, **kwargs):
def test_can_edit(self, topic_id, *args, **kwargs):
"""Checks whether the user can edit a given topic.

Args:
topic_id: str. The topic id.
*args: arguments.
**kwargs: *. Keyword arguments.

Returns:
Expand All @@ -1523,7 +1529,7 @@ def test_can_edit(self, topic_id, **kwargs):
raise base.UserFacingExceptions.PageNotFoundException

if topic_services.check_can_edit_topic(self.user, topic_rights):
return handler(self, topic_id, **kwargs)
return handler(self, topic_id, *args, **kwargs)
lilithxxx marked this conversation as resolved.
Show resolved Hide resolved
else:
raise self.UnauthorizedUserException(
'You do not have credentials to edit this topic.')
Expand Down Expand Up @@ -2429,7 +2435,16 @@ def test_can_accept_suggestion(
user_actions_info.actions):
return handler(self, target_id, suggestion_id, **kwargs)

if len(suggestion_id.split('.')) != 3:
raise self.InvalidInputException(
'Invalid format for suggestion_id.'
' It must contain 3 parts separated by \'.\'')

suggestion = suggestion_services.get_suggestion_by_id(suggestion_id)

if suggestion is None:
raise self.PageNotFoundException

if suggestion_services.check_user_can_review_in_category(
self.user_id, suggestion.score_category):
return handler(self, target_id, suggestion_id, **kwargs)
Expand Down
16 changes: 2 additions & 14 deletions core/controllers/suggestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ class SuggestionToExplorationActionHandler(base.BaseHandler):
@acl_decorators.get_decorator_for_accepting_suggestion(
acl_decorators.can_edit_exploration)
def put(self, target_id, suggestion_id):
if len(suggestion_id.split('.')) != 3:
raise self.InvalidInputException('Invalid format for suggestion_id.'
' It must contain 3 parts'
' separated by \'.\'')

if (
suggestion_id.split('.')[0] !=
suggestion_models.TARGET_TYPE_EXPLORATION):
Expand Down Expand Up @@ -90,9 +85,6 @@ class ResubmitSuggestionHandler(base.BaseHandler):
@acl_decorators.can_resubmit_suggestion
def put(self, suggestion_id):
suggestion = suggestion_services.get_suggestion_by_id(suggestion_id)
if not suggestion:
raise self.InvalidInputException(
'No suggestion found with given suggestion id')
new_change = self.payload.get('change')
change_cls = type(suggestion.change)
change_object = change_cls(new_change)
Expand All @@ -113,11 +105,6 @@ def put(self, target_id, suggestion_id):
if not constants.ENABLE_NEW_STRUCTURE_PLAYERS:
raise self.PageNotFoundException

if len(suggestion_id.split('.')) != 3:
raise self.InvalidInputException(
'Invalid format for suggestion_id. It must contain 3 parts'
' separated by \'.\'')

if suggestion_id.split('.')[0] != suggestion_models.TARGET_TYPE_TOPIC:
raise self.InvalidInputException(
'This handler allows actions only on suggestions to topics.')
Expand Down Expand Up @@ -167,7 +154,8 @@ def get(self):

for query in query_fields_and_values:
if query[0] not in suggestion_models.ALLOWED_QUERY_FIELDS:
raise Exception('Not allowed to query on field %s' % query[0])
raise self.InvalidInputException(
'Not allowed to query on field %s' % query[0])

suggestions = suggestion_services.query_suggestions(
query_fields_and_values)
Expand Down
Loading