Skip to content

Commit

Permalink
Fixing sonarcloud suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
ratheesh-aot committed Jan 23, 2024
1 parent 17d2dc8 commit 8d9c9d4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
7 changes: 4 additions & 3 deletions met-api/src/met_api/resources/widget_poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from met_api.utils.ip_util import hash_ip

API = Namespace('widget_polls', description='Endpoints for Poll Widget Management')
INVALID_REQUEST_MESSAGE = 'Invalid request format'


@cors_preflight('GET, POST')
Expand All @@ -40,7 +41,7 @@ def post(widget_id):
request_json = request.get_json()
valid_format, errors = Polls.validate_request_format(request_json)
if not valid_format:
return {'message': 'Invalid response format', 'errors': errors}, HTTPStatus.BAD_REQUEST
return {'message': INVALID_REQUEST_MESSAGE, 'errors': errors}, HTTPStatus.BAD_REQUEST
widget_poll = WidgetPollService().create_poll(widget_id, request_json)
return WidgetPollSchema().dump(widget_poll), HTTPStatus.OK
except BusinessException as err:
Expand Down Expand Up @@ -69,7 +70,7 @@ def patch(widget_id, poll_widget_id):
request_json = request.get_json()
valid_format, errors = Poll.validate_request_format(request_json)
if not valid_format:
return {'message': 'Invalid response format', 'errors': errors}, HTTPStatus.BAD_REQUEST
return {'message': INVALID_REQUEST_MESSAGE, 'errors': errors}, HTTPStatus.BAD_REQUEST

widget_poll = WidgetPollService().update_poll(widget_id, poll_widget_id, request_json)
return WidgetPollSchema().dump(widget_poll), HTTPStatus.OK
Expand Down Expand Up @@ -98,7 +99,7 @@ def post(widget_id, poll_widget_id):
response_data = request.get_json()
valid_format, errors = PollResponseRecord.validate_request_format(response_data)
if not valid_format:
return {'message': 'Invalid response format', 'errors': errors}, HTTPStatus.BAD_REQUEST
return {'message': INVALID_REQUEST_MESSAGE, 'errors': errors}, HTTPStatus.BAD_REQUEST

response_dict = PollResponseRecord.prepare_response_data(response_data, widget_id, poll_widget_id)

Expand Down
4 changes: 2 additions & 2 deletions met-api/tests/unit/api/test_widget_poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_create_poll_widget(client, jwt, session, setup_admin_user_and_claims):
"""Assert that a poll widget can be POSTed."""
# Test setup: create a poll widget model

user, claims = setup_admin_user_and_claims
_, claims = setup_admin_user_and_claims
headers = factory_auth_header(jwt=jwt, claims=claims)

engagement = factory_engagement_model()
Expand Down Expand Up @@ -111,7 +111,7 @@ def test_create_poll_widget(client, jwt, session, setup_admin_user_and_claims):
def test_update_poll_widget(client, jwt, session, setup_admin_user_and_claims):
"""Assert that a poll widget can be PATCHed."""
# Test setup: create and post a poll widget model
user, claims = setup_admin_user_and_claims
_, claims = setup_admin_user_and_claims
headers = factory_auth_header(jwt=jwt, claims=claims)

engagement = factory_engagement_model()
Expand Down
6 changes: 0 additions & 6 deletions met-api/tests/unit/services/test_widget_poll_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,6 @@ def test_check_already_polled(session):
already_polled = WidgetPollService.check_already_polled(poll.id, response_data['participant_id'], 1)
assert already_polled is True

# Test wrong poll id
with pytest.raises(BusinessException) as exc_info:
_ = WidgetPollService.check_already_polled('wrong_string', response_data['participant_id'], 1)

assert exc_info.value.status_code == HTTPStatus.INTERNAL_SERVER_ERROR


def test_is_poll_active(session):
"""Check if poll is active or not."""
Expand Down

0 comments on commit 8d9c9d4

Please sign in to comment.