-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#56): Adição de testes unitários para diário
Foi implementado testes unitários para verificar o processamento de diários, extração de fornecedores e valores monetários. Esses testes asseguram que os dados estão sendo processados corretamente e que os fornecedores e valores estão no formato esperado.
- Loading branch information
1 parent
20ba4b7
commit 95a4ee6
Showing
7 changed files
with
104 additions
and
13 deletions.
There are no files selected for viewing
Empty file.
18 changes: 18 additions & 0 deletions
18
server/apps/diarios/migrations/0004_fornecedor_nome_fantasia.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,18 @@ | ||
# Generated by Django 4.1.13 on 2025-01-13 14:51 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('diarios', '0003_fornecedor'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='fornecedor', | ||
name='nome_fantasia', | ||
field=models.CharField(blank=True, max_length=255, null=True), | ||
), | ||
] |
17 changes: 17 additions & 0 deletions
17
server/apps/diarios/migrations/0005_remove_fornecedor_nome_fantasia.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,17 @@ | ||
# Generated by Django 4.1.13 on 2025-01-13 15:56 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('diarios', '0004_fornecedor_nome_fantasia'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='fornecedor', | ||
name='nome_fantasia', | ||
), | ||
] |
17 changes: 17 additions & 0 deletions
17
server/apps/diarios/migrations/0006_remove_fornecedor_ocorrencias.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,17 @@ | ||
# Generated by Django 4.1.13 on 2025-01-13 18:17 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('diarios', '0005_remove_fornecedor_nome_fantasia'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='fornecedor', | ||
name='ocorrencias', | ||
), | ||
] |
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
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
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,8 +1,51 @@ | ||
from django.test import TestCase | ||
from .models import Diario # Certifique-se de que o caminho para models está correto | ||
|
||
class DiarioTestCase(TestCase): | ||
def test_diarios_salvos(self): | ||
diarios = Diario.objects.all() # Recupera todos os registros | ||
for diario in diarios: | ||
print(diario.date, diario.url, diario.valor_final) | ||
import unittest | ||
from unittest.mock import patch, Mock | ||
from .services import processar_diarios, extrair_fornecedores, extrair_valores | ||
|
||
class TestDiarioServices(unittest.TestCase): | ||
@patch("apps.diarios.services.requests.get") | ||
def test_processar_diarios(self, mock_get): | ||
"""Testa o processamento de diários sem fazer requisições reais.""" | ||
# Mock da resposta do requests.get | ||
mock_response = Mock() | ||
mock_response.status_code = 200 | ||
mock_response.iter_content = lambda chunk_size: [b"Mocked content"] | ||
mock_get.return_value = mock_response | ||
|
||
diarios_mock = [{ | ||
"date": "2024-01-01", | ||
"url": "https://mock-url.com/diario.pdf", | ||
"txt_url": "https://mock-url.com/diario.txt", | ||
"edition": "Extraordinária", | ||
"is_extra_edition": True, | ||
"excerpts": "", | ||
}] | ||
|
||
resultados = processar_diarios(diarios_mock) | ||
|
||
# Testa se ao menos um diário foi processado | ||
self.assertGreater(len(resultados), 0) | ||
|
||
def test_extrair_fornecedores(self): | ||
"""Testa a extração básica de fornecedores.""" | ||
texto_mock = """ | ||
Fornecedor: Empresa A | ||
CNPJ: 00.000.000/0000-00 | ||
""" | ||
|
||
fornecedores = extrair_fornecedores(texto_mock) | ||
|
||
# Testa se ao menos um fornecedor foi extraído | ||
self.assertIn("00.000.000/0000-00", fornecedores) | ||
self.assertEqual(fornecedores["00.000.000/0000-00"]["nome"], "Empresa A") | ||
|
||
def test_extrair_valores(self): | ||
"""Testa a extração básica de valores monetários.""" | ||
texto_mock = "Valor total: R$ 1.000,00" | ||
valores = extrair_valores(texto_mock) | ||
|
||
# Testa se ao menos um valor foi extraído | ||
self.assertIn("R$ 1.000,00", valores) | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |