Skip to content

Conversation

@JosueOb
Copy link
Collaborator

@JosueOb JosueOb commented Oct 6, 2021

Description

In this pull request, use cases and endpoints were created using flask to access activity data from a JSON file, according to the new backend architecture for the Time Tracker project.
The following image shows the new backend architecture.

Captura de Pantalla 2021-10-05 a la(s) 20 36 28

@JosueOb JosueOb changed the title Tt 352 create v2 read activites flask endpoint TT 352 create v2 read activites flask endpoint Oct 6, 2021
@JosueOb JosueOb changed the title TT 352 create v2 read activites flask endpoint TT-352 create v2 read activites flask endpoint Oct 6, 2021
import json
import typing


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Siempre deben quedar dos líneas entre los imports y las clases o funciones de acuerdo a PEP 8. Creo que estaba bien

if test_config is not None:
app.config.from_mapping(test_config)

ns_activities = Namespace('activities', description='Endpoint for activities')

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


class Activities(Resource):
def get(self):
activities_dto = use_cases.get_list_activities()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

porqué el sufijo _dto?

class Activity(Resource):
def get(self, activity_id: str):
try:
activities_dto = use_cases.get_activity_by_id(activity_id)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

igual aquí

yield client


def test__activities_class__uses_the_get_activities_use_case__to_retrieve_activities(client: FlaskClient,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me gusta un montón el typing en el test


def test__activities_class__uses_the_get_activities_use_case__to_retrieve_activities(client: FlaskClient,
mocker: MockFixture):
use_cases.get_list_activities = mocker.Mock(return_value=[])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

esto se hace con mocker.patch en lugar de reemplazar el valor real de get_list_activities

yield client


def test__activities_class__uses_the_get_activities_use_case__to_retrieve_activities(client: FlaskClient,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

El nombre de esta prueba dice: test__activities_class. Pero no estamos probando el activities class, estamos probando el endpoint de /activities. Entonces, este test no es un test unitario es un test de API y habría que ponerle en la correspondiente carpeta

assert [] == json_data


def test__activity_class__returns_an_activity__when_activity_matches_its_id(client: FlaskClient, mocker: MockFixture):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

igual que el anterior

assert fake_activity == json.loads(response.data)


def test__activity_class__returns_an_activity__when_no_activity_matches_its_id(client: FlaskClient,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

igual que el anterior

fake = Faker()


def test__get_list_activities_function__uses_the_activities_service__to_retrieve_activities(mocker: MockFixture):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

estos tests están perfectos


class Activities(Resource):
def get(self):
activity_json = ActivitiesJsonDao(JSON_PATH)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Este código está duplicado con la línea 21

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@JosueOb JosueOb merged commit 2c6e148 into master Oct 13, 2021
@JosueOb JosueOb deleted the TT-352-Create-V2-read-activites-flask-endpoint branch October 13, 2021 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants