-
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 all commits
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
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
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,251 @@ | ||
import json | ||
from http import HTTPStatus | ||
|
||
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 | ||
|
||
PROJECT_URL = '/api/projects/' | ||
|
||
|
||
@pytest.fixture(name='insert_project') | ||
def _insert_project(test_db, insert_customer, project_factory, customer_factory) -> domain.Project: | ||
inserted_customer = insert_customer(customer_factory(), test_db) | ||
|
||
def _new_project(): | ||
project_to_insert = project_factory(customer_id=inserted_customer.id) | ||
dao = infrastructure.ProjectsSQLDao(test_db) | ||
inserted_project = dao.create(project_to_insert) | ||
return inserted_project | ||
return _new_project | ||
|
||
|
||
def test__project_azure_endpoint__returns_all_projects( | ||
insert_project | ||
): | ||
inserted_projects = [ | ||
insert_project().__dict__, | ||
insert_project().__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 == HTTPStatus.OK | ||
assert projects_json_data == json.dumps(inserted_projects) | ||
|
||
|
||
def test__project_azure_endpoint__returns_a_project__when_project_matches_its_id( | ||
insert_project | ||
): | ||
inserted_project = insert_project().__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 == HTTPStatus.OK | ||
assert activitiy_json_data == json.dumps(inserted_project) | ||
|
||
|
||
def test__projects_azure_endpoint__returns_a_status_code_400__when_project_receive_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 == HTTPStatus.BAD_REQUEST | ||
assert response.get_body() == b"Invalid Format ID" | ||
|
||
|
||
def test__project_azure_endpoint__returns_a_project_with_inactive_status__when_a_project_matching_its_id_is_found( | ||
insert_project | ||
): | ||
inserted_project = insert_project().__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 == HTTPStatus.OK | ||
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_receive_invalid_id( | ||
): | ||
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 == HTTPStatus.BAD_REQUEST | ||
assert response.get_body() == b"Invalid Format ID" | ||
|
||
|
||
def test__delete_projects_azure_endpoint__returns_a_status_code_404__when_no_found_a_project_to_delete( | ||
): | ||
req = func.HttpRequest( | ||
method="DELETE", | ||
body=None, | ||
url=PROJECT_URL, | ||
route_params={"id": Faker().pyint()}, | ||
) | ||
|
||
response = azure_projects._delete_project.delete_project(req) | ||
|
||
assert response.status_code == HTTPStatus.NOT_FOUND | ||
assert response.get_body() == b"Not found" | ||
|
||
|
||
def test__update_project_azure_endpoint__returns_a_project__when_found_a_project_to_update( | ||
insert_project | ||
): | ||
inserted_project = insert_project().__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 == HTTPStatus.OK | ||
assert activitiy_json_data == json.dumps(inserted_project) | ||
|
||
|
||
def test__update_projects_azure_endpoint__returns_a_status_code_404__when_no_found_a_project_to_update( | ||
project_factory | ||
): | ||
project_body = project_factory().__dict__ | ||
|
||
req = func.HttpRequest( | ||
method="PUT", | ||
body=json.dumps(project_body).encode("utf-8"), | ||
url=PROJECT_URL, | ||
route_params={"id": project_body["id"]}, | ||
) | ||
|
||
response = azure_projects._update_project.update_project(req) | ||
|
||
assert response.status_code == HTTPStatus.NOT_FOUND | ||
assert response.get_body() == b"Not found" | ||
|
||
|
||
def test__update_projects_azure_endpoint__returns_a_status_code_400__when_receive_an_incorrect_body( | ||
): | ||
project_body = Faker().pydict(5, True, str) | ||
req = func.HttpRequest( | ||
method="PUT", | ||
body=json.dumps(project_body).encode("utf-8"), | ||
url=PROJECT_URL, | ||
route_params={"id": Faker().pyint()}, | ||
) | ||
|
||
response = azure_projects._update_project.update_project(req) | ||
|
||
assert response.status_code == HTTPStatus.BAD_REQUEST | ||
assert response.get_body() == b"Incorrect body" | ||
|
||
|
||
def test__update_projects_azure_endpoint__returns_a_status_code_400__when_project_receive_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 == HTTPStatus.BAD_REQUEST | ||
assert response.get_body() == b"Invalid Format ID" | ||
|
||
|
||
def test__project_azure_endpoint__creates_a_project__when_project_has_all_attributes( | ||
test_db, project_factory, insert_customer, customer_factory | ||
): | ||
inserted = insert_customer(customer_factory(), test_db) | ||
project_body = project_factory(inserted.id).__dict__ | ||
|
||
req = func.HttpRequest( | ||
method='POST', | ||
body=json.dumps(project_body).encode("utf-8"), | ||
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 == HTTPStatus.CREATED | ||
assert project_json_data == project_body | ||
|
||
|
||
def test__project_azure_endpoint__returns_a_status_code_400__when_project_does_not_all_attributes( | ||
test_db, project_factory, insert_customer, customer_factory | ||
): | ||
inserted_customer = insert_customer(customer_factory(), test_db) | ||
project_body = project_factory(customer_id=inserted_customer.id).__dict__ | ||
project_body.pop('name') | ||
|
||
req = func.HttpRequest( | ||
method='POST', | ||
body=json.dumps(project_body).encode("utf-8"), | ||
url=PROJECT_URL, | ||
) | ||
|
||
response = azure_projects._create_project.create_project(req) | ||
|
||
assert response.status_code == HTTPStatus.BAD_REQUEST | ||
assert response.get_body() == json.dumps(['The name key is missing in the input data']).encode() | ||
|
||
|
||
def test__project_azure_endpoint__returns_a_status_code_500__when_project_receive_incorrect_type_data( | ||
project_factory, insert_customer, customer_factory, test_db | ||
): | ||
insert_customer(customer_factory(), test_db) | ||
project_body = project_factory(technologies=Faker().pylist(2, True, str)).__dict__ | ||
|
||
req = func.HttpRequest( | ||
method='POST', | ||
body=json.dumps(project_body).encode("utf-8"), | ||
url=PROJECT_URL, | ||
) | ||
|
||
response = azure_projects._create_project.create_project(req) | ||
|
||
assert response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR | ||
assert response.get_body() == b"could not be created" |
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,4 +1,5 @@ | ||
# flake8: noqa | ||
from fixtures import _activity_factory, _test_db, _insert_activity | ||
from fixtures import _time_entry_factory | ||
from fixtures import _customer_factory | ||
from fixtures import _customer_factory, _insert_customer | ||
from fixtures import _project_factory |
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
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.