-
Notifications
You must be signed in to change notification settings - Fork 0
feat: TT-417-crud-v2-projects #360
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
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
237d47e
feat: TT-417 created CRUD project
ararcos da64eef
test: TT-417 add test of projects
Jobzi 6376755
test: TT-417 add test with customer id
Jobzi 4e614c2
refactor: TT-417 created enums and use
ararcos 4057a10
test: TT-417 add missing tests
Jobzi 25f7860
test: TT-417 add missing tests and resolve comments
ararcos db9bedc
refactor: TT-417 add HTTPStatus from http
Jobzi 7dec55a
refactor: TT-417 test name correction
ararcos 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-417 add test of projects
- Loading branch information
commit da64eeff66ce68363365a34d36b3b74d4e1224ad
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 |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| import json | ||
|
|
||
| import pytest | ||
| from faker import Faker | ||
| import azure.functions as func | ||
|
|
||
| from time_tracker.projects._application import _projects as azure_projects | ||
| from time_tracker.projects import _domain as domain | ||
| from time_tracker.projects import _infrastructure as infrastructure | ||
| from time_tracker._infrastructure import DB | ||
|
|
||
| PROJECT_URL = '/api/projects/' | ||
|
|
||
|
|
||
| @pytest.fixture(name='insert_project') | ||
| def _insert_project() -> domain.Project: | ||
| def _new_project(project: domain.Project, database: DB): | ||
| dao = infrastructure.ProjectsSQLDao(database) | ||
| new_project = dao.create(project) | ||
| return new_project | ||
| return _new_project | ||
|
|
||
|
|
||
| def test__project_azure_endpoint__returns_all_projects( | ||
| test_db, project_factory, insert_project | ||
| ): | ||
| project_to_insert = [project_factory(), project_factory()] | ||
| inserted_projects = [ | ||
| insert_project(project_to_insert[0], test_db).__dict__, | ||
| insert_project(project_to_insert[1], test_db).__dict__ | ||
| ] | ||
|
|
||
| req = func.HttpRequest(method='GET', body=None, url=PROJECT_URL) | ||
| response = azure_projects._get_projects.get_projects(req) | ||
| projects_json_data = response.get_body().decode("utf-8") | ||
|
|
||
| assert response.status_code == 200 | ||
| assert projects_json_data == json.dumps(inserted_projects) | ||
|
|
||
|
|
||
| def test__project_azure_endpoint__returns_an_project__when_project_matches_its_id( | ||
ararcos marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| test_db, project_factory, insert_project | ||
| ): | ||
| project_to_insert = project_factory() | ||
| inserted_project = insert_project(project_to_insert, test_db).__dict__ | ||
|
|
||
| req = func.HttpRequest( | ||
| method='GET', | ||
| body=None, | ||
| url=PROJECT_URL, | ||
| route_params={"id": inserted_project["id"]}, | ||
| ) | ||
|
|
||
| response = azure_projects._get_projects.get_projects(req) | ||
| activitiy_json_data = response.get_body().decode("utf-8") | ||
|
|
||
| assert response.status_code == 200 | ||
| assert activitiy_json_data == json.dumps(inserted_project) | ||
|
|
||
|
|
||
| def test__projects_azure_endpoint__returns_a_status_code_400__when_project_recive_invalid_id( | ||
| ): | ||
| req = func.HttpRequest( | ||
| method="GET", | ||
| body=None, | ||
| url=PROJECT_URL, | ||
| route_params={"id": "invalid id"}, | ||
| ) | ||
|
|
||
| response = azure_projects._get_projects.get_projects(req) | ||
|
|
||
| assert response.status_code == 400 | ||
| assert response.get_body() == b'Invalid Format ID' | ||
|
|
||
|
|
||
| def test__project_azure_endpoint__returns_an_project_with_inactive_status__when_an_project_matching_its_id_is_found( | ||
| test_db, project_factory, insert_project | ||
| ): | ||
| project_to_insert = project_factory() | ||
| inserted_project = insert_project(project_to_insert, test_db).__dict__ | ||
|
|
||
| req = func.HttpRequest( | ||
| method='DELETE', | ||
| body=None, | ||
| url=PROJECT_URL, | ||
| route_params={"id": inserted_project["id"]}, | ||
| ) | ||
|
|
||
| response = azure_projects._delete_project.delete_project(req) | ||
| project_json_data = json.loads(response.get_body().decode("utf-8")) | ||
|
|
||
| assert response.status_code == 200 | ||
| assert project_json_data['status'] == 0 | ||
| assert project_json_data['deleted'] is True | ||
|
|
||
|
|
||
| def test__delete_projects_azure_endpoint__returns_a_status_code_400__when_project_recive_invalid_id( | ||
ararcos marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ): | ||
| req = func.HttpRequest( | ||
| method="DELETE", | ||
| body=None, | ||
| url=PROJECT_URL, | ||
| route_params={"id": "invalid id"}, | ||
| ) | ||
|
|
||
| response = azure_projects._delete_project.delete_project(req) | ||
|
|
||
| assert response.status_code == 400 | ||
| assert response.get_body() == b'Invalid Format ID' | ||
|
|
||
|
|
||
| def test__update_project_azure_endpoint__returns_an_project__when_found_an_project_to_update( | ||
| test_db, project_factory, insert_project | ||
| ): | ||
| project_to_insert = project_factory() | ||
| inserted_project = insert_project(project_to_insert, test_db).__dict__ | ||
|
|
||
| project_body = {"description": Faker().sentence()} | ||
| req = func.HttpRequest( | ||
| method='PUT', | ||
| body=json.dumps(project_body).encode("utf-8"), | ||
| url=PROJECT_URL, | ||
| route_params={"id": inserted_project["id"]}, | ||
| ) | ||
|
|
||
| response = azure_projects._update_project.update_project(req) | ||
| activitiy_json_data = response.get_body().decode("utf-8") | ||
| inserted_project.update(project_body) | ||
|
|
||
| assert response.status_code == 200 | ||
| assert activitiy_json_data == json.dumps(inserted_project) | ||
|
|
||
|
|
||
| def test__update_projects_azure_endpoint__returns_a_status_code_400__when_project_recive_invalid_id( | ||
| ): | ||
| req = func.HttpRequest( | ||
| method="PUT", | ||
| body=None, | ||
| url=PROJECT_URL, | ||
| route_params={"id": "invalid id"}, | ||
| ) | ||
|
|
||
| response = azure_projects._update_project.update_project(req) | ||
|
|
||
| assert response.status_code == 400 | ||
| assert response.get_body() == b'Invalid Format ID' | ||
|
|
||
|
|
||
| def test__project_azure_endpoint__creates_an_project__when_project_has_all_attributes( | ||
| project_factory | ||
| ): | ||
| project_body = project_factory().__dict__ | ||
| body = json.dumps(project_body).encode("utf-8") | ||
ararcos marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| req = func.HttpRequest( | ||
| method='POST', | ||
| body=body, | ||
| url=PROJECT_URL, | ||
| ) | ||
|
|
||
| response = azure_projects._create_project.create_project(req) | ||
| project_json_data = json.loads(response.get_body()) | ||
| project_body['id'] = project_json_data['id'] | ||
|
|
||
| assert response.status_code == 201 | ||
| assert project_json_data == project_body | ||
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
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,136 @@ | ||
| import pytest | ||
| import typing | ||
| from faker import Faker | ||
|
|
||
| from time_tracker.projects import _domain as domain | ||
| from time_tracker.projects import _infrastructure as infrastructure | ||
| from time_tracker._infrastructure import DB | ||
|
|
||
|
|
||
| @pytest.fixture(name='create_fake_dao') | ||
| def _create_fake_dao() -> domain.ProjectsDao: | ||
| db_fake = DB() | ||
| dao = infrastructure.ProjectsSQLDao(db_fake) | ||
| return dao | ||
|
|
||
|
|
||
| @pytest.fixture(name='clean_database', autouse=True) | ||
| def _clean_database(): | ||
| yield | ||
| db_fake = DB() | ||
| dao = infrastructure.ProjectsSQLDao(db_fake) | ||
| query = dao.project.delete() | ||
| dao.db.get_session().execute(query) | ||
|
|
||
|
|
||
| def test__create_project__returns_a_project_dto__when_saves_correctly_with_sql_database( | ||
| create_fake_dao, project_factory | ||
| ): | ||
| dao = create_fake_dao | ||
| project_to_insert = project_factory() | ||
|
|
||
| inserted_project = dao.create(project_to_insert) | ||
|
|
||
| assert isinstance(inserted_project, domain.Project) | ||
| assert inserted_project == project_to_insert | ||
|
|
||
|
|
||
| def test_update__returns_an_update_project__when_an_project_matching_its_id_is_found_with_sql_database( | ||
| create_fake_dao, project_factory | ||
| ): | ||
| dao = create_fake_dao | ||
| project_to_insert = project_factory() | ||
| inserted_project = dao.create(project_to_insert) | ||
|
|
||
| expected_description = Faker().sentence() | ||
| updated_project = dao.update(inserted_project.id, {"description": expected_description}) | ||
|
|
||
| assert isinstance(updated_project, domain.Project) | ||
| assert updated_project.id == inserted_project.id | ||
| assert updated_project.description == expected_description | ||
|
|
||
|
|
||
| def test_update__returns_none__when_no_project_matching_its_id_is_found_with_sql_database( | ||
| create_fake_dao, project_factory | ||
| ): | ||
| dao = create_fake_dao | ||
| project_to_insert = project_factory() | ||
|
|
||
| results = dao.update(project_to_insert.id, {"description": Faker().sentence()}) | ||
|
|
||
| assert results is None | ||
|
|
||
|
|
||
| def test__get_all__returns_a_list_of_project_dto_objects__when_one_or_more_projects_are_found_with_sql_database( | ||
| create_fake_dao, project_factory | ||
| ): | ||
| dao = create_fake_dao | ||
| project_to_inserts = [project_factory(), project_factory()] | ||
| inserted_projects = [ | ||
| dao.create(project_to_inserts[0]), | ||
| dao.create(project_to_inserts[1]) | ||
| ] | ||
|
|
||
| projects = dao.get_all() | ||
| assert isinstance(projects, typing.List) | ||
| assert projects == inserted_projects | ||
|
|
||
|
|
||
| def test_get_by_id__returns_an_project_dto__when_found_one_project_that_matches_its_id_with_sql_database( | ||
| create_fake_dao, project_factory | ||
| ): | ||
| dao = create_fake_dao | ||
| project_to_insert = project_factory() | ||
| inserted_project = dao.create(project_to_insert) | ||
|
|
||
| project = dao.get_by_id(inserted_project.id) | ||
|
|
||
| assert isinstance(project, domain.Project) | ||
| assert project.id == inserted_project.id | ||
| assert project == inserted_project | ||
|
|
||
|
|
||
| def test__get_by_id__returns_none__when_no_project_matches_its_id_with_sql_database( | ||
| create_fake_dao, project_factory | ||
| ): | ||
| dao = create_fake_dao | ||
| project_to_insert = project_factory() | ||
|
|
||
| project = dao.get_by_id(project_to_insert.id) | ||
|
|
||
| assert project is None | ||
|
|
||
|
|
||
| def test_get_all__returns_an_empty_list__when_doesnt_found_any_projects_with_sql_database( | ||
| create_fake_dao | ||
| ): | ||
| projects = create_fake_dao.get_all() | ||
|
|
||
| assert isinstance(projects, typing.List) | ||
| assert projects == [] | ||
|
|
||
|
|
||
| def test_delete__returns_an_project_with_inactive_status__when_an_project_matching_its_id_is_found_with_sql_database( | ||
| create_fake_dao, project_factory | ||
| ): | ||
| dao = create_fake_dao | ||
| project_to_insert = project_factory() | ||
| inserted_project = dao.create(project_to_insert) | ||
|
|
||
| project = dao.delete(inserted_project.id) | ||
|
|
||
| assert isinstance(project, domain.Project) | ||
| assert project.id == inserted_project.id | ||
| assert project.status == 0 | ||
| assert project.deleted is True | ||
|
|
||
|
|
||
| def test_delete__returns_none__when_no_project_matching_its_id_is_found_with_sql_database( | ||
| create_fake_dao, project_factory | ||
| ): | ||
| dao = create_fake_dao | ||
| project_to_insert = project_factory() | ||
|
|
||
| results = dao.delete(project_to_insert.id) | ||
|
|
||
| assert results is None |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.