|
17 | 17 |
|
18 | 18 | response_confirmacao_operacao_rejeicao = """<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><nfeResultMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NFeRecepcaoEvento4"><retEnvEvento xmlns="http://www.portalfiscal.inf.br/nfe" versao="1.00"><idLote /><tpAmb>2</tpAmb><verAplic>SVRS202305251555</verAplic><cStat>494</cStat><retEvento versao="1.00"><infEvento><tpAmb>2</tpAmb><verAplic>SVRS202305251555</verAplic><cStat>494</cStat><xMotivo>Rejeição: Chave de Acesso inexistente</xMotivo><chNFe>31201010588201000105550010038421171838422178</chNFe><tpEvento>210200</tpEvento><xEvento>Confirmacao de Operacao registrada</xEvento><nSeqEvento>1</nSeqEvento><CNPJDest>81583054000129</CNPJDest><dhRegEvento>2023-07-10T10:00:00-03:00</dhRegEvento></infEvento></retEvento></retEnvEvento></nfeResultMsg></soap:Body></soap:Envelope>""" # noqa: E501
|
19 | 19 |
|
| 20 | +response_ciencia_operacao = """<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><nfeResultMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NFeRecepcaoEvento4"><retEnvEvento xmlns="http://www.portalfiscal.inf.br/nfe" versao="1.00"><idLote /><tpAmb>2</tpAmb><verAplic>SVRS202305251555</verAplic><cStat>135</cStat><retEvento versao="1.00"><infEvento><tpAmb>2</tpAmb><verAplic>SVRS202305251555</verAplic><cStat>135</cStat><xMotivo>Teste Ciência da Operação.</xMotivo><chNFe>31201010588201000105550010038421171838422178</chNFe><tpEvento>210210</tpEvento><xEvento>Ciencia da Operacao registrada</xEvento><nSeqEvento>1</nSeqEvento><CNPJDest>81583054000129</CNPJDest><dhRegEvento>2023-07-10T10:00:00-03:00</dhRegEvento></infEvento></retEvento></retEnvEvento></nfeResultMsg></soap:Body></soap:Envelope>""" # noqa: E501 |
| 21 | + |
| 22 | +response_desconhecimento_operacao = """<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><nfeResultMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NFeRecepcaoEvento4"><retEnvEvento xmlns="http://www.portalfiscal.inf.br/nfe" versao="1.00"><idLote /><tpAmb>2</tpAmb><verAplic>SVRS202305251555</verAplic><cStat>135</cStat><retEvento versao="1.00"><infEvento><tpAmb>2</tpAmb><verAplic>SVRS202305251555</verAplic><cStat>135</cStat><xMotivo>Teste Desconhecimento da Operação.</xMotivo><chNFe>31201010588201000105550010038421171838422178</chNFe><tpEvento>210220</tpEvento><xEvento>Desconhecimento da Operacao registrada</xEvento><nSeqEvento>1</nSeqEvento><CNPJDest>81583054000129</CNPJDest><dhRegEvento>2023-07-10T10:00:00-03:00</dhRegEvento></infEvento></retEvento></retEnvEvento></nfeResultMsg></soap:Body></soap:Envelope>""" # noqa: E501 |
| 23 | + |
| 24 | +response_operacao_nao_realizada = """<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><nfeResultMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NFeRecepcaoEvento4"><retEnvEvento xmlns="http://www.portalfiscal.inf.br/nfe" versao="1.00"><idLote /><tpAmb>2</tpAmb><verAplic>SVRS202305251555</verAplic><cStat>135</cStat><retEvento versao="1.00"><infEvento><tpAmb>2</tpAmb><verAplic>SVRS202305251555</verAplic><cStat>135</cStat><xMotivo>Teste Operação não Realizada.</xMotivo><chNFe>31201010588201000105550010038421171838422178</chNFe><tpEvento>210240</tpEvento><xEvento>Operacao nao Realizada registrada</xEvento><nSeqEvento>1</nSeqEvento><CNPJDest>81583054000129</CNPJDest><dhRegEvento>2023-07-10T10:00:00-03:00</dhRegEvento></infEvento></retEvento></retEnvEvento></nfeResultMsg></soap:Body></soap:Envelope>""" # noqa: E501 |
| 25 | + |
20 | 26 |
|
21 | 27 | class FakeRetorno:
|
22 | 28 | def __init__(self, text, status_code=200):
|
@@ -58,6 +64,36 @@ def mocked_post_confirmacao_invalid_status_error(*args, **kwargs):
|
58 | 64 | )
|
59 | 65 |
|
60 | 66 |
|
| 67 | +def mocked_post_ciencia(*args, **kwargs): |
| 68 | + return analisar_retorno_raw( |
| 69 | + "nfeRecepcaoEvento", |
| 70 | + object(), |
| 71 | + b"<fake_post/>", |
| 72 | + FakeRetorno(response_ciencia_operacao), |
| 73 | + retEnvEvento, |
| 74 | + ) |
| 75 | + |
| 76 | + |
| 77 | +def mocked_post_desconhecimento(*args, **kwargs): |
| 78 | + return analisar_retorno_raw( |
| 79 | + "nfeRecepcaoEvento", |
| 80 | + object(), |
| 81 | + b"<fake_post/>", |
| 82 | + FakeRetorno(response_desconhecimento_operacao), |
| 83 | + retEnvEvento, |
| 84 | + ) |
| 85 | + |
| 86 | + |
| 87 | +def mocked_post_nao_realizada(*args, **kwargs): |
| 88 | + return analisar_retorno_raw( |
| 89 | + "nfeRecepcaoEvento", |
| 90 | + object(), |
| 91 | + b"<fake_post/>", |
| 92 | + FakeRetorno(response_operacao_nao_realizada), |
| 93 | + retEnvEvento, |
| 94 | + ) |
| 95 | + |
| 96 | + |
61 | 97 | class TestMDe(TransactionCase):
|
62 | 98 | @classmethod
|
63 | 99 | def setUpClass(cls):
|
@@ -95,15 +131,42 @@ def test_events_success(self):
|
95 | 131 | with mock.patch.object(
|
96 | 132 | DocumentoElectronicoAdapter,
|
97 | 133 | "_post",
|
98 |
| - side_effect=mocked_post_confirmacao, |
| 134 | + side_effect=mocked_post_ciencia, |
99 | 135 | ):
|
100 |
| - self.mde_id.event_type_selection = "confirmado" |
| 136 | + self.mde_id.event_type_selection = "ciente" |
101 | 137 | self.mde_id.action_confirm_selection()
|
102 |
| - self.assertEqual(self.mde_id.event_type, "confirmado") |
| 138 | + self.assertEqual(self.mde_id.event_type, "ciente") |
103 | 139 | self.assertEqual(
|
104 | 140 | self.mde_id.display_name, "31201010588201000105550010038421171838422178"
|
105 | 141 | )
|
106 | 142 |
|
| 143 | + with mock.patch.object( |
| 144 | + DocumentoElectronicoAdapter, |
| 145 | + "_post", |
| 146 | + side_effect=mocked_post_confirmacao, |
| 147 | + ): |
| 148 | + self.mde_id.event_type_selection = "confirmado" |
| 149 | + self.mde_id.action_confirm_selection() |
| 150 | + self.assertEqual(self.mde_id.event_type, "confirmado") |
| 151 | + |
| 152 | + with mock.patch.object( |
| 153 | + DocumentoElectronicoAdapter, |
| 154 | + "_post", |
| 155 | + side_effect=mocked_post_desconhecimento, |
| 156 | + ): |
| 157 | + self.mde_id.event_type_selection = "desconhecido" |
| 158 | + self.mde_id.action_confirm_selection() |
| 159 | + self.assertEqual(self.mde_id.event_type, "desconhecido") |
| 160 | + |
| 161 | + with mock.patch.object( |
| 162 | + DocumentoElectronicoAdapter, |
| 163 | + "_post", |
| 164 | + side_effect=mocked_post_nao_realizada, |
| 165 | + ): |
| 166 | + self.mde_id.event_type_selection = "nao_realizado" |
| 167 | + self.mde_id.action_confirm_selection() |
| 168 | + self.assertEqual(self.mde_id.event_type, "nao_realizado") |
| 169 | + |
107 | 170 | def test_event_error(self):
|
108 | 171 | with mock.patch.object(
|
109 | 172 | DocumentoElectronicoAdapter,
|
|
0 commit comments