Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions V2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ help:
@echo "---------------HELP-----------------"
@echo "To install the dependencies type make install"
@echo "To test the project type make test"
@echo "To test a specific test of the project make test specific_test=name of test"
@echo "To run the local database type make start-local"
@echo "To run all comands type make ci"
@echo "------------------------------------"
Expand All @@ -17,13 +18,17 @@ install:

.PHONY: test
test: export ENVIRONMENT = test
test: export TEST_DB_CONNECTION = sqlite:///:memory:
test: export TEST_DB_CONNECTION = sqlite:///file:memory?mode=memory&cache=shared&uri=true
test:
@echo "=========================================Lint with flake8========================================="
flake8 . --show-source --statistics
@echo "Completed flake8!"
@echo "=========================================Test with pytest========================================="
python -m pytest -v
@if [ "$(specific_test)" ]; then \
python -m pytest -v -k $(specific_test);\
else \
python -m pytest -v;\
fi
@echo "Completed test!"

start-local:
Expand Down
5 changes: 0 additions & 5 deletions V2/tests/api/azure/activity_azure_endpoints_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ def test__activity_azure_endpoint__returns_all_activities(
insert_activity(existent_activities[1], test_db).__dict__
]

azure_activities._get_activities.DATABASE = test_db

req = func.HttpRequest(method='GET', body=None, url=ACTIVITY_URL)
response = azure_activities._get_activities.get_activities(req)
activities_json_data = response.get_body().decode("utf-8")
Expand All @@ -33,7 +31,6 @@ def test__activity_azure_endpoint__returns_an_activity__when_activity_matches_it
existent_activity = activity_factory()
inserted_activity = insert_activity(existent_activity, test_db).__dict__

azure_activities._get_activities.DATABASE = test_db
req = func.HttpRequest(
method='GET',
body=None,
Expand All @@ -54,7 +51,6 @@ def test__activity_azure_endpoint__returns_an_activity_with_inactive_status__whe
existent_activity = activity_factory()
inserted_activity = insert_activity(existent_activity, test_db).__dict__

azure_activities._delete_activity.DATABASE = test_db
req = func.HttpRequest(
method='DELETE',
body=None,
Expand All @@ -76,7 +72,6 @@ def test__update_activity_azure_endpoint__returns_an_activity__when_found_an_act
existent_activity = activity_factory()
inserted_activity = insert_activity(existent_activity, test_db).__dict__

azure_activities._update_activity.DATABASE = test_db
activity_body = {"description": Faker().sentence()}
req = func.HttpRequest(
method='PUT',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

@pytest.fixture(name='create_fake_dao')
def _create_fake_dao() -> domain.ActivitiesDao:
db_fake = DB('sqlite:///:memory:')
db_fake = DB()
dao = infrastructure.ActivitiesSQLDao(db_fake)
return dao


@pytest.fixture(name='clean_database', autouse=True)
def _clean_database():
yield
db_fake = DB('sqlite:///:memory:')
db_fake = DB()
dao = infrastructure.ActivitiesSQLDao(db_fake)
query = dao.activity.delete()
dao.db.get_session().execute(query)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
from ... import _infrastructure
from time_tracker._infrastructure import DB

DATABASE = DB()


def create_activity(req: func.HttpRequest) -> func.HttpResponse:
activity_dao = _infrastructure.ActivitiesSQLDao(DATABASE)
database = DB()
activity_dao = _infrastructure.ActivitiesSQLDao(database)
activity_service = _domain.ActivityService(activity_dao)
use_case = _domain._use_cases.CreateActivityUseCase(activity_service)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from ... import _infrastructure
from time_tracker._infrastructure import DB

DATABASE = DB()


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


def _delete(activity_id: int) -> str:
database = DB()
activity_use_case = _domain._use_cases.DeleteActivityUseCase(
_create_activity_service(DATABASE)
_create_activity_service(database)
)
activity = activity_use_case.delete_activity(activity_id)
return json.dumps(activity.__dict__) if activity else b'Not found'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
from ... import _infrastructure
from time_tracker._infrastructure import DB

DATABASE = DB()


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

try:
if activity_id:
response = _get_by_id(int(activity_id))
response = _get_by_id(int(activity_id), database)
if response == b'Not Found':
status_code = 404
else:
response = _get_all()
response = _get_all(database)

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


def _get_by_id(activity_id: int) -> str:
def _get_by_id(activity_id: int, database: DB) -> str:
activity_use_case = _domain._use_cases.GetActivityUseCase(
_create_activity_service(DATABASE)
_create_activity_service(database)
)
activity = activity_use_case.get_activity_by_id(activity_id)

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


def _get_all() -> str:
def _get_all(database: DB) -> str:
activities_use_case = _domain._use_cases.GetActivitiesUseCase(
_create_activity_service(DATABASE)
_create_activity_service(database)
)
return json.dumps(
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
from ... import _infrastructure
from time_tracker._infrastructure import DB

DATABASE = DB()


def update_activity(req: func.HttpRequest) -> func.HttpResponse:
logging.info(
Expand Down Expand Up @@ -37,8 +35,9 @@ def update_activity(req: func.HttpRequest) -> func.HttpResponse:


def _update(activity_id: int, activity_data: dict) -> str:
database = DB()
activity_use_case = _domain._use_cases.UpdateActivityUseCase(
_create_activity_service(DATABASE)
_create_activity_service(database)
)
activity = activity_use_case.update_activity(
activity_id, activity_data.get("name"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# flake8: noqa
from ._activities_sql_dao import ActivitiesSQLDao
from ._activities_dao import ActivitiesSQLDao
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def create_time_entry(req: func.HttpRequest) -> func.HttpResponse:
def _validate_time_entry(time_entry_data: dict) -> typing.List[str]:
time_entry_fields = [field.name for field in dataclasses.fields(_domain.TimeEntry)]
time_entry_fields.pop(8)
time_entry_fields.pop(0)
missing_keys = [field for field in time_entry_fields if field not in time_entry_data]
return [
f'The {missing_key} key is missing in the input data'
Expand Down