-
-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP][l10n_br_paulistana] Mock Tests
- Loading branch information
Showing
2 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 +1,2 @@ | ||
from . import test_fiscal_document_nfse_paulistana | ||
from . import test_webservices_nfse_paulistana |
158 changes: 158 additions & 0 deletions
158
l10n_br_nfse_paulistana/tests/test_webservices_nfse_paulistana.py
This file contains 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,158 @@ | ||
# Copyright 2024 KMEE INFORMATICA LTDA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from datetime import datetime | ||
from unittest.mock import patch | ||
|
||
from odoo.tests import common | ||
|
||
from odoo.addons.l10n_br_fiscal.constants.fiscal import ( | ||
MODELO_FISCAL_NFSE, | ||
PROCESSADOR_OCA, | ||
SITUACAO_EDOC_AUTORIZADA, | ||
SITUACAO_EDOC_REJEITADA, | ||
) | ||
|
||
|
||
class TestL10nBrNfsePaulistana(common.TransactionCase): | ||
"""Test class for Brazilian NFSe Paulistana integration.""" | ||
|
||
def setUp(self): | ||
"""Sets up test environment.""" | ||
super().setUp() | ||
self.company = self.env.ref("base.main_company") # Reference to main company | ||
self.company.provedor_nfse = "paulistana" # Setting NFSe provider to paulistana | ||
|
||
self.company.processador_edoc = PROCESSADOR_OCA | ||
self.company.partner_id.inscr_mun = "35174" | ||
self.company.partner_id.inscr_est = "" | ||
|
||
self.nfse_demo = self.env.ref( | ||
"l10n_br_fiscal.demo_nfse_same_state" | ||
) # NFSe demo document | ||
self.nfse_demo.document_number = "0001" # Setting document number | ||
self.nfse_demo.rps_number = "0002" # Setting RPS number | ||
self.nfse_demo.processador_edoc = ( | ||
PROCESSADOR_OCA | ||
) # Setting document processor to OCA | ||
self.nfse_demo.document_type_id.code = ( | ||
MODELO_FISCAL_NFSE # Setting document type to NFSe | ||
) | ||
self.nfse_demo.date_in_out = ( | ||
datetime.now() | ||
) # Setting a valid datetime for testing | ||
|
||
@patch("odoo.addons.l10n_br_nfse_focus.models.document.requests.request") | ||
def test_serialize_nfse_paulistana(self, mock_post): | ||
"""Tests serialization and processing of NFSe Paulistana.""" | ||
# Configuring mock to simulate a successful response | ||
mock_post.return_value.status_code = 200 # Simulating successful POST request | ||
mock_post.return_value.json.return_value = { | ||
"status": "sucesso" | ||
} # Mocking JSON response | ||
|
||
# Preparing document for serialization | ||
serialized_nfse = self.nfse_demo.serialize_nfse_paulistana() | ||
|
||
self.assertIsNotNone( | ||
serialized_nfse | ||
) # Asserting that serialization is not None | ||
self.assertEqual( | ||
serialized_nfse.Cabecalho.CPFCNPJRemetente.CNPJ, | ||
self.company.cnpj_cpf, | ||
"The serialized CNPJ should match the company's CNPJ", | ||
) | ||
|
||
@patch("odoo.addons.l10n_br_nfse_focus.models.document.requests.request") | ||
def test_processar_nfse_paulistana(self, mock_request): | ||
"""Tests NFSe Paulistana processing with mocked responses.""" | ||
# Configuring mock to simulate different HTTP responses | ||
mock_request.return_value.status_code = ( | ||
200 | ||
) # Simulating successful POST request | ||
mock_request.return_value.json.return_value = { | ||
"status": "success", | ||
"data": { | ||
"NumeroNFe": "00012345", | ||
"DataEmissaoRPS": "2024-01-01T00:00:00", | ||
"CodigoVerificacao": "123ABC", | ||
}, | ||
} | ||
|
||
# Setting a valid datetime for the document before processing | ||
self.nfse_demo.document_date = datetime.now() | ||
|
||
# Testing NFSe processing | ||
self.nfse_demo._eletronic_document_send() # Sending the electronic document | ||
|
||
# Verifying if the document status has changed to authorized | ||
self.assertEqual( | ||
self.nfse_demo.state, | ||
SITUACAO_EDOC_AUTORIZADA, | ||
"The document state should be updated to 'authorized'", | ||
) | ||
self.assertEqual( | ||
self.nfse_demo.document_number, | ||
"00012345", | ||
"The document number should match the returned value from the provider", | ||
) | ||
self.assertEqual( | ||
self.nfse_demo.verify_code, | ||
"123ABC", | ||
"The verification code should match the returned value from the provider", | ||
) | ||
|
||
@patch("odoo.addons.l10n_br_nfse_focus.models.document.requests.request") | ||
def test_cancela_documento_paulistana(self, mock_delete): | ||
"""Tests edoc cancellation for NFSe Paulistana with mocked DELETE request.""" | ||
# Configuring mock to simulate a successful cancellation response | ||
mock_delete.return_value.status_code = 200 | ||
mock_delete.return_value.json.return_value = {"status": "cancelado"} | ||
|
||
# Setting the document to be in an authorized state | ||
self.nfse_demo.state = SITUACAO_EDOC_AUTORIZADA | ||
self.nfse_demo.document_number = "00012345" | ||
self.nfse_demo.verify_code = "123ABC" | ||
|
||
# Attempting to cancel the document | ||
result = self.nfse_demo.cancel_document_paulistana() | ||
|
||
# Asserting that cancellation was successful | ||
self.assertTrue(result, "The cancellation should be successful.") | ||
self.assertEqual( | ||
self.nfse_demo.state, | ||
SITUACAO_EDOC_REJEITADA, | ||
"The document state should be updated to 'rejected' after cancellation", | ||
) | ||
|
||
@patch("odoo.addons.l10n_br_nfse_focus.models.document.requests.request") | ||
def test_document_status_paulistana(self, mock_get): | ||
"""Tests querying edoc status for NFSe Paulistana with mocked GET request.""" | ||
# Configuring mock to simulate a successful status query response | ||
mock_get.return_value.status_code = 200 | ||
mock_get.return_value.json.return_value = { | ||
"status": "success", | ||
"data": { | ||
"NumeroNFe": "00012345", | ||
"DataEmissaoRPS": "2024-01-01T00:00:00", | ||
"CodigoVerificacao": "123ABC", | ||
}, | ||
} | ||
|
||
# Setting a valid datetime for the document before querying status | ||
self.nfse_demo.document_date = datetime.now() | ||
|
||
# Querying the status of the NFSe | ||
status = self.nfse_demo._document_status() | ||
|
||
# Asserting that the status query was successful | ||
self.assertEqual( | ||
status, | ||
"Procesado com Sucesso", | ||
"The document status should be 'Processed with Success'", | ||
) | ||
self.assertEqual( | ||
self.nfse_demo.state, | ||
SITUACAO_EDOC_AUTORIZADA, | ||
"The document state should be updated to 'authorized'", | ||
) |