| """Testes dos geradores de arquivos SPED e XML fiscal.""" |
| import pytest |
| import re |
| from datetime import date |
| from decimal import Decimal |
| from pathlib import Path |
|
|
| from src.fiscal.entities import ( |
| Contato, |
| Empresa, |
| Endereco, |
| ItemNotaFiscal, |
| LancamentoContabil, |
| NotaFiscal, |
| PeriodoApuracao, |
| Produto, |
| RegimeTributario, |
| TipoEmpresa, |
| UF, |
| ) |
| from src.generators.sped_writer import ArquivoSPED, RegistroSPED, criar_registro |
| from src.generators.efd_icms_ipi import GeradorEFDICMSIPI |
| from src.generators.efd_contribuicoes import GeradorEFDContribuicoes |
| from src.generators.ecd import GeradorECD, PlanoContas |
| from src.generators.ecf import DadosLucroPresumido, DadosLucroReal, GeradorECF |
| from src.generators.nfe_xml import GeradorNFeXML |
| from src.generators.efd_reinf import ( |
| EventoR2010, |
| GeradorEFDReinf, |
| PrestadorServico, |
| ) |
| from src.generators.esocial import ( |
| GeradorESocial, |
| Trabalhador, |
| VinculoEmpregaticio, |
| FolhaPagamento, |
| ItemFolha, |
| RUBRICAS_PADRAO, |
| ) |
| from src.generators.dctf import DebitoDCTF, GeradorDCTF, ItemDCTF, montar_dctf_do_periodo |
| from src.generators.cte import GeradorCTe, CargaCTe, ParteCTe, DadosTransporte, DocumentoReferenciado |
| from src.generators.nfce_xml import GeradorNFCeXML, ConsumidorNFCe |
| from src.generators.mdfe import GeradorMDFe, MunicipioDescarga, DocumentoMDFe, ConductorMDFe, SeguroMDFe |
| from src.generators.dirf import GeradorDIRF, BeneficiarioDIRF, ResponsavelDIRF |
| from src.generators.defis import GeradorDEFIS, ReceitaMensalDEFIS, SocioDEFIS |
| from src.generators.destda import GeradorDeSTDA, OperacaoSTDeSTDA |
| from src.generators.gia import GeradorGIA, ApuracaoGIA, ApuracaoGIAST |
|
|
|
|
| |
| |
| |
|
|
| @pytest.fixture |
| def empresa_sp(): |
| return Empresa( |
| cnpj="11222333000181", |
| razao_social="EMPRESA TESTE LTDA", |
| nome_fantasia="TESTE", |
| ie="111111111111", |
| regime_tributario=RegimeTributario.LUCRO_PRESUMIDO, |
| tipo_empresa=TipoEmpresa.COMERCIO, |
| endereco=Endereco( |
| logradouro="Av. Paulista", |
| numero="1000", |
| bairro="Bela Vista", |
| municipio="São Paulo", |
| uf=UF.SP, |
| cep="01310100", |
| cod_municipio="3550308", |
| ), |
| contato=Contato(telefone="1133334444", email="teste@teste.com"), |
| ) |
|
|
|
|
| @pytest.fixture |
| def cliente_sp(): |
| return Empresa( |
| cnpj="22333444000181", |
| razao_social="CLIENTE TESTE SA", |
| regime_tributario=RegimeTributario.LUCRO_PRESUMIDO, |
| tipo_empresa=TipoEmpresa.COMERCIO, |
| endereco=Endereco( |
| logradouro="Rua das Flores", |
| numero="100", |
| bairro="Centro", |
| municipio="Campinas", |
| uf=UF.SP, |
| cep="13010050", |
| cod_municipio="3509502", |
| ), |
| ) |
|
|
|
|
| @pytest.fixture |
| def produto_padrao(): |
| return Produto( |
| codigo="PROD001", |
| descricao="PRODUTO TESTE", |
| ncm="84713012", |
| unidade="UN", |
| aliq_icms=Decimal("18"), |
| aliq_ipi=Decimal("5"), |
| cst_icms="000", |
| cst_ipi="50", |
| cst_pis="01", |
| cst_cofins="01", |
| ) |
|
|
|
|
| @pytest.fixture |
| def nota_fiscal(empresa_sp, cliente_sp, produto_padrao): |
| item = ItemNotaFiscal( |
| numero_item=1, |
| produto=produto_padrao, |
| cfop="5102", |
| quantidade=Decimal("10"), |
| valor_unitario=Decimal("100.00"), |
| ) |
| return NotaFiscal( |
| numero="000001", |
| serie="001", |
| data_emissao=date(2024, 1, 15), |
| data_saida_entrada=date(2024, 1, 15), |
| emitente=empresa_sp, |
| destinatario=cliente_sp, |
| natureza_operacao="VENDA DE MERCADORIA", |
| itens=[item], |
| chave_acesso="35240111222333000181550010000000011000000015", |
| ) |
|
|
|
|
| @pytest.fixture |
| def periodo(empresa_sp, nota_fiscal): |
| return PeriodoApuracao( |
| data_inicio=date(2024, 1, 1), |
| data_fim=date(2024, 1, 31), |
| empresa=empresa_sp, |
| notas_saida=[nota_fiscal], |
| ) |
|
|
|
|
| |
| |
| |
|
|
| class TestSpedWriter: |
|
|
| def test_criar_registro_formato_pipe(self): |
| linha = criar_registro("C100", "1", "0", "12345678") |
| assert linha.startswith("|C100|") |
| assert linha.endswith("|\n") |
|
|
| def test_criar_registro_data(self): |
| linha = criar_registro("0000", date(2024, 1, 1)) |
| assert "01012024" in linha |
|
|
| def test_criar_registro_decimal(self): |
| linha = criar_registro("E110", Decimal("1234.56")) |
| assert "1234,56" in linha |
|
|
| def test_criar_registro_none_vazio(self): |
| linha = criar_registro("X001", None, "") |
| parts = linha.strip("|").split("|") |
| assert parts[1] == "" |
| assert parts[2] == "" |
|
|
| def test_arquivo_sped_contagem_linhas(self): |
| arq = ArquivoSPED("teste.txt") |
| arq.adicionar_linha_raw(criar_registro("0000", "017")) |
| arq.adicionar_linha_raw(criar_registro("0001", "0")) |
| assert arq.total_linhas() == 2 |
|
|
| def test_registro_sped_builder(self): |
| reg = RegistroSPED("C100") |
| reg.add("1").add("0").add("12345678000195") |
| linha = reg.to_line() |
| assert "|C100|1|0|12345678000195|" in linha |
|
|
|
|
| |
| |
| |
|
|
| class TestEFDICMSIPI: |
|
|
| def test_gera_arquivo_existente(self, periodo, tmp_path): |
| gerador = GeradorEFDICMSIPI(periodo) |
| caminho = gerador.gerar(tmp_path) |
| assert caminho.exists() |
| assert caminho.stat().st_size > 0 |
|
|
| def test_registro_0000_presente(self, periodo, tmp_path): |
| gerador = GeradorEFDICMSIPI(periodo) |
| caminho = gerador.gerar(tmp_path) |
| conteudo = caminho.read_text() |
| assert "|0000|" in conteudo |
|
|
| def test_cnpj_no_registro_0000(self, periodo, tmp_path): |
| gerador = GeradorEFDICMSIPI(periodo) |
| caminho = gerador.gerar(tmp_path) |
| conteudo = caminho.read_text() |
| assert "11222333000181" in conteudo |
|
|
| def test_registro_c100_presente(self, periodo, tmp_path): |
| gerador = GeradorEFDICMSIPI(periodo) |
| caminho = gerador.gerar(tmp_path) |
| conteudo = caminho.read_text() |
| assert "|C100|" in conteudo |
|
|
| def test_registro_e110_presente(self, periodo, tmp_path): |
| gerador = GeradorEFDICMSIPI(periodo) |
| caminho = gerador.gerar(tmp_path) |
| conteudo = caminho.read_text() |
| assert "|E110|" in conteudo |
|
|
| def test_registro_9999_presente(self, periodo, tmp_path): |
| gerador = GeradorEFDICMSIPI(periodo) |
| caminho = gerador.gerar(tmp_path) |
| conteudo = caminho.read_text() |
| assert "|9999|" in conteudo |
|
|
| def test_todas_linhas_sao_pipe_delimited(self, periodo, tmp_path): |
| gerador = GeradorEFDICMSIPI(periodo) |
| caminho = gerador.gerar(tmp_path) |
| for linha in caminho.read_text().splitlines(): |
| assert linha.startswith("|") and linha.endswith("|"), f"Linha inválida: {linha}" |
|
|
| def test_nome_arquivo_correto(self, periodo): |
| gerador = GeradorEFDICMSIPI(periodo) |
| assert "11222333000181" in gerador._arquivo.nome_arquivo |
| assert "202401" in gerador._arquivo.nome_arquivo |
|
|
|
|
| |
| |
| |
|
|
| class TestEFDContribuicoes: |
|
|
| def test_gera_arquivo(self, periodo, tmp_path): |
| gerador = GeradorEFDContribuicoes(periodo) |
| caminho = gerador.gerar(tmp_path) |
| assert caminho.exists() |
|
|
| def test_registro_m200_presente(self, periodo, tmp_path): |
| gerador = GeradorEFDContribuicoes(periodo) |
| caminho = gerador.gerar(tmp_path) |
| assert "|M200|" in caminho.read_text() |
|
|
| def test_registro_m600_presente(self, periodo, tmp_path): |
| gerador = GeradorEFDContribuicoes(periodo) |
| caminho = gerador.gerar(tmp_path) |
| assert "|M600|" in caminho.read_text() |
|
|
|
|
| |
| |
| |
|
|
| class TestECD: |
|
|
| def test_gera_arquivo(self, periodo, tmp_path): |
| gerador = GeradorECD(periodo) |
| caminho = gerador.gerar(tmp_path) |
| assert caminho.exists() |
| assert caminho.stat().st_size > 100 |
|
|
| def test_plano_contas_no_arquivo(self, periodo, tmp_path): |
| gerador = GeradorECD(periodo) |
| caminho = gerador.gerar(tmp_path) |
| assert "|I050|" in caminho.read_text() |
|
|
| def test_registro_i001_presente(self, periodo, tmp_path): |
| gerador = GeradorECD(periodo) |
| caminho = gerador.gerar(tmp_path) |
| assert "|I001|" in caminho.read_text() |
|
|
| def test_lancamentos_contabeis(self, periodo, empresa_sp, tmp_path): |
| periodo.lancamentos = [ |
| LancamentoContabil( |
| data=date(2024, 1, 5), |
| numero_lancamento="000001", |
| historico="Venda de mercadorias", |
| debito_conta="1.1.2.01", |
| credito_conta="4.1.01", |
| valor=Decimal("1000.00"), |
| ) |
| ] |
| gerador = GeradorECD(periodo) |
| caminho = gerador.gerar(tmp_path) |
| assert "|I200|" in caminho.read_text() |
| assert "|I250|" in caminho.read_text() |
|
|
| def test_plano_contas_customizado(self, periodo, tmp_path): |
| plano = [ |
| PlanoContas("1", "ATIVO", 1, "S", "D"), |
| PlanoContas("1.01", "CAIXA", 2, "A", "D"), |
| ] |
| gerador = GeradorECD(periodo, plano_contas=plano) |
| caminho = gerador.gerar(tmp_path) |
| assert "CAIXA" in caminho.read_text() |
|
|
|
|
| |
| |
| |
|
|
| class TestECF: |
|
|
| def test_gera_ecf_lucro_presumido(self, empresa_sp, tmp_path): |
| dados = DadosLucroPresumido( |
| receita_venda_mercadorias=Decimal("500000"), |
| receita_prestacao_servicos=Decimal("100000"), |
| ) |
| gerador = GeradorECF(empresa_sp, 2023, dados_lp=dados) |
| caminho = gerador.gerar(tmp_path) |
| assert caminho.exists() |
|
|
| def test_registro_0000_ecf(self, empresa_sp, tmp_path): |
| dados = DadosLucroPresumido(receita_venda_mercadorias=Decimal("100000")) |
| gerador = GeradorECF(empresa_sp, 2023, dados_lp=dados) |
| caminho = gerador.gerar(tmp_path) |
| assert "|0000|" in caminho.read_text() |
|
|
| def test_gera_ecf_lucro_real(self, tmp_path): |
| empresa = Empresa( |
| cnpj="11222333000181", |
| razao_social="EMPRESA LR LTDA", |
| regime_tributario=RegimeTributario.LUCRO_REAL, |
| tipo_empresa=TipoEmpresa.COMERCIO, |
| endereco=Endereco( |
| logradouro="Rua X", numero="1", bairro="B", |
| municipio="SP", uf=UF.SP, cep="01310100", |
| ), |
| ) |
| dados = DadosLucroReal( |
| lucro_contabil=Decimal("200000"), |
| adicoes=Decimal("10000"), |
| exclusoes=Decimal("5000"), |
| ) |
| gerador = GeradorECF(empresa, 2023, dados_lr=dados) |
| caminho = gerador.gerar(tmp_path) |
| assert "|L020|" in caminho.read_text() |
|
|
|
|
| |
| |
| |
|
|
| class TestNFeXML: |
|
|
| def test_gera_xml_valido(self, nota_fiscal, tmp_path): |
| gerador = GeradorNFeXML(nota_fiscal) |
| xml = gerador.gerar_xml() |
| assert xml.startswith("<?xml") |
| assert "<NFe" in xml |
| assert "<infNFe" in xml |
|
|
| def test_xml_contem_cnpj(self, nota_fiscal): |
| gerador = GeradorNFeXML(nota_fiscal) |
| xml = gerador.gerar_xml() |
| assert "11222333000181" in xml |
|
|
| def test_xml_contem_valor_total(self, nota_fiscal): |
| gerador = GeradorNFeXML(nota_fiscal) |
| xml = gerador.gerar_xml() |
| |
| assert "1000.00" in xml or "1050.00" in xml |
|
|
| def test_xml_contem_imposto(self, nota_fiscal): |
| gerador = GeradorNFeXML(nota_fiscal) |
| xml = gerador.gerar_xml() |
| assert "<ICMS>" in xml |
| assert "<IPI>" in xml or "<IPITrib>" in xml |
|
|
| def test_chave_acesso_44_digitos(self, nota_fiscal): |
| gerador = GeradorNFeXML(nota_fiscal) |
| chave = gerador._gerar_chave() |
| assert len(chave) == 44 |
| assert chave.isdigit() |
|
|
| def test_salva_arquivo_xml(self, nota_fiscal, tmp_path): |
| gerador = GeradorNFeXML(nota_fiscal) |
| caminho = gerador.salvar(tmp_path) |
| assert caminho.exists() |
| assert caminho.suffix == ".xml" |
|
|
|
|
| |
| |
| |
|
|
| class TestEFDReinf: |
|
|
| def test_gera_r2010(self): |
| gerador = GeradorEFDReinf("11222333000181") |
| evt = EventoR2010( |
| cnpj_tomador="11222333000181", |
| periodo="2024-01", |
| prestadores=[ |
| PrestadorServico( |
| cnpj_cpf="22333444000181", |
| nome="PRESTADOR TESTE", |
| valor_bruto=Decimal("10000"), |
| valor_bc_csll=Decimal("10000"), |
| valor_bc_irrf=Decimal("10000"), |
| valor_bc_pis=Decimal("10000"), |
| valor_bc_cofins=Decimal("10000"), |
| ) |
| ], |
| ) |
| xml = gerador.gerar_r2010(evt) |
| assert "evtServTom" in xml |
| assert "22333444000181" in xml |
|
|
| def test_gera_r2099(self): |
| gerador = GeradorEFDReinf("11222333000181") |
| xml = gerador.gerar_r2099("2024-01") |
| assert "evtFechamento" in xml |
|
|
| def test_salva_eventos(self, tmp_path): |
| gerador = GeradorEFDReinf("11222333000181") |
| arquivos = gerador.salvar_eventos(tmp_path, periodo="2024-01") |
| assert len(arquivos) >= 2 |
| assert all(a.exists() for a in arquivos) |
|
|
|
|
| |
| |
| |
|
|
| class TestESocial: |
|
|
| def test_gera_s2200_admissao(self): |
| gerador = GeradorESocial("11222333000181") |
| trab = Trabalhador( |
| cpf="12345678909", |
| nome="JOAO DA SILVA", |
| data_nascimento=date(1985, 3, 15), |
| ) |
| vinculo = VinculoEmpregaticio( |
| trabalhador=trab, |
| matricula="001", |
| data_admissao=date(2024, 1, 2), |
| salario_base=Decimal("3000"), |
| ) |
| xml = gerador.gerar_s2200(vinculo) |
| assert "evtAdmissao" in xml |
| assert "JOAO DA SILVA" in xml |
|
|
| def test_gera_s1200_folha(self): |
| gerador = GeradorESocial("11222333000181") |
| trab = Trabalhador(cpf="12345678909", nome="MARIA SOUZA", data_nascimento=date(1990, 6, 20)) |
| rubrica = RUBRICAS_PADRAO[0] |
| folha = FolhaPagamento( |
| trabalhador=trab, |
| matricula="002", |
| periodo="2024-01", |
| itens=[ItemFolha(rubrica=rubrica, valor=Decimal("3000"))], |
| base_cp=Decimal("3000"), |
| base_fgts=Decimal("3000"), |
| valor_fgts=Decimal("240"), |
| ) |
| xml = gerador.gerar_s1200(folha) |
| assert "evtRemun" in xml |
| assert "3000.00" in xml |
|
|
| def test_gera_s1299_fechamento(self): |
| gerador = GeradorESocial("11222333000181") |
| xml = gerador.gerar_s1299("2024-01") |
| assert "evtFechamento" in xml |
|
|
|
|
| |
| |
| |
|
|
| class TestDCTF: |
|
|
| def test_gera_xml_dctf(self, empresa_sp, tmp_path): |
| item = ItemDCTF(debito=DebitoDCTF( |
| codigo_receita="2089", |
| periodo_apuracao="2024-01", |
| valor_debito=Decimal("5000"), |
| )) |
| gerador = GeradorDCTF(empresa_sp, "2024-01", [item]) |
| xml = gerador.gerar_xml() |
| assert "<DCTF" in xml |
| assert "2089" in xml |
| assert "5000.00" in xml |
|
|
| def test_salva_arquivo(self, empresa_sp, tmp_path): |
| gerador = GeradorDCTF(empresa_sp, "2024-01") |
| caminho = gerador.salvar(tmp_path) |
| assert caminho.exists() |
|
|
| def test_saldo_a_pagar(self, empresa_sp): |
| from src.generators.dctf import PagamentoDCTF |
| item = ItemDCTF( |
| debito=DebitoDCTF("6912", "2024-01", Decimal("10000")), |
| pagamentos=[PagamentoDCTF("12345", date(2024, 2, 15), Decimal("7000"))], |
| ) |
| assert item.saldo_a_pagar == Decimal("3000.00") |
| assert item.total_pago == Decimal("7000.00") |
|
|
| def test_montar_dctf_do_periodo(self, empresa_sp): |
| gen = montar_dctf_do_periodo( |
| empresa=empresa_sp, |
| periodo="2024-01", |
| valor_irpj=Decimal("3000"), |
| valor_csll=Decimal("1200"), |
| valor_pis=Decimal("650"), |
| valor_cofins=Decimal("3000"), |
| ) |
| assert len(gen.itens) == 4 |
| xml = gen.gerar_xml() |
| assert "3000.00" in xml |
|
|
| def test_relatorio_resumo(self, empresa_sp): |
| item = ItemDCTF(debito=DebitoDCTF("8109", "2024-01", Decimal("1000"))) |
| gerador = GeradorDCTF(empresa_sp, "2024-01", [item]) |
| relatorio = gerador.relatorio_resumo() |
| assert "8109" in relatorio |
| assert "1,000.00" in relatorio |
|
|
|
|
| |
| |
| |
|
|
| class TestCTe: |
| @pytest.fixture |
| def gerador_cte(self, empresa_sp): |
| remetente = ParteCTe("11222333000181", "REMETENTE LTDA", "Rua A, 1", "São Paulo", "SP", "01310100", "3550308") |
| destinatario = ParteCTe("22333444000181", "DESTINATÁRIO SA", "Av B, 2", "Campinas", "SP", "13010050", "3509502") |
| carga = CargaCTe("ELETRONICOS", "84", Decimal("50000"), peso_kg=Decimal("500")) |
| transporte = DadosTransporte("12345678", "ABC1234", "SP", date(2024, 2, 1)) |
| docs = [DocumentoReferenciado("35240111222333000181550010000000011000000015")] |
| return GeradorCTe(empresa_sp, remetente, destinatario, carga, docs, transporte) |
|
|
| def test_gera_xml_valido(self, gerador_cte): |
| xml = gerador_cte.gerar_xml() |
| assert "<?xml" in xml |
| assert "CTe" in xml or "infCte" in xml |
|
|
| def test_chave_44_digitos(self, gerador_cte): |
| chave = gerador_cte._gerar_chave() |
| assert len(chave) == 44 |
| assert chave.isdigit() |
|
|
| def test_modelo_57(self, gerador_cte): |
| xml = gerador_cte.gerar_xml() |
| assert "57" in xml |
|
|
| def test_salva_arquivo(self, gerador_cte, tmp_path): |
| caminho = gerador_cte.salvar(tmp_path) |
| assert caminho.exists() |
| assert caminho.suffix == ".xml" |
|
|
|
|
| |
| |
| |
|
|
| class TestNFCe: |
| @pytest.fixture |
| def gerador_nfce(self, empresa_sp, produto_padrao): |
| from src.fiscal.entities import ItemNotaFiscal |
| item = ItemNotaFiscal(numero_item=1, produto=produto_padrao, cfop="5102", |
| quantidade=Decimal("2"), valor_unitario=Decimal("100")) |
| consumidor = ConsumidorNFCe(cpf="", nome="CONSUMIDOR") |
| return GeradorNFCeXML(empresa_sp, [item], consumidor=consumidor) |
|
|
| def test_gera_xml_valido(self, gerador_nfce): |
| xml = gerador_nfce.gerar_xml() |
| assert "<?xml" in xml |
|
|
| def test_modelo_65(self, gerador_nfce): |
| xml = gerador_nfce.gerar_xml() |
| assert "65" in xml |
|
|
| def test_chave_44_digitos(self, gerador_nfce): |
| chave = gerador_nfce._gerar_chave() |
| assert len(chave) == 44 |
|
|
| def test_salva_arquivo(self, gerador_nfce, tmp_path): |
| caminho = gerador_nfce.salvar(tmp_path) |
| assert caminho.exists() |
|
|
|
|
| |
| |
| |
|
|
| class TestMDFe: |
| @pytest.fixture |
| def gerador_mdfe(self, empresa_sp): |
| docs = [DocumentoMDFe("35240111222333000181550010000000011000000015", "NFe")] |
| municipios = [MunicipioDescarga("3509502", "Campinas", "SP", docs)] |
| condutores = [ConductorMDFe("João Silva", "12345678901")] |
| seguro = SeguroMDFe("1", "11222333000181", "SEGURADORA SA", "APL001", ["1"]) |
| return GeradorMDFe(empresa_sp, municipios, condutores, seguro, |
| "SP", "SP", "ABC1234", "SP", "12345678") |
|
|
| def test_gera_xml_valido(self, gerador_mdfe): |
| xml = gerador_mdfe.gerar_xml() |
| assert "<?xml" in xml |
| assert "MDF" in xml or "infMDFe" in xml |
|
|
| def test_modelo_58(self, gerador_mdfe): |
| xml = gerador_mdfe.gerar_xml() |
| assert "58" in xml |
|
|
| def test_chave_44_digitos(self, gerador_mdfe): |
| chave = gerador_mdfe._gerar_chave() |
| assert len(chave) == 44 |
|
|
| def test_salva_arquivo(self, gerador_mdfe, tmp_path): |
| caminho = gerador_mdfe.salvar(tmp_path) |
| assert caminho.exists() |
|
|
|
|
| |
| |
| |
|
|
| class TestDIRF: |
| @pytest.fixture |
| def gerador_dirf(self, empresa_sp): |
| responsavel = ResponsavelDIRF("12345678901", "CONTADOR", "CONTADOR", "11", "33334444") |
| beneficiarios = [ |
| BeneficiarioDIRF( |
| cpf_cnpj="98765432100", |
| nome="FUNCIONÁRIO TESTE", |
| tipo="PF", |
| cod_receita="0561", |
| rendimentos_por_mes={1: Decimal("5000"), 2: Decimal("5000")}, |
| ir_retido_por_mes={1: Decimal("250"), 2: Decimal("250")}, |
| ) |
| ] |
| return GeradorDIRF(empresa_sp, 2024, beneficiarios, responsavel) |
|
|
| def test_gera_txt(self, gerador_dirf): |
| txt = gerador_dirf.gerar_txt() |
| assert "DIRF" in txt |
| assert "BPFDEC" in txt or "DECPJ" in txt |
|
|
| def test_contem_cnpj(self, gerador_dirf): |
| txt = gerador_dirf.gerar_txt() |
| assert "11222333000181" in txt |
|
|
| def test_contem_rendimento(self, gerador_dirf): |
| txt = gerador_dirf.gerar_txt() |
| assert "5000" in txt |
|
|
| def test_salva_arquivo(self, gerador_dirf, tmp_path): |
| caminho = gerador_dirf.salvar(tmp_path) |
| assert caminho.exists() |
| assert caminho.suffix == ".txt" |
|
|
|
|
| |
| |
| |
|
|
| class TestDEFIS: |
| @pytest.fixture |
| def gerador_defis(self, empresa_sp): |
| receitas = [ReceitaMensalDEFIS(mes=m, receita_bruta_total=Decimal("10000")) for m in range(1, 13)] |
| socios = [SocioDEFIS("12345678901", "SÓCIO TESTE", Decimal("100"))] |
| return GeradorDEFIS(empresa_sp, 2024, receitas, socios) |
|
|
| def test_gera_xml_valido(self, gerador_defis): |
| xml = gerador_defis.gerar_xml() |
| assert "<?xml" in xml |
| assert "DEFIS" in xml |
|
|
| def test_contem_cnpj(self, gerador_defis): |
| xml = gerador_defis.gerar_xml() |
| assert "11222333000181" in xml |
|
|
| def test_total_anual(self, gerador_defis): |
| xml = gerador_defis.gerar_xml() |
| assert "120000.00" in xml |
|
|
| def test_socio_presente(self, gerador_defis): |
| xml = gerador_defis.gerar_xml() |
| assert "SÓCIO TESTE" in xml or "100.00" in xml |
|
|
| def test_salva_arquivo(self, gerador_defis, tmp_path): |
| caminho = gerador_defis.salvar(tmp_path) |
| assert caminho.exists() |
|
|
|
|
| |
| |
| |
|
|
| class TestDeSTDA: |
| @pytest.fixture |
| def gerador_destda(self, empresa_sp): |
| ops = [ |
| OperacaoSTDeSTDA("SP", "RJ", "ST", Decimal("10000"), Decimal("18"), Decimal("1800")), |
| OperacaoSTDeSTDA("SP", "MG", "DIFAL", Decimal("5000"), Decimal("6"), Decimal("300")), |
| ] |
| return GeradorDeSTDA(empresa_sp, "2024-01", ops) |
|
|
| def test_gera_xml_valido(self, gerador_destda): |
| xml = gerador_destda.gerar_xml() |
| assert "<?xml" in xml |
| assert "DeSTDA" in xml |
|
|
| def test_totais_corretos(self, gerador_destda): |
| xml = gerador_destda.gerar_xml() |
| assert "1800.00" in xml |
| assert "300.00" in xml |
|
|
| def test_data_vencimento(self, gerador_destda): |
| venc = gerador_destda.data_vencimento() |
| assert venc.day == 20 |
| assert venc.month == 2 |
|
|
| def test_relatorio_resumo(self, gerador_destda): |
| rel = gerador_destda.relatorio_resumo() |
| assert "1,800.00" in rel or "1800" in rel |
|
|
| def test_salva_arquivo(self, gerador_destda, tmp_path): |
| caminho = gerador_destda.salvar(tmp_path) |
| assert caminho.exists() |
|
|
|
|
| |
| |
| |
|
|
| class TestGIA: |
| @pytest.fixture |
| def gerador_gia(self, empresa_sp): |
| apuracao = ApuracaoGIA( |
| debitos_operacoes_proprias=Decimal("50000"), |
| creditos_entradas=Decimal("30000"), |
| ) |
| st = ApuracaoGIAST("MG", Decimal("20000"), Decimal("12"), Decimal("2400")) |
| return GeradorGIA(empresa_sp, "2024-01", apuracao, [st]) |
|
|
| def test_gera_aie(self, gerador_gia): |
| aie = gerador_gia.gerar_aie() |
| assert "|GIA|" in aie |
| assert "|APURACAO_ICMS|" in aie |
|
|
| def test_icms_a_recolher(self, gerador_gia): |
| assert gerador_gia.icms_a_recolher == Decimal("20000") |
|
|
| def test_gia_st_presente(self, gerador_gia): |
| aie = gerador_gia.gerar_aie() |
| assert "|GIA_ST|" in aie |
| assert "MG" in aie |
|
|
| def test_encerramento_com_hash(self, gerador_gia): |
| aie = gerador_gia.gerar_aie() |
| assert "|ENCERRAMENTO|" in aie |
|
|
| def test_salva_arquivo(self, gerador_gia, tmp_path): |
| caminho = gerador_gia.salvar(tmp_path) |
| assert caminho.exists() |
| assert caminho.suffix == ".aie" |
|
|
|
|
| |
| |
| |
|
|
| class TestEFDICMSIPIBlocosGK: |
| def test_bloco_g_presente(self, periodo, tmp_path): |
| gen = GeradorEFDICMSIPI(periodo) |
| caminho = gen.gerar(tmp_path) |
| conteudo = caminho.read_text() |
| assert "|G001|" in conteudo |
| assert "|G990|" in conteudo |
|
|
| def test_bloco_k_presente(self, periodo, tmp_path): |
| gen = GeradorEFDICMSIPI(periodo) |
| caminho = gen.gerar(tmp_path) |
| conteudo = caminho.read_text() |
| assert "|K001|" in conteudo |
| assert "|K990|" in conteudo |
|
|