Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements/time_tracker_api/dev.txt
pip install -r requirements/time_tracker_events/dev.txt

- name: Login to azure
uses: Azure/login@v1
with:
Expand Down Expand Up @@ -54,7 +53,6 @@ jobs:
AZURE_STORAGE_ACCOUNT_KEY: ${{ steps.timeTrackerAzureVault.outputs.AZURE-STORAGE-ACCOUNT-KEY }}
run: |
pytest tests

- name: Test the build of the app
run: |
docker build .
docker build .
4 changes: 1 addition & 3 deletions .github/workflows/time-tracker-v1-on-push-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements/time_tracker_api/dev.txt
pip install -r requirements/time_tracker_events/dev.txt

- name: Login to azure
uses: Azure/login@v1
with:
Expand Down Expand Up @@ -54,7 +53,6 @@ jobs:
AZURE_STORAGE_ACCOUNT_KEY: ${{ steps.timeTrackerAzureVault.outputs.AZURE-STORAGE-ACCOUNT-KEY }}
run: |
pytest tests

- name: Login to docker registry
uses: azure/docker-login@v1
with:
Expand All @@ -64,4 +62,4 @@ jobs:
- name: Build and push image
run: |
docker build . -t ${{ secrets.REGISTRY_LOGIN_SERVER }}/timetrackerapi:${{ github.sha }}
docker push ${{ secrets.REGISTRY_LOGIN_SERVER }}/timetrackerapi:${{ github.sha }}
docker push ${{ secrets.REGISTRY_LOGIN_SERVER }}/timetrackerapi:${{ github.sha }}
51 changes: 51 additions & 0 deletions V2/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ package:
- "!.gitignore"
- "!.git/**"

#region start Functions

functions:

#region Start Functions Activities

get_activities:
handler: time_tracker/activities/interface.get_activities
events:
Expand Down Expand Up @@ -77,6 +82,10 @@ functions:
route: activities/
authLevel: anonymous

#endregion End Functions Activities

#region Start Functions Time-Entries

create_time_entry:
handler: time_tracker/time_entries/interface.create_time_entry
events:
Expand Down Expand Up @@ -117,6 +126,10 @@ functions:
route: time-entries/{id}
authLevel: anonymous

#endregion End Functions Time-Entries

#region Start Functions Customers

create_customer:
handler: time_tracker/customers/interface.create_customer
events:
Expand All @@ -127,6 +140,40 @@ functions:
route: customers/
authLevel: anonymous

get_customers:
handler: time_tracker/customers/interface.get_customers
events:
- http: true
x-azure-settings:
methods:
- GET
route: customers/{id:?}
authLevel: anonymous

update_customer:
handler: time_tracker/customers/interface.update_customer
events:
- http: true
x-azure-settings:
methods:
- PUT
route: customers/{id}
authLevel: anonymous

delete_customer:
handler: time_tracker/customers/interface.delete_customer
events:
- http: true
x-azure-settings:
methods:
- DELETE
route: customers/{id}
authLevel: anonymous

#endregion End Functions Customers

#region Start Functions Projects

get_projects:
handler: time_tracker/projects/interface.get_projects
events:
Expand Down Expand Up @@ -166,3 +213,7 @@ functions:
- POST
route: projects/
authLevel: anonymous

#endregion End Functions Projects

#endregion End Functions
173 changes: 169 additions & 4 deletions V2/tests/api/azure/customer_azure_endpoints_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from http import HTTPStatus
import json
from faker import Faker

Expand All @@ -8,7 +9,7 @@
CUSTOMER_URL = "/api/customers/"


def test__customer_azure_endpoint__creates_a_customer__when_customer_has_all_necesary_attributes(
def test__create_customer_azure_endpoint__creates_a_customer__when_customer_has_all_necesary_attributes(
customer_factory
):
customer_body = customer_factory().__dict__
Expand All @@ -24,11 +25,11 @@ def test__customer_azure_endpoint__creates_a_customer__when_customer_has_all_nec
customer_json_data = json.loads(response.get_body())
customer_body['id'] = customer_json_data['id']

assert response.status_code == 201
assert response.status_code == HTTPStatus.CREATED
assert customer_json_data == customer_body


def test__customer_azure_endpoint__returns_a_status_400__when_dont_recieve_all_necessary_attributes():
def test__create_customer_azure_endpoint__returns_a_status_400__when_dont_recieve_all_necessary_attributes():
customer_to_insert = {
"id": None,
"name": Faker().user_name(),
Expand All @@ -45,5 +46,169 @@ def test__customer_azure_endpoint__returns_a_status_400__when_dont_recieve_all_n

response = azure_customers._create_customer.create_customer(req)

assert response.status_code == 400
assert response.status_code == HTTPStatus.BAD_REQUEST
assert response.get_body() == b'Invalid format or structure of the attributes of the customer'


def test__delete_customer_azure_endpoint__returns_a_customer_with_true_deleted__when_its_id_is_found(
test_db, customer_factory, insert_customer
):
customer_preinsert = customer_factory()
inserted_customer = insert_customer(customer_preinsert, test_db).__dict__

req = func.HttpRequest(
method='DELETE',
body=None,
url=CUSTOMER_URL,
route_params={"id": inserted_customer["id"]},
)

response = azure_customers._delete_customer.delete_customer(req)
customer_json_data = json.loads(response.get_body().decode("utf-8"))

assert response.status_code == HTTPStatus.OK
assert customer_json_data['deleted'] is True


def test__delete_customer_azure_endpoint__returns_not_found__when_its_id_is_not_found():
req = func.HttpRequest(
method='DELETE',
body=None,
url=CUSTOMER_URL,
route_params={"id": Faker().pyint()},
)

response = azure_customers._delete_customer.delete_customer(req)

assert response.status_code == HTTPStatus.NOT_FOUND
assert response.get_body() == b'Not found'


def test__update_customer_azure_endpoint__returns_an_updated_customer__when_customer_has_all_necesary_attributes(
test_db, customer_factory, insert_customer
):
existent_customer = customer_factory()
inserted_customer = insert_customer(existent_customer, test_db).__dict__

inserted_customer["description"] = Faker().sentence()

body = json.dumps(inserted_customer).encode("utf-8")
req = func.HttpRequest(
method='PUT',
body=body,
url=CUSTOMER_URL,
route_params={"id": inserted_customer["id"]},
)

response = azure_customers._update_customer.update_customer(req)
customer_json_data = json.loads(response.get_body())

assert response.status_code == HTTPStatus.OK
assert customer_json_data == inserted_customer


def test__update_customer_azure_endpoint__returns_update_a_customer__when_customer_has_all_necesary_attributes(
customer_factory
):
existent_customer = customer_factory().__dict__

body = json.dumps(existent_customer).encode("utf-8")
req = func.HttpRequest(
method='PUT',
body=body,
url=CUSTOMER_URL,
route_params={"id": Faker().pyint()},
)

response = azure_customers._update_customer.update_customer(req)

assert response.status_code == HTTPStatus.CONFLICT
assert response.get_body() == b'This customer does not exist or is duplicated'


def test__update_customer_azure_endpoint__returns_invalid_format__when_customer_doesnt_have_all_necesary_attributes(
customer_factory, insert_customer, test_db
):
existent_customer = customer_factory()
inserted_customer = insert_customer(existent_customer, test_db).__dict__

inserted_customer.pop("name")

body = json.dumps(inserted_customer).encode("utf-8")
req = func.HttpRequest(
method='PUT',
body=body,
url=CUSTOMER_URL,
route_params={"id": inserted_customer["id"]},
)

response = azure_customers._update_customer.update_customer(req)

assert response.status_code == HTTPStatus.BAD_REQUEST
assert response.get_body() == b'Invalid format or structure of the attributes of the customer'


def test__delete_customers_azure_endpoint__returns_a_status_code_400__when_customer_recive_invalid_id(
):
req = func.HttpRequest(
method="DELETE",
body=None,
url=CUSTOMER_URL,
route_params={"id": "invalid id"},
)

response = azure_customers._delete_customer.delete_customer(req)

assert response.status_code == HTTPStatus.BAD_REQUEST
assert response.get_body() == b'Invalid Format ID'


def test__customers_azure_endpoint__returns_all_customers(
test_db, customer_factory, insert_customer
):
customer_to_insert = customer_factory()

inserted_customer = insert_customer(customer_to_insert, test_db).__dict__

req = func.HttpRequest(method='GET', body=None, url=CUSTOMER_URL)
response = azure_customers._get_customers.get_customers(req)
customers_json_data = response.get_body().decode("utf-8")
customer_list = json.loads(customers_json_data)

assert response.status_code == HTTPStatus.OK
assert customers_json_data <= json.dumps(inserted_customer)
assert customer_list.pop() == inserted_customer


def test__customer_azure_endpoint__returns_a_customer__when_customer_matches_its_id(
test_db, customer_factory, insert_customer
):
existent_customer = customer_factory()
inserted_customer = insert_customer(existent_customer, test_db).__dict__

req = func.HttpRequest(
method='GET',
body=None,
url=CUSTOMER_URL,
route_params={"id": inserted_customer["id"]},
)

response = azure_customers._get_customers.get_customers(req)
customer_json_data = response.get_body().decode("utf-8")

assert response.status_code == HTTPStatus.OK
assert customer_json_data == json.dumps(inserted_customer)


def test__customer_azure_endpoint__returns_invalid_id__when_customer_not_matches_its_id():
req = func.HttpRequest(
method='GET',
body=None,
url=CUSTOMER_URL,
route_params={"id": "Invalid ID"},
)

response = azure_customers._get_customers.get_customers(req)

assert response.status_code == HTTPStatus.BAD_REQUEST
assert response.get_body() == b'The id has an invalid format'
2 changes: 1 addition & 1 deletion V2/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from faker import Faker

import time_tracker.activities._domain as activities_domain
import time_tracker.activities._infrastructure as activities_infrastructure
import time_tracker.time_entries._domain as time_entries_domain
import time_tracker.customers._domain as customers_domain
import time_tracker.activities._infrastructure as activities_infrastructure
import time_tracker.customers._infrastructure as customers_infrastructure
import time_tracker.projects._domain as projects_domain
from time_tracker._infrastructure import DB
Expand Down
Loading