Skip to content
Prev Previous commit
Next Next commit
refactor: TT-353 Solving code smells from SonarCloud
  • Loading branch information
Andrés Soto committed Sep 24, 2021
commit 3bb39b069da8dfade88b21e096333b4ab7a939db
2 changes: 1 addition & 1 deletion V2/source/daos/activities_json_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def get_by_id(self, id):
activities = json.load(file)
file.close()

except FileNotFoundError as e:
except FileNotFoundError:
return HTTPStatus.NOT_FOUND

activity = next(
Expand Down
21 changes: 8 additions & 13 deletions V2/tests/daos/activities_json_dao_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def test_get_by_id__return_activity_dto__when_find_activity_that_matches_its_id(
mocker,
):
activities_json_dao = ActivitiesJsonDao('non-important-path')
open_file = 'builtins.open'
activities = [
{
"name": "test_name",
Expand All @@ -22,9 +23,7 @@ def test_get_by_id__return_activity_dto__when_find_activity_that_matches_its_id(
read_data = json.dumps(activities)
activity_dto = ActivityDto(**activities.pop())

open_file_mock = mocker.patch(
'builtins.open', mocker.mock_open(read_data=read_data)
)
mocker.patch(open_file, mocker.mock_open(read_data=read_data))

result = activities_json_dao.get_by_id(activity_dto.id)

Expand All @@ -35,13 +34,11 @@ def test__get_by_id__return_httpstatus_not_found__when_no_activity_matches_its_i
mocker,
):
activities_json_dao = ActivitiesJsonDao('non-important-path')

open_file = 'builtins.open'
activity = []
read_data = json.dumps(activity)

open_file_mock = mocker.patch(
'builtins.open', mocker.mock_open(read_data=read_data)
)
mocker.patch(open_file, mocker.mock_open(read_data=read_data))

result = activities_json_dao.get_by_id('non-important-id')

Expand All @@ -52,6 +49,7 @@ def test_get_all__return_list_of_activity_dto__when_find_one_or_more_activities(
mocker,
):
activities_json_dao = ActivitiesJsonDao('non-important-path')
open_file = 'builtins.open'
activity = {
"name": "test_name",
"description": "test_description",
Expand All @@ -68,9 +66,7 @@ def test_get_all__return_list_of_activity_dto__when_find_one_or_more_activities(
activities = [activity] * number_of_activities
read_data = json.dumps(activities)

open_file_mock = mocker.patch(
'builtins.open', mocker.mock_open(read_data=read_data)
)
mocker.patch(open_file, mocker.mock_open(read_data=read_data))

result = activities_json_dao.get_all()

Expand All @@ -79,13 +75,12 @@ def test_get_all__return_list_of_activity_dto__when_find_one_or_more_activities(

def test_get_all__return_empty_list__when_doesnt_found_any_activities(mocker):
activities_json_dao = ActivitiesJsonDao('non-important-path')
open_file = 'builtins.open'
activities = []

read_data = json.dumps(activities)

open_file_mock = mocker.patch(
'builtins.open', mocker.mock_open(read_data=read_data)
)
mocker.patch(open_file, mocker.mock_open(read_data=read_data))

result = activities_json_dao.get_all()

Expand Down