-
Notifications
You must be signed in to change notification settings - Fork 0
TT-352 create v2 read activites flask endpoint #324
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
Merged
JosueOb
merged 26 commits into
master
from
TT-352-Create-V2-read-activites-flask-endpoint
Oct 13, 2021
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
1065bde
feat: TT-353 Create V2 Activities DAO
3bb39b0
refactor: TT-353 Solving code smells from SonarCloud
b15c301
refactor: TT-353 Solving duplicated literal
7a2565c
refactor: TT-353 Add type of argument and return type to functions
8bdbdfe
refactor: TT-353 Solving comments from PR
bc998fe
refactor: TT-353 Solving Sonarcloud code smell
9d0e21e
refactor: TT-353 Changing variable names and tests
4c467c7
feat: TT-352 Create entry point and use case to get activities
JosueOb 408c016
feat: TT-352 Create entry point and use case to get activity
JosueOb a936f0a
refactor: TT-352 use list comprehensions
JosueOb 47bb34b
refactor: TT-352 standarization flask_api directory
JosueOb 1f92569
refactor: TT-353 Solving requested changes on PR
2ce4987
refactor: TT-352 use_cases and entry_points improvements to read acti…
JosueOb 361a864
Merge branch 'TT-353-Create-V2-Activities-DAO' into TT-352-Create-V2-…
JosueOb bb87c54
test: TT-352 Unit test of activity use cases
JosueOb 1006410
test: TT-352 entry_points and use_cases for activities complete testing
JosueOb 39f5221
refactor: TT-352 solving merge conflicts
JosueOb 9539885
code-smell: TT-352 fixing code-smell
JosueOb 9e090bc
build: TT-352 implementation of CSRF Protection using Flask-WTF
JosueOb b0cc467
refactor: TT-352 improving use_cases, endpoitns and test to get activ…
JosueOb 13133d1
test: TT-352 improved testing of activity use cases
JosueOb 7b582b7
refactor: TT-352 improvement of endpoint testing for obtaining activi…
JosueOb a2d912c
refactor: TT-352 refactoring of the use case and endpoint to obtain a…
JosueOb b4987e6
refactor: TT-352 refactoring of use cases and enpoint to obtain activ…
JosueOb 4866913
test: TT-352 refactoring of use cases and enpoint to obtain activities
JosueOb fd84ea1
refactor: TT-352 refactoring of activity endpoints
JosueOb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
test: TT-352 entry_points and use_cases for activities complete testing
- Loading branch information
commit 10064105a174c755dd2f75a652e3af6d27a8e675
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,27 @@ | ||
| from flask import Flask | ||
| from flask_restplus import Resource, Api | ||
| from flask_restplus import Namespace, Resource, Api | ||
| from http import HTTPStatus | ||
|
|
||
| from . import activities_endpoints | ||
|
|
||
| app = Flask(__name__) | ||
| api = Api( | ||
| app, | ||
| version='1.0', | ||
| title='Time Tracker API', | ||
| description='API for the TimeTracker project', | ||
| ) | ||
|
|
||
| ns_activities = api.namespace('activities', description='Endpoint for activities') | ||
| ns_activities.route('/')(activities_endpoints.Activities) | ||
| ns_activities.route('/<string:activity_id>')(activities_endpoints.Activity) | ||
|
|
||
| def create_app(test_config=None): | ||
| app = Flask(__name__, instance_relative_config=True) | ||
|
|
||
| api = Api( | ||
| app, | ||
| version='1.0', | ||
| title='Time Tracker API', | ||
| description='API for the TimeTracker project', | ||
| ) | ||
|
|
||
| if test_config is not None: | ||
| app.config.from_mapping(test_config) | ||
|
|
||
| ns_activities = Namespace('activities', description='Endpoint for activities') | ||
| ns_activities.route('/')(activities_endpoints.Activities) | ||
| ns_activities.route('/<string:activity_id>')(activities_endpoints.Activity) | ||
|
|
||
| api.add_namespace(ns_activities) | ||
|
|
||
| return app | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
V2/tests/entry_points/flask_api/activities_endpoints_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import json | ||
|
|
||
| import pytest | ||
| from http import HTTPStatus | ||
| from pytest_mock import MockFixture | ||
| from flask.testing import FlaskClient | ||
| from faker import Faker | ||
| from werkzeug.exceptions import NotFound | ||
|
|
||
| from V2.source.entry_points.flask_api import create_app | ||
| from V2.source import use_cases | ||
| from V2.source.dtos.activity import Activity | ||
|
|
||
| fake = Faker() | ||
|
|
||
| valid_id = fake.uuid4() | ||
|
|
||
| fake_activity = { | ||
| "name": fake.company(), | ||
| "description": fake.paragraph(), | ||
| "tenant_id": fake.uuid4(), | ||
| "id": valid_id, | ||
| "deleted": fake.date(), | ||
| "status": fake.boolean(), | ||
| } | ||
| fake_activity_dto = Activity(**fake_activity) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def client(): | ||
| app = create_app({'TESTING': True}) | ||
| with app.test_client() as client: | ||
| yield client | ||
|
|
||
|
|
||
| def test_get_all_activities_endpoint(client: FlaskClient, mocker: MockFixture): | ||
| use_cases.get_list_activities = mocker.Mock(return_value=[]) | ||
|
||
| response = client.get("/activities/") | ||
| assert response.status_code == HTTPStatus.OK | ||
|
|
||
| json_data = json.loads(response.data) | ||
| assert [] == json_data | ||
|
|
||
|
|
||
| def test_get_activity_by_id_using_a_valid_id(client: FlaskClient, mocker: MockFixture): | ||
| use_cases.get_activity_by_id = mocker.Mock(return_value=fake_activity_dto) | ||
| response = client.get("/activities/%s" % valid_id) | ||
| assert response.status_code == HTTPStatus.OK | ||
| assert fake_activity == json.loads(response.data) | ||
|
|
||
|
|
||
| def test_get_activity_by_id_using_an_invalid_id(client: FlaskClient, mocker: MockFixture): | ||
| invalid_id = fake.uuid4() | ||
| use_cases.get_activity_by_id = mocker.Mock(side_effect=NotFound) | ||
| response = client.get("/activities/%s" % invalid_id) | ||
| assert response.status_code == HTTPStatus.NOT_FOUND | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,42 @@ | ||
| import pytest | ||
| from pytest_mock import MockFixture | ||
| from faker import Faker | ||
|
|
||
| from V2.source import use_cases | ||
| from V2.source.daos.activities_json_dao import ActivitiesJsonDao | ||
| import pytest | ||
|
|
||
| fake = Faker() | ||
|
|
||
|
|
||
| @pytest.fixture(scope='module') | ||
| def activities_json_dao(): | ||
| activities_json_dao = ActivitiesJsonDao('./V2/source/activities_data.json') | ||
| return activities_json_dao | ||
|
|
||
| def test_get_activities_use_case(activities_json_dao): | ||
|
|
||
| def test_get_activities_use_case(activities_json_dao, mocker: MockFixture): | ||
| activities_dto = activities_json_dao.get_all() | ||
| activities_expected = use_cases.get_list_activities() | ||
|
|
||
| assert activities_dto == activities_expected | ||
|
|
||
| def test_get_activity_by_id_use_case(activities_json_dao): | ||
| expected_activities = mocker.Mock() | ||
| use_cases.get_list_activities = mocker.Mock(return_value=expected_activities) | ||
| actual_activities = use_cases.get_list_activities() | ||
|
|
||
| assert use_cases.get_list_activities.called | ||
| assert expected_activities == actual_activities | ||
|
|
||
|
|
||
| def test_get_activity_by_id_use_case(activities_json_dao, mocker: MockFixture): | ||
| activity_dto = activities_json_dao.get_by_id('94ec92e2-a500-4700-a9f6-e41eb7b5507c') | ||
| activity_expected = use_cases.get_activity_by_id('94ec92e2-a500-4700-a9f6-e41eb7b5507c') | ||
|
|
||
| assert activity_dto == activity_expected | ||
| assert activity_dto == activity_expected | ||
|
|
||
| expected_activity = mocker.Mock() | ||
| use_cases.get_activity_by_id = mocker.Mock(return_value=expected_activity) | ||
| actual_activity = use_cases.get_activity_by_id(fake.uuid4()) | ||
|
|
||
| assert use_cases.get_activity_by_id.called | ||
| assert expected_activity == actual_activity |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
con el prefijo ns_ te refieres a que es un namespace? capaz es mejor cambiar el nombre a activities_namespace