Skip to content

Commit

Permalink
refactor: rename invoice to receipt
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiago-da-silva23 committed Dec 12, 2023
1 parent b36889a commit 033f626
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ help:
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: help

test: ## run tests, all or a specific test, example: 'make test apps.billing.tests.test_invoice_host_service' or 'pytest apps/billing/tests/test_invoice_host_service.py -k test_get_document_transaction_not_found'
test: ## run tests, all or a specific test, example: 'make test apps.billing.tests.test_receipt_host_service' or 'pytest apps/billing/tests/test_receipt_host_service.py -k test_get_document_transaction_not_found'
@args="$(filter-out $@,$(MAKECMDGOALS))" && $(TEST_CMD) $${args:-${1}}
.PHONY: test

test-mysql: ## run tests, all or a specific test, example: 'make test apps.billing.tests.test_invoice_host_service' or 'pytest apps/billing/tests/test_invoice_host_service.py -k test_get_document_transaction_not_found'
test-mysql: ## run tests, all or a specific test, example: 'make test apps.billing.tests.test_receipt_host_service' or 'pytest apps/billing/tests/test_receipt_host_service.py -k test_get_document_transaction_not_found'
@args="$(filter-out $@,$(MAKECMDGOALS))" && $(TEST_MYSQL_CMD) $${args:-${1}}
.PHONY: test-mysql

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@
from django.conf import settings


class InvoiceDocumentHost:
class ReceiptDocumentHost:
def __init__(self) -> None:
self.__invoice_host_url = getattr(settings, "INVOICE_HOST_URL")
self.__invoice_host_auth = getattr(settings, "INVOICE_HOST_AUTH")
self.__invoice_host_password = getattr(settings, "INVOICE_HOST_PASSWORD")
self.__receipt_host_url = getattr(settings, "RECEIPT_HOST_URL")
self.__receipt_host_auth = getattr(settings, "RECEIPT_HOST_AUTH")
self.__receipt_host_password = getattr(settings, "RECEIPT_HOST_PASSWORD")

def get_document(self, document_id: str):
"""
This method gets the file url, it calls the invoice host giving the required parameters.
This method gets the file url, it calls the receipt host giving the required parameters.
document_id comes from the transaction. It is the returned id from the transaction processor.
__invoice_host_auth and __invoice_host_password is setted in the environment.
__receipt_host_auth and __receipt_host_password is setted in the environment.
"""

try:
response = requests.get(
url=f"{self.__invoice_host_url}/{document_id}",
url=f"{self.__receipt_host_url}/{document_id}",
auth=(
self.__invoice_host_auth,
self.__invoice_host_password,
self.__receipt_host_auth,
self.__receipt_host_password,
),
).content
response = json.JSONDecoder().decode(response)
Expand Down
26 changes: 13 additions & 13 deletions apps/billing/tests/test_invoice_host_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
from apps.billing.factories import TransactionFactory
from apps.billing.mocks import ILINK_RESPONSE_MOCK
from apps.billing.models import Transaction
from apps.billing.services.invoice_host_service import InvoiceDocumentHost
from apps.billing.services.receipt_host_service import ReceiptDocumentHost


class InvoiceDocumentHostForTest(InvoiceDocumentHost):
class ReceiptDocumentHostForTest(ReceiptDocumentHost):
def __init__(self) -> None:
self.__invoice_host_url = "https://invoice-fake.com/"
self.__invoice_host_auth = "test_auth"
self.__invoice_host_password = "pwd_test"
self.__receipt_host_url = "https://receipt-fake.com/"
self.__receipt_host_auth = "test_auth"
self.__receipt_host_password = "pwd_test"


class MockResponse(Response):
Expand All @@ -34,17 +34,17 @@ def mocked_get(*args, **kwargs):
return MockResponse(data=ILINK_RESPONSE_MOCK, status_code=200)


class InvoiceDocumentHostTest(TestCase):
class ReceiptDocumentHostTest(TestCase):
def setUp(self) -> None:
"""
This method starts the `InvoiceDocumentHostTest` compoment,
This method starts the `ReceiptDocumentHostTest` compoment,
setting the required parameters to excute the tests.
"""

user = get_user_model().objects.create(username="user_test", password="pwd_test")
self.token = Token.objects.create(user=user)
self.api_client = APIClient()
self.invoice_document_host = InvoiceDocumentHostForTest()
self.receipt_document_host = ReceiptDocumentHostForTest()
self.transaction: Transaction = TransactionFactory.create()

@mock.patch("requests.get", mocked_get)
Expand All @@ -57,7 +57,7 @@ def test_get_document_success(self):
self.api_client.credentials(HTTP_AUTHORIZATION=f"Token {self.token.key}")

link = ILINK_RESPONSE_MOCK["response"]["data"]["attachments"][0]["file"]
response = self.api_client.get(f"/api/billing/invoice-link/{self.transaction.transaction_id}/")
response = self.api_client.get(f"/api/billing/receipt-link/{self.transaction.transaction_id}/")
obtained_link = response.data["response"]

self.assertEqual(response.status_code, 200)
Expand All @@ -76,7 +76,7 @@ def test_get_document_transaction_not_found(self):

self.api_client.credentials(HTTP_AUTHORIZATION=f"Token {self.token.key}")

response = self.api_client.get("/api/billing/invoice-link/wrong-transaction-id/")
response = self.api_client.get("/api/billing/receipt-link/wrong-transaction-id/")
data = response.data["response"]

self.assertEqual(response.status_code, 404)
Expand All @@ -90,7 +90,7 @@ def test_get_document_authentication_not_provided(self):

self.api_client.credentials()

response = self.api_client.get("/api/billing/invoice-link/wrong-transaction-id/")
response = self.api_client.get("/api/billing/receipt-link/wrong-transaction-id/")
content = response.content.decode()
message = json.JSONDecoder().decode(s=content)
message = message["error"]["message"]["detail"]
Expand All @@ -106,7 +106,7 @@ def test_get_document_invalid_token(self):

self.api_client.credentials(HTTP_AUTHORIZATION=f"Token {self.token.key[:-3]}abc")

response = self.api_client.get("/api/billing/invoice-link/wrong-transaction-id/")
response = self.api_client.get("/api/billing/receipt-link/wrong-transaction-id/")
content = response.content.decode()
message = json.JSONDecoder().decode(s=content)
message = message["error"]["message"]["detail"]
Expand All @@ -121,6 +121,6 @@ def test_get_document_endpoint_not_found(self):

self.api_client.credentials(HTTP_AUTHORIZATION=f"Token {self.token.key[:-3]}abc")

response = self.api_client.get("/api/billing/invoice-link/")
response = self.api_client.get("/api/billing/receipt-link/")

self.assertEqual(response.status_code, 404)
6 changes: 3 additions & 3 deletions apps/billing/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
name="transaction_complete",
),
path(
"invoice-link/<str:transaction_id>/",
views.get_invoice_link,
name="get_invoice_link",
"receipt-link/<str:transaction_id>/",
views.get_receipt_link,
name="get_receipt_link",
),
]
10 changes: 5 additions & 5 deletions apps/billing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from apps.billing.models import Transaction
from apps.billing.serializers import ProcessTransactionSerializer
from apps.billing.services.invoice_host_service import InvoiceDocumentHost
from apps.billing.services.receipt_host_service import ReceiptDocumentHost
from apps.util.base_views import GeneralPost


Expand All @@ -19,9 +19,9 @@ class ProcessTransaction(APIView, GeneralPost):

@api_view(["GET"])
@authentication_classes([TokenAuthentication])
def get_invoice_link(request, *args, **kwargs):
def get_receipt_link(request, *args, **kwargs):
"""
This method is the endpoint method called through `invoice-link/<str:transaction_id>/`.
This method is the endpoint method called through `receipt-link/<str:transaction_id>/`.
"""

try:
Expand All @@ -34,8 +34,8 @@ def get_invoice_link(request, *args, **kwargs):
except ObjectDoesNotExist:
return Response({"response": "Trasaction not found"}, status=404)

invoice_link = InvoiceDocumentHost().get_document(document_id=transaction.document_id)
receipt_link = ReceiptDocumentHost().get_document(document_id=transaction.document_id)

return Response({"response": invoice_link}, status=200)
return Response({"response": receipt_link}, status=200)
except Exception as e:
raise e
8 changes: 4 additions & 4 deletions nau_financial_manager/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,10 @@ def get_env_setting(env_variable, default=None):
USER_PROCESSOR_AUTH = CONFIG.get("USER_PROCESSOR_AUTH", "")
USER_PROCESSOR_PASSWORD = CONFIG.get("USER_PROCESSOR_PASSWORD", "")

# Invoice host information
INVOICE_HOST_URL = CONFIG.get("INVOICE_HOST_URL", "")
INVOICE_HOST_AUTH = CONFIG.get("INVOICE_HOST_AUTH", "")
INVOICE_HOST_PASSWORD = CONFIG.get("INVOICE_HOST_PASSWORD", "")
# Receipt host information
RECEIPT_HOST_URL = CONFIG.get("RECEIPT_HOST_URL", "")
RECEIPT_HOST_AUTH = CONFIG.get("RECEIPT_HOST_AUTH", "")
RECEIPT_HOST_PASSWORD = CONFIG.get("RECEIPT_HOST_PASSWORD", "")

SWAGGER_PROJECT_NAME = CONFIG.get("SWAGGER_PROJECT_NAME", "Nau Financial Manager")
SWAGGER_PROJECT_VERSION = CONFIG.get("SWAGGER_PROJECT_VERSION", "1.0.0")
Expand Down

0 comments on commit 033f626

Please sign in to comment.