Skip to content

Commit

Permalink
feat: create tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Robso-creator committed Dec 13, 2024
1 parent 599ff0c commit 3831eaf
Show file tree
Hide file tree
Showing 14 changed files with 465 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""'main'
Revision ID: 1a7373ae8efd
Revision ID: 2610f232a617
Revises:
Create Date: 2024-12-13 16:33:21.659717
Create Date: 2024-12-13 19:46:08.295255
"""
from typing import Sequence
Expand All @@ -13,7 +13,7 @@


# revision identifiers, used by Alembic.
revision: str = '1a7373ae8efd'
revision: str = '2610f232a617'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
Expand Down
Empty file added tests/loader/__init__.py
Empty file.
36 changes: 36 additions & 0 deletions tests/loader/test_circulacao_viaria.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest
from unittest.mock import patch
import pandas as pd
from src.loader.circulacao_viaria import main


@pytest.fixture
def mock_s3():
with patch('src.loader.circulacao_viaria.S3') as MockS3:
mock_s3 = MockS3.return_value
yield mock_s3


@pytest.fixture
def mock_send_to_db():
with patch('src.loader.circulacao_viaria.send_to_db') as mock_send:
yield mock_send


def test_main(mock_s3, mock_send_to_db):
# Mocking S3 list_files method
mock_s3.list_files.return_value = (['path/to/file1.csv', 'path/to/file2.csv'], ['file1.csv', 'file2.csv'], None)

df_mock = pd.DataFrame({'col1': [1, 2], 'col2': ['a', 'b']})
mock_s3.read_to_df.return_value = df_mock

main()

mock_s3.list_files.assert_called_once_with(prefix='gold/circulacao-viaria-no-do-trecho')
assert mock_s3.read_to_df.call_count == 2
mock_send_to_db.assert_called_once()

called_df = mock_send_to_db.call_args[0][0]
assert called_df.shape == (4, 2)
assert called_df.columns.tolist() == ['col1', 'col2']

36 changes: 36 additions & 0 deletions tests/loader/test_estacionamento_idoso.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest
from unittest.mock import patch, MagicMock
import pandas as pd
from src.loader.estacionamento_rotativo_idoso import main


@pytest.fixture
def mock_s3():
with patch('src.loader.estacionamento_rotativo_idoso.S3') as MockS3:
mock_s3 = MockS3.return_value
yield mock_s3


@pytest.fixture
def mock_send_to_db():
with patch('src.loader.estacionamento_rotativo_idoso.send_to_db') as mock_send:
yield mock_send


def test_main(mock_s3, mock_send_to_db):
# Mocking S3 list_files method
mock_s3.list_files.return_value = (['path/to/file1.csv', 'path/to/file2.csv'], ['file1.csv', 'file2.csv'], None)

df_mock = pd.DataFrame({'col1': [1, 2], 'col2': ['a', 'b']})
mock_s3.read_to_df.return_value = df_mock

main()

mock_s3.list_files.assert_called_once_with(prefix='gold/estacionamento_idoso')
assert mock_s3.read_to_df.call_count == 2
mock_send_to_db.assert_called_once()

called_df = mock_send_to_db.call_args[0][0]
assert called_df.shape == (4, 2)
assert called_df.columns.tolist() == ['col1', 'col2']

36 changes: 36 additions & 0 deletions tests/loader/test_estacionamento_rotativo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest
from unittest.mock import patch
import pandas as pd
from src.loader.estacionamento_rotativo import main


@pytest.fixture
def mock_s3():
with patch('src.loader.estacionamento_rotativo.S3') as MockS3:
mock_s3 = MockS3.return_value
yield mock_s3


@pytest.fixture
def mock_send_to_db():
with patch('src.loader.estacionamento_rotativo.send_to_db') as mock_send:
yield mock_send


def test_main(mock_s3, mock_send_to_db):
# Mocking S3 list_files method
mock_s3.list_files.return_value = (['path/to/file1.csv', 'path/to/file2.csv'], ['file1.csv', 'file2.csv'], None)

df_mock = pd.DataFrame({'col1': [1, 2], 'col2': ['a', 'b']})
mock_s3.read_to_df.return_value = df_mock

main()

mock_s3.list_files.assert_called_once_with(prefix='gold/faces-de-quadras-regulamentadas-com-estacionamento-rotativo')
assert mock_s3.read_to_df.call_count == 2
mock_send_to_db.assert_called_once()

called_df = mock_send_to_db.call_args[0][0]
assert called_df.shape == (4, 2)
assert called_df.columns.tolist() == ['col1', 'col2']

36 changes: 36 additions & 0 deletions tests/loader/test_estacionamento_rotativo_motofrete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest
from unittest.mock import patch
import pandas as pd
from src.loader.estacionamento_rotativo_motofrete import main


@pytest.fixture
def mock_s3():
with patch('src.loader.estacionamento_rotativo_motofrete.S3') as MockS3:
mock_s3 = MockS3.return_value
yield mock_s3


@pytest.fixture
def mock_send_to_db():
with patch('src.loader.estacionamento_rotativo_motofrete.send_to_db') as mock_send:
yield mock_send


def test_main(mock_s3, mock_send_to_db):
# Mocking S3 list_files method
mock_s3.list_files.return_value = (['path/to/file1.csv', 'path/to/file2.csv'], ['file1.csv', 'file2.csv'], None)

df_mock = pd.DataFrame({'col1': [1, 2], 'col2': ['a', 'b']})
mock_s3.read_to_df.return_value = df_mock

main()

mock_s3.list_files.assert_called_once_with(prefix='gold/estacionamento-rotativo-para-motofrete')
assert mock_s3.read_to_df.call_count == 2
mock_send_to_db.assert_called_once()

called_df = mock_send_to_db.call_args[0][0]
assert called_df.shape == (4, 2)
assert called_df.columns.tolist() == ['col1', 'col2']

36 changes: 36 additions & 0 deletions tests/loader/test_logradouros_acidentes_transito_vitima.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest
from unittest.mock import patch
import pandas as pd
from src.loader.logradouros_acidentes_transito_vitima import main


@pytest.fixture
def mock_s3():
with patch('src.loader.logradouros_acidentes_transito_vitima.S3') as MockS3:
mock_s3 = MockS3.return_value
yield mock_s3


@pytest.fixture
def mock_send_to_db():
with patch('src.loader.logradouros_acidentes_transito_vitima.send_to_db') as mock_send:
yield mock_send


def test_main(mock_s3, mock_send_to_db):
# Mocking S3 list_files method
mock_s3.list_files.return_value = (['path/to/file1.csv', 'path/to/file2.csv'], ['file1.csv', 'file2.csv'], None)

df_mock = pd.DataFrame({'col1': [1, 2], 'col2': ['a', 'b']})
mock_s3.read_to_df.return_value = df_mock

main()

mock_s3.list_files.assert_called_once_with(prefix='gold/relacao-dos-logradouros-dos-locais-de-acidentes-de-transito-com-vitima')
assert mock_s3.read_to_df.call_count == 2
mock_send_to_db.assert_called_once()

called_df = mock_send_to_db.call_args[0][0]
assert called_df.shape == (4, 2)
assert called_df.columns.tolist() == ['col1', 'col2']

36 changes: 36 additions & 0 deletions tests/loader/test_ocorrencias_acidentes_transito_vitima.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest
from unittest.mock import patch
import pandas as pd
from src.loader.ocorrencias_acidentes_transito_vitima import main


@pytest.fixture
def mock_s3():
with patch('src.loader.ocorrencias_acidentes_transito_vitima.S3') as MockS3:
mock_s3 = MockS3.return_value
yield mock_s3


@pytest.fixture
def mock_send_to_db():
with patch('src.loader.ocorrencias_acidentes_transito_vitima.send_to_db') as mock_send:
yield mock_send


def test_main(mock_s3, mock_send_to_db):
# Mocking S3 list_files method
mock_s3.list_files.return_value = (['path/to/file1.csv', 'path/to/file2.csv'], ['file1.csv', 'file2.csv'], None)

df_mock = pd.DataFrame({'col1': [1, 2], 'col2': ['a', 'b']})
mock_s3.read_to_df.return_value = df_mock

main()

mock_s3.list_files.assert_called_once_with(prefix='gold/relacao-de-ocorrencias-de-acidentes-de-transito-com-vitima')
assert mock_s3.read_to_df.call_count == 2
mock_send_to_db.assert_called_once()

called_df = mock_send_to_db.call_args[0][0]
assert called_df.shape == (4, 2)
assert called_df.columns.tolist() == ['col1', 'col2']

36 changes: 36 additions & 0 deletions tests/loader/test_pessoas_acidentes_transito_vitima.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest
from unittest.mock import patch
import pandas as pd
from src.loader.pessoas_acidentes_transito_vitima import main


@pytest.fixture
def mock_s3():
with patch('src.loader.pessoas_acidentes_transito_vitima.S3') as MockS3:
mock_s3 = MockS3.return_value
yield mock_s3


@pytest.fixture
def mock_send_to_db():
with patch('src.loader.pessoas_acidentes_transito_vitima.send_to_db') as mock_send:
yield mock_send


def test_main(mock_s3, mock_send_to_db):
# Mocking S3 list_files method
mock_s3.list_files.return_value = (['path/to/file1.csv', 'path/to/file2.csv'], ['file1.csv', 'file2.csv'], None)

df_mock = pd.DataFrame({'col1': [1, 2], 'col2': ['a', 'b']})
mock_s3.read_to_df.return_value = df_mock

main()

mock_s3.list_files.assert_called_once_with(prefix='gold/relacao-das-pessoas-envolvidas-nos-acidentes-de-transito-com-vitima')
assert mock_s3.read_to_df.call_count == 2
mock_send_to_db.assert_called_once()

called_df = mock_send_to_db.call_args[0][0]
assert called_df.shape == (4, 2)
assert called_df.columns.tolist() == ['col1', 'col2']

36 changes: 36 additions & 0 deletions tests/loader/test_posto_venda_rotativo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest
from unittest.mock import patch
import pandas as pd
from src.loader.posto_venda_rotativo import main


@pytest.fixture
def mock_s3():
with patch('src.loader.posto_venda_rotativo.S3') as MockS3:
mock_s3 = MockS3.return_value
yield mock_s3


@pytest.fixture
def mock_send_to_db():
with patch('src.loader.posto_venda_rotativo.send_to_db') as mock_send:
yield mock_send


def test_main(mock_s3, mock_send_to_db):
# Mocking S3 list_files method
mock_s3.list_files.return_value = (['path/to/file1.csv', 'path/to/file2.csv'], ['file1.csv', 'file2.csv'], None)

df_mock = pd.DataFrame({'col1': [1, 2], 'col2': ['a', 'b']})
mock_s3.read_to_df.return_value = df_mock

main()

mock_s3.list_files.assert_called_once_with(prefix='gold/posto-de-venda-rotativo')
assert mock_s3.read_to_df.call_count == 2
mock_send_to_db.assert_called_once()

called_df = mock_send_to_db.call_args[0][0]
assert called_df.shape == (4, 2)
assert called_df.columns.tolist() == ['col1', 'col2']

36 changes: 36 additions & 0 deletions tests/loader/test_redutor_velocidade.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest
from unittest.mock import patch
import pandas as pd
from src.loader.redutor_velocidade import main


@pytest.fixture
def mock_s3():
with patch('src.loader.redutor_velocidade.S3') as MockS3:
mock_s3 = MockS3.return_value
yield mock_s3


@pytest.fixture
def mock_send_to_db():
with patch('src.loader.redutor_velocidade.send_to_db') as mock_send:
yield mock_send


def test_main(mock_s3, mock_send_to_db):
# Mocking S3 list_files method
mock_s3.list_files.return_value = (['path/to/file1.csv', 'path/to/file2.csv'], ['file1.csv', 'file2.csv'], None)

df_mock = pd.DataFrame({'col1': [1, 2], 'col2': ['a', 'b']})
mock_s3.read_to_df.return_value = df_mock

main()

mock_s3.list_files.assert_called_once_with(prefix='gold/redutor-de-velocidade')
assert mock_s3.read_to_df.call_count == 2
mock_send_to_db.assert_called_once()

called_df = mock_send_to_db.call_args[0][0]
assert called_df.shape == (4, 2)
assert called_df.columns.tolist() == ['col1', 'col2']

36 changes: 36 additions & 0 deletions tests/loader/test_sinalizacao_semaforica.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest
from unittest.mock import patch
import pandas as pd
from src.loader.sinalizacao_semaforica import main


@pytest.fixture
def mock_s3():
with patch('src.loader.sinalizacao_semaforica.S3') as MockS3:
mock_s3 = MockS3.return_value
yield mock_s3


@pytest.fixture
def mock_send_to_db():
with patch('src.loader.sinalizacao_semaforica.send_to_db') as mock_send:
yield mock_send


def test_main(mock_s3, mock_send_to_db):
# Mocking S3 list_files method
mock_s3.list_files.return_value = (['path/to/file1.csv', 'path/to/file2.csv'], ['file1.csv', 'file2.csv'], None)

df_mock = pd.DataFrame({'col1': [1, 2], 'col2': ['a', 'b']})
mock_s3.read_to_df.return_value = df_mock

main()

mock_s3.list_files.assert_called_once_with(prefix='gold/localizacao-das-sinalizacoes-semaforicas')
assert mock_s3.read_to_df.call_count == 2
mock_send_to_db.assert_called_once()

called_df = mock_send_to_db.call_args[0][0]
assert called_df.shape == (4, 2)
assert called_df.columns.tolist() == ['col1', 'col2']

Loading

0 comments on commit 3831eaf

Please sign in to comment.