Skip to content

Commit

Permalink
fix: sonarcloud issues
Browse files Browse the repository at this point in the history
  • Loading branch information
felixrodrigo19 committed Dec 11, 2024
1 parent aaae103 commit 9dc57f5
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 9 deletions.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-install-project --no-dev

COPY . /app
COPY ./mock-payment-server /app/mock-payment-server
COPY ./src /app/src
COPY ./pyproject.toml /app
COPY ./uv.lock /app

RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev
Expand Down
1 change: 0 additions & 1 deletion mock-payment-server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ async def set_webhook(

@app.post("/user-payment")
async def user_paymeny(paymeny_info: Payment):
result = "error"
if paymeny_info.user_amount > paymeny_info.total_sale_amount:
result = "ok"
else:
Expand Down
2 changes: 1 addition & 1 deletion src/client/domain/validators/user_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _first_and_last_name_validator(user):
def _cpf_validator(user):
if not user.cpf or not user.cpf.strip():
raise ClientDomainException("CPF não pode ser vazio")
if re.match(r"[0-9]{11}", user.cpf) is None:
if re.match(r"\d{11}", user.cpf) is None:
raise ClientDomainException("CPF inválido")

@staticmethod
Expand Down
3 changes: 2 additions & 1 deletion tests/cart/test_order.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import math
from datetime import datetime

import pytest
Expand Down Expand Up @@ -30,7 +31,7 @@ def test_order_creation_valid():
quantity=2)]
)
assert order.id is not None
assert order.total_order == 100.0
assert math.isclose(order.total_order, 100.0 - 0.1, rel_tol=1e-09, abs_tol=1e-09)
assert order.order_status == OrderStatus.PENDENTE
assert order.payment_condition == PaymentConditions.PIX

Expand Down
2 changes: 1 addition & 1 deletion tests/client/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_user_valid():
cpf="66007637018",
email="[email protected]",
password="12345678")
assert result is not None
assert result
assert result.cpf == "66007637018"
assert result.email == "[email protected]"
assert result.password == "12345678"
Expand Down
9 changes: 6 additions & 3 deletions tests/product/adapters/test_product_gateway.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import math
from dataclasses import dataclass

from src.product.domain.entities.product import Product
Expand All @@ -15,15 +16,17 @@ class ProductDto:

def test_get_products(gateway, mock_uow):
mock_uow.repository.get_all.return_value = [
ProductDto(**{'id': 1, 'sku': 'sku1', 'description': 'desc1', 'category': 'Bebida', 'price': 100.0, 'stock': 10}),
ProductDto(**{'id': 2, 'sku': 'sku2', 'description': 'desc2', 'category': 'Sobremesa', 'price': 200.0, 'stock': 20})
ProductDto(
**{'id': 1, 'sku': 'sku1', 'description': 'desc1', 'category': 'Bebida', 'price': 100.0, 'stock': 10}),
ProductDto(
**{'id': 2, 'sku': 'sku2', 'description': 'desc2', 'category': 'Sobremesa', 'price': 200.0, 'stock': 20})
]

products = gateway.get_products()

assert len(products) == 2
assert products[0].sku == 'sku1'
assert products[1].price == 200.0
assert math.isclose(products[1].price, 200.0 - 0.1, rel_tol=1e-09, abs_tol=1e-09)
mock_uow.repository.get_all.assert_called_once()


Expand Down
3 changes: 3 additions & 0 deletions tests/product/in_memory_uow.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ def __init__(self, repository: IProductRepository):
self._committed = False

def __enter__(self):
# Not implemented
pass

def __exit__(self, *args):
# Not implemented
pass

def commit(self):
self._committed = True

def rollback(self):
# Not implemented
pass
2 changes: 1 addition & 1 deletion tests/product/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_valid_product():
category="Lanche",
stock=100,
price=10.0)
assert result is not None
assert result
assert result.description == "Darth Burger"
assert result.category == "Lanche"
assert result.stock == 100
Expand Down

0 comments on commit 9dc57f5

Please sign in to comment.