Skip to content

Unit tests for issue #90 #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat: added tests for formatos xml
Signed-off-by: HanslettTheDev <[email protected]>
HanslettTheDev committed Nov 3, 2023

Verified

This commit was signed with the committer’s verified signature.
commit d0c23db26171305c86f0d47097d612c6d90c5438
Empty file removed output.txt
Empty file.
61 changes: 58 additions & 3 deletions tests/test_formatos_xml.py
Original file line number Diff line number Diff line change
@@ -18,9 +18,64 @@


import pytest
from pyafipws.formatos.formato_xml import leer, escribir

import os
from pyafipws.formatos.formato_xml import (mapear, leer, desserializar,
escribir, serializar
)
import tempfile

pytestmark = [pytest.mark.dontusefix]


@pytest.fixture
def xml_file():
# Create a temporary file with XML content
xml_content = """
<?xml version="1.0" encoding="UTF-8"?>
<comprobantes>
<comprobante>
<tipo>1</tipo>
</comprobante>
</comprobantes>
""".strip()
with tempfile.NamedTemporaryFile(mode="w", delete=False) as f:
f.write(xml_content)
file_path = f.name

yield file_path

os.remove(file_path)


def test_mapear():
# Mapping with default behavior
old = {"tipo_cbte": 1, "punto_vta": 2, "cbt_numero": 3}
new = mapear({}, old, {"tipo": "tipo_cbte", "ptovta": "punto_vta", "numero": "cbt_numero"})
assert new == {"tipo": 1, "ptovta": 2, "numero": 3}

# Mapping with swap=True
old = {"tipo_cbte": 1, "punto_vta": 2, "cbt_numero": 3}
new = mapear({}, old, {"tipo_cbte": "tipo", "punto_vta": "ptovta", "cbt_numero": "numero"}, swap=True)
assert {'tipo': 1, 'ptovta': 2, 'numero': 3}

# Mapping with missing value
old = {"tipo_cbte": 1, "punto_vta": 2}
new = mapear({}, old, {"tipo": "tipo_cbte", "ptovta": "punto_vta", "numero": "cbt_numero"})
assert new == {"tipo": 1, "ptovta": 2, "numero": None}

# Mapping with empty dictionary
old = {}
new = mapear({}, old, {"tipo": "tipo_cbte", "ptovta": "punto_vta", "numero": "cbt_numero"})
assert new == {"tipo": None, "ptovta": None, "numero": None}


def test_desserializar():
# Test case 1: Valid XML string
xml = "<comprobantes><comprobante><tipo>1</tipo></comprobante></comprobantes>"
with pytest.raises(KeyError):
result = desserializar(xml)

# with Invalid XML string
xml = "<comprobantes><comprobante><tipo>1</tipo></comprobante>"
with pytest.raises(Exception):
result = desserializar(xml)