diff --git a/Makefile b/Makefile index bf25858..e6bc7c3 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/apps/billing/services/invoice_host_service.py b/apps/billing/services/receipt_host_service.py similarity index 60% rename from apps/billing/services/invoice_host_service.py rename to apps/billing/services/receipt_host_service.py index f9f75c0..e211ab5 100644 --- a/apps/billing/services/invoice_host_service.py +++ b/apps/billing/services/receipt_host_service.py @@ -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) diff --git a/apps/billing/tests/test_invoice_host_service.py b/apps/billing/tests/test_invoice_host_service.py index cc4741f..938faa5 100644 --- a/apps/billing/tests/test_invoice_host_service.py +++ b/apps/billing/tests/test_invoice_host_service.py @@ -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): @@ -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) @@ -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) @@ -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) @@ -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"] @@ -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"] @@ -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) diff --git a/apps/billing/urls.py b/apps/billing/urls.py index ef944d6..d301ee8 100644 --- a/apps/billing/urls.py +++ b/apps/billing/urls.py @@ -9,8 +9,8 @@ name="transaction_complete", ), path( - "invoice-link//", - views.get_invoice_link, - name="get_invoice_link", + "receipt-link//", + views.get_receipt_link, + name="get_receipt_link", ), ] diff --git a/apps/billing/views.py b/apps/billing/views.py index 822f740..c8685a7 100644 --- a/apps/billing/views.py +++ b/apps/billing/views.py @@ -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 @@ -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//`. + This method is the endpoint method called through `receipt-link//`. """ try: @@ -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 diff --git a/nau_financial_manager/settings.py b/nau_financial_manager/settings.py index 29d6279..c99dcd1 100644 --- a/nau_financial_manager/settings.py +++ b/nau_financial_manager/settings.py @@ -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")