55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
from os import name
|
|
import shutil
|
|
import pytest
|
|
from modules.copier import copiar_ficheiros_para_destino
|
|
from modules.organizer import categorizar_por_tipo, obter_data_ficheiro
|
|
|
|
|
|
@pytest.fixture
|
|
def ficheiro_teste(tmp_path):
|
|
ficheiro = tmp_path / "teste.txt"
|
|
ficheiro.write_text("conteudo de teste")
|
|
return ficheiro
|
|
|
|
|
|
def test_copiar_ficheiros_para_destino_simples(tmp_path, ficheiro_teste):
|
|
destino = tmp_path / "destino"
|
|
destino.mkdir()
|
|
|
|
copiar_ficheiros_para_destino([str(ficheiro_teste)], str(destino))
|
|
|
|
# verificar se foi copiado para a pasta 'outros'
|
|
ficheiro_copiado = destino / "outros" / ficheiro_teste.name
|
|
assert ficheiro_copiado.exists()
|
|
assert ficheiro_copiado.read_text() == "conteudo de teste"
|
|
|
|
|
|
def test_copiar_ficheiros_para_destino_com_data_modificacao(tmp_path, ficheiro_teste):
|
|
destino = tmp_path / "destino"
|
|
destino.mkdir()
|
|
|
|
copiar_ficheiros_para_destino(
|
|
[str(ficheiro_teste)],
|
|
str(destino),
|
|
categorizar_data=True,
|
|
usar_criacao=False,
|
|
formato_data="%Y-%m-%d",
|
|
)
|
|
|
|
categoria = categorizar_por_tipo(str(ficheiro_teste))
|
|
data_dir = obter_data_ficheiro(
|
|
str(ficheiro_teste), False).strftime("%Y-%m-%d")
|
|
ficheiro_copiado = destino / categoria / data_dir / ficheiro_teste.name
|
|
|
|
assert ficheiro_copiado.exists()
|
|
assert ficheiro_copiado.read_text() == "conteudo de teste"
|
|
|
|
|
|
def test_copiar_ficheiros_para_destino_lista_ficheiros_vazia(tmp_path):
|
|
destino = tmp_path / "destino"
|
|
destino.mkdir()
|
|
|
|
copiar_ficheiros_para_destino([], str(destino))
|
|
# verifica se a pasta de destino ficou vazia
|
|
assert list(destino.glob("*")) == []
|