Skip to content

Commit a212e94

Browse files
committed
feat: TT-418 merge with master changes
1 parent 2d0efbd commit a212e94

File tree

13 files changed

+125
-46
lines changed

13 files changed

+125
-46
lines changed

V2/Makefile

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
.PHONY: help
22
help:
33
@echo "---------------HELP-----------------"
4-
@echo "To install the dependencies type make install"
5-
@echo "To test the project type make test"
6-
@echo "To run the local database type make start-local"
7-
@echo "To run all comands type make ci"
4+
@echo "- make install --> Install the dependencies"
5+
@echo "- make test --> Run all tests"
6+
@echo "- make test specific_test=<name_of_the_test> --> Run specific test"
7+
@echo "- make start-local --> Run local database"
8+
@echo "- make ci --> Install the dependencies and run all tests"
89
@echo "------------------------------------"
910

1011
.PHONY: install
@@ -17,13 +18,16 @@ install:
1718

1819
.PHONY: test
1920
test: export ENVIRONMENT = test
20-
test: export TEST_DB_CONNECTION = sqlite:///:memory:
2121
test:
2222
@echo "=========================================Lint with flake8========================================="
2323
flake8 . --show-source --statistics
2424
@echo "Completed flake8!"
2525
@echo "=========================================Test with pytest========================================="
26-
python -m pytest -v
26+
@if [ "$(specific_test)" ]; then \
27+
python -m pytest -vv -s -k $(specific_test);\
28+
else \
29+
python -m pytest -v;\
30+
fi
2731
@echo "Completed test!"
2832

2933
start-local:

V2/README.md

Lines changed: 94 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,108 @@
1-
# time-tracker-api V2
1+
# **Time-tracker-api V2 Architecture**
2+
Architecture
3+
The application follows a DDD approach with a hexagonal clean architecture. BIG WORDS!, what does it mean? it means the following:
24

3-
Refer to [Serverless docs](https://serverless.com/framework/docs/providers/azure/guide/intro/) for more information.
5+
We have a directory for each domain entitiy (i.e. time entries, technologies, activities, etc)
6+
Inside each entity directory we have other 3 directories (application, domain and infrastructure)
7+
I'll leave this drawing to understand how these three folders work and what logic should be included in these directories
48

5-
## Requirements to use makefile
9+
![ddd.png](https://raw.githubusercontent.com/eguezgustavo/time_tracker_app_skeleton/master/ddd.png)
10+
More information [Here](https://github.com/eguezgustavo/time_tracker_app_skeleton)
611

7-
- Python version 3.6 or 3.7.
12+
## **Stack Technologies**
13+
- [Serverless](https://serverless.com/framework/docs/providers/azure/guide/intro/)
14+
- Python
15+
- Pytest
16+
- Docker Compose
17+
18+
Recommended link [tdd_dojo](https://github.com/eguezgustavo/tdd_dojo)
819

9-
- Use an environment to install requirements (pyenv).
20+
## **Setup environment**
1021

11-
## How to use makefile
22+
### **Requeriments**
23+
24+
- Install python 3.6 or 3.7 (recommendation to install python [pyenv](https://github.com/pyenv/pyenv))
25+
- Install node (recommendation to install node [nvm](https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-20-04-es#:~:text=de%20Node.js.-,Opci%C3%B3n%203%3A%20Instalar%20Node%20usando%20el%20administrador%20de%20versiones%20de%20Node,-Otra%20forma%20de))
26+
27+
### **Add variables**
28+
In the root directory /time-tracker-backend create a file .env with these values
29+
30+
```
31+
export MS_AUTHORITY=XXX
32+
export MS_CLIENT_ID=XXX
33+
export MS_SCOPE=XXX
34+
export MS_SECRET=XXX
35+
export MS_ENDPOINT=XXX
36+
export DATABASE_ACCOUNT_URI=XXX
37+
export DATABASE_MASTER_KEY=XXX
38+
export DATABASE_NAME=XXX
39+
export FLASK_APP=XXX
40+
export FLASK_ENV=XXX
41+
export AZURE_APP_CONFIGURATION_CONNECTION_STRING=XXX
42+
export USERID=XXX
43+
export FLASK_DEBUG=True
44+
export PYTHONPATH=XXX
45+
export DB_CONNECTION=XXX
46+
export ENVIRONMENT=XXX
47+
```
48+
49+
In the directory /V2 create a file .env with these values
50+
```
51+
DB_USER=XXX
52+
DB_PASS=XXX
53+
DB_NAME=XXX
54+
```
55+
56+
### **Install dependencies**
57+
In the Directory /V2
58+
```
59+
make install
60+
```
61+
62+
## **Start Project**
63+
In the directory /V2
64+
```
65+
npm run offline
66+
docker compose up or make start-local
67+
```
68+
69+
70+
## **Makefile to run a locally CI**
1271

1372
Execute the next command to show makefile help:
1473

1574
```shell
16-
make help
75+
$ make help
1776
```
1877

1978
- To install the dependencies type the command ```make install```
20-
2179
- To test the project type the command ```make test```
22-
2380
- To run the local database type the command ```make start-local```
81+
82+
## **How to contribute to the project**
83+
Clone the repository and from the master branch create a new branch for each new task.
84+
### **Branch names format**
85+
For example if your task in Jira is **TT-48 implement semantic versioning** your branch name is:
86+
```
87+
TT-48-implement-semantic-versioning
88+
```
89+
### **Commit messages format**
90+
91+
92+
Below there are some common examples you can use for your commit messages [semantic version](https://semver.org/) :
93+
94+
- **feat**: A new feature.
95+
- **fix**: A bug fix.
96+
- **perf**: A code change that improves performance.
97+
- **build**: Changes that affect the build system or external dependencies (example scopes: npm, ts configuration).
98+
- **ci**: Changes to our CI or CD configuration files and scripts (example scopes: Azure devops, github actions).
99+
- **docs**: Documentation only changes.
100+
- **refactor**: A code change that neither fixes a bug nor adds a feature.
101+
It is important to mention that this key is not related to css styles.
102+
- **test**: Adding missing tests or correcting existing tests.
103+
104+
### Example
105+
fix: TT-48 implement semantic versioning
106+
107+
Prefix to use in the space fix:
108+
`(fix: |feat: |perf: |build: |ci: |docs: |refactor: |style: |test: )`

V2/serverless.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,3 @@ functions:
157157
#endregion Fin Customer
158158

159159
#endregion Fin Funciones
160-

V2/tests/api/azure/activity_azure_endpoints_test.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ def test__activity_azure_endpoint__returns_all_activities(
1717
insert_activity(existent_activities[1], test_db).__dict__
1818
]
1919

20-
azure_activities._get_activities.DATABASE = test_db
21-
2220
req = func.HttpRequest(method='GET', body=None, url=ACTIVITY_URL)
2321
response = azure_activities._get_activities.get_activities(req)
2422
activities_json_data = response.get_body().decode("utf-8")
@@ -33,7 +31,6 @@ def test__activity_azure_endpoint__returns_an_activity__when_activity_matches_it
3331
existent_activity = activity_factory()
3432
inserted_activity = insert_activity(existent_activity, test_db).__dict__
3533

36-
azure_activities._get_activities.DATABASE = test_db
3734
req = func.HttpRequest(
3835
method='GET',
3936
body=None,
@@ -54,7 +51,6 @@ def test__activity_azure_endpoint__returns_an_activity_with_inactive_status__whe
5451
existent_activity = activity_factory()
5552
inserted_activity = insert_activity(existent_activity, test_db).__dict__
5653

57-
azure_activities._delete_activity.DATABASE = test_db
5854
req = func.HttpRequest(
5955
method='DELETE',
6056
body=None,
@@ -76,7 +72,6 @@ def test__update_activity_azure_endpoint__returns_an_activity__when_found_an_act
7672
existent_activity = activity_factory()
7773
inserted_activity = insert_activity(existent_activity, test_db).__dict__
7874

79-
azure_activities._update_activity.DATABASE = test_db
8075
activity_body = {"description": Faker().sentence()}
8176
req = func.HttpRequest(
8277
method='PUT',

V2/tests/integration/daos/activities_sql_dao_test.py renamed to V2/tests/integration/daos/activities_dao_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99

1010
@pytest.fixture(name='create_fake_dao')
1111
def _create_fake_dao() -> domain.ActivitiesDao:
12-
db_fake = DB('sqlite:///:memory:')
12+
db_fake = DB()
1313
dao = infrastructure.ActivitiesSQLDao(db_fake)
1414
return dao
1515

1616

1717
@pytest.fixture(name='clean_database', autouse=True)
1818
def _clean_database():
1919
yield
20-
db_fake = DB('sqlite:///:memory:')
20+
db_fake = DB()
2121
dao = infrastructure.ActivitiesSQLDao(db_fake)
2222
query = dao.activity.delete()
2323
dao.db.get_session().execute(query)

V2/time_tracker/activities/_application/_activities/_create_activity.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
from ... import _infrastructure
99
from time_tracker._infrastructure import DB
1010

11-
DATABASE = DB()
12-
1311

1412
def create_activity(req: func.HttpRequest) -> func.HttpResponse:
15-
activity_dao = _infrastructure.ActivitiesSQLDao(DATABASE)
13+
database = DB()
14+
activity_dao = _infrastructure.ActivitiesSQLDao(database)
1615
activity_service = _domain.ActivityService(activity_dao)
1716
use_case = _domain._use_cases.CreateActivityUseCase(activity_service)
1817

V2/time_tracker/activities/_application/_activities/_delete_activity.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
from ... import _infrastructure
88
from time_tracker._infrastructure import DB
99

10-
DATABASE = DB()
11-
1210

1311
def delete_activity(req: func.HttpRequest) -> func.HttpResponse:
1412
logging.info(
@@ -29,8 +27,9 @@ def delete_activity(req: func.HttpRequest) -> func.HttpResponse:
2927

3028

3129
def _delete(activity_id: int) -> str:
30+
database = DB()
3231
activity_use_case = _domain._use_cases.DeleteActivityUseCase(
33-
_create_activity_service(DATABASE)
32+
_create_activity_service(database)
3433
)
3534
activity = activity_use_case.delete_activity(activity_id)
3635
return json.dumps(activity.__dict__) if activity else b'Not found'

V2/time_tracker/activities/_application/_activities/_get_activities.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
from ... import _infrastructure
88
from time_tracker._infrastructure import DB
99

10-
DATABASE = DB()
11-
1210

1311
def get_activities(req: func.HttpRequest) -> func.HttpResponse:
12+
database = DB()
1413
logging.info(
1514
'Python HTTP trigger function processed a request to get an activity.'
1615
)
@@ -19,11 +18,11 @@ def get_activities(req: func.HttpRequest) -> func.HttpResponse:
1918

2019
try:
2120
if activity_id:
22-
response = _get_by_id(int(activity_id))
21+
response = _get_by_id(int(activity_id), database)
2322
if response == b'Not Found':
2423
status_code = 404
2524
else:
26-
response = _get_all()
25+
response = _get_all(database)
2726

2827
return func.HttpResponse(
2928
body=response, status_code=status_code, mimetype="application/json"
@@ -34,18 +33,18 @@ def get_activities(req: func.HttpRequest) -> func.HttpResponse:
3433
)
3534

3635

37-
def _get_by_id(activity_id: int) -> str:
36+
def _get_by_id(activity_id: int, database: DB) -> str:
3837
activity_use_case = _domain._use_cases.GetActivityUseCase(
39-
_create_activity_service(DATABASE)
38+
_create_activity_service(database)
4039
)
4140
activity = activity_use_case.get_activity_by_id(activity_id)
4241

4342
return json.dumps(activity.__dict__) if activity else b'Not Found'
4443

4544

46-
def _get_all() -> str:
45+
def _get_all(database: DB) -> str:
4746
activities_use_case = _domain._use_cases.GetActivitiesUseCase(
48-
_create_activity_service(DATABASE)
47+
_create_activity_service(database)
4948
)
5049
return json.dumps(
5150
[

V2/time_tracker/activities/_application/_activities/_update_activity.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
from ... import _infrastructure
99
from time_tracker._infrastructure import DB
1010

11-
DATABASE = DB()
12-
1311

1412
def update_activity(req: func.HttpRequest) -> func.HttpResponse:
1513
logging.info(
@@ -37,8 +35,9 @@ def update_activity(req: func.HttpRequest) -> func.HttpResponse:
3735

3836

3937
def _update(activity_id: int, activity_data: dict) -> str:
38+
database = DB()
4039
activity_use_case = _domain._use_cases.UpdateActivityUseCase(
41-
_create_activity_service(DATABASE)
40+
_create_activity_service(database)
4241
)
4342
activity = activity_use_case.update_activity(
4443
activity_id, activity_data.get("name"),
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# flake8: noqa
2-
from ._activities_sql_dao import ActivitiesSQLDao
2+
from ._activities_dao import ActivitiesSQLDao

0 commit comments

Comments
 (0)