mirror of
https://github.com/gmbrax/Pilgrim.git
synced 2026-11-10 09:30:17 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ca0b8c554c | ||
|
|
8119ae74f6 |
+10
-6
@@ -2,8 +2,9 @@
|
|||||||
requires = ["hatchling"]
|
requires = ["hatchling"]
|
||||||
build-backend = "hatchling.build"
|
build-backend = "hatchling.build"
|
||||||
|
|
||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "pilgrim"
|
name = "Pilgrim"
|
||||||
version = "0.0.4"
|
version = "0.0.4"
|
||||||
authors = [
|
authors = [
|
||||||
{ name="Gustavo Henrique Santos Souza de Miranda", email="gustavohssmiranda@gmail.com" }
|
{ name="Gustavo Henrique Santos Souza de Miranda", email="gustavohssmiranda@gmail.com" }
|
||||||
@@ -20,13 +21,16 @@ dependencies = [
|
|||||||
"sqlalchemy",
|
"sqlalchemy",
|
||||||
"textual",
|
"textual",
|
||||||
"tomli",
|
"tomli",
|
||||||
"tomli_w",
|
"tomli_w"
|
||||||
"unidecode"
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
|
]
|
||||||
|
[template.plugins.default]
|
||||||
|
src-layout = true
|
||||||
[project.urls]
|
[project.urls]
|
||||||
Homepage = "https://github.com/gmbrax/Pilgrim/"
|
Homepage = "https://github.com/gmbrax/Pilgrim/"
|
||||||
Issues = "https://github.com/gmbrax/Pilgrim/issues"
|
Issues = "https://github.com/gmbrax/Pilgrim/issues"
|
||||||
|
[tool.hatch.build.targets.wheel]
|
||||||
|
packages = ["src/pilgrim"]
|
||||||
[project.scripts]
|
[project.scripts]
|
||||||
pilgrim = "pilgrim.command:main"
|
pilgrim = "pilgrim:main"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.orm import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import os
|
import os
|
||||||
|
|||||||
@@ -4,16 +4,15 @@ from pilgrim.models.photo_in_entry import photo_entry_association
|
|||||||
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime
|
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
|
|
||||||
from pilgrim.database import Base
|
from ..database import Base
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Entry(Base):
|
class Entry(Base):
|
||||||
__tablename__ = "entries"
|
__tablename__ = "entries"
|
||||||
id = Column(Integer, primary_key=True)
|
id = Column(Integer, primary_key=True)
|
||||||
title = Column(String,nullable=False)
|
title = Column(String)
|
||||||
text = Column(String)
|
text = Column(String)
|
||||||
date = Column(DateTime,nullable=False)
|
date = Column(DateTime)
|
||||||
photos = relationship(
|
photos = relationship(
|
||||||
"Photo",
|
"Photo",
|
||||||
secondary=photo_entry_association,
|
secondary=photo_entry_association,
|
||||||
|
|||||||
@@ -7,8 +7,7 @@ from sqlalchemy.orm import relationship
|
|||||||
from sqlalchemy.sql.schema import Index
|
from sqlalchemy.sql.schema import Index
|
||||||
|
|
||||||
from pilgrim.models.photo_in_entry import photo_entry_association
|
from pilgrim.models.photo_in_entry import photo_entry_association
|
||||||
from pilgrim.database import Base
|
from ..database import Base
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Photo(Base):
|
class Photo(Base):
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from sqlalchemy import Table, Column, Integer, ForeignKey
|
from sqlalchemy import Table, Column, Integer, ForeignKey
|
||||||
|
|
||||||
from pilgrim.database import Base
|
from ..database import Base
|
||||||
|
|
||||||
photo_entry_association = Table('photo_entry_association', Base.metadata,
|
photo_entry_association = Table('photo_entry_association', Base.metadata,
|
||||||
Column('id', Integer, primary_key=True, autoincrement=True),
|
Column('id', Integer, primary_key=True, autoincrement=True),
|
||||||
|
|||||||
@@ -3,11 +3,10 @@ from typing import Any
|
|||||||
from sqlalchemy import Column, Integer, String, UniqueConstraint
|
from sqlalchemy import Column, Integer, String, UniqueConstraint
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
|
|
||||||
from pilgrim.database import Base
|
from .. import database
|
||||||
|
|
||||||
|
|
||||||
|
class TravelDiary(database.Base):
|
||||||
class TravelDiary(Base):
|
|
||||||
__tablename__ = "travel_diaries"
|
__tablename__ = "travel_diaries"
|
||||||
id = Column(Integer, primary_key=True)
|
id = Column(Integer, primary_key=True)
|
||||||
name = Column(String, nullable=False)
|
name = Column(String, nullable=False)
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from pilgrim.models.entry import Entry
|
from ..models.entry import Entry
|
||||||
from pilgrim.models.travel_diary import TravelDiary
|
from ..models.travel_diary import TravelDiary
|
||||||
from pilgrim.models.photo import Photo # ✨ Importe o modelo Photo
|
from ..models.photo import Photo # ✨ Importe o modelo Photo
|
||||||
|
|
||||||
|
|
||||||
class EntryService:
|
class EntryService:
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ from pathlib import Path
|
|||||||
from pilgrim.utils import DirectoryManager
|
from pilgrim.utils import DirectoryManager
|
||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError
|
||||||
|
|
||||||
from pilgrim.models.travel_diary import TravelDiary
|
from ..models.travel_diary import TravelDiary
|
||||||
from unidecode import unidecode
|
|
||||||
|
|
||||||
class TravelDiaryService:
|
class TravelDiaryService:
|
||||||
def __init__(self, session):
|
def __init__(self, session):
|
||||||
@@ -20,10 +20,8 @@ class TravelDiaryService:
|
|||||||
- Replaces spaces with underscores
|
- Replaces spaces with underscores
|
||||||
- Ensures name is unique by adding a suffix if needed
|
- Ensures name is unique by adding a suffix if needed
|
||||||
"""
|
"""
|
||||||
transliterated_name = unidecode(name)
|
|
||||||
|
|
||||||
# Remove special characters and replace spaces
|
# Remove special characters and replace spaces
|
||||||
safe_name = re.sub(r'[^\w\s-]', '', transliterated_name)
|
safe_name = re.sub(r'[^\w\s-]', '', name)
|
||||||
safe_name = safe_name.strip().replace(' ', '_').lower()
|
safe_name = safe_name.strip().replace(' ', '_').lower()
|
||||||
|
|
||||||
# Ensure we have a valid name
|
# Ensure we have a valid name
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
import pytest
|
|
||||||
from sqlalchemy import create_engine
|
|
||||||
from sqlalchemy.orm import sessionmaker
|
|
||||||
|
|
||||||
from pilgrim.database import Base
|
|
||||||
from pilgrim.models.travel_diary import TravelDiary
|
|
||||||
|
|
||||||
# Todos os imports necessários para as fixtures devem estar aqui
|
|
||||||
# ...
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
|
||||||
def db_session():
|
|
||||||
"""Esta fixture agora está disponível para TODOS os testes."""
|
|
||||||
engine = create_engine("sqlite:///:memory:")
|
|
||||||
Base.metadata.create_all(engine)
|
|
||||||
Session = sessionmaker(bind=engine)
|
|
||||||
session = Session()
|
|
||||||
yield session
|
|
||||||
session.close()
|
|
||||||
Base.metadata.drop_all(engine)
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def populated_db_session(db_session):
|
|
||||||
"""Esta também fica disponível para todos."""
|
|
||||||
travel_diary = TravelDiary(name="My Travel Diary", directory_name="viagem-teste")
|
|
||||||
db_session.add(travel_diary)
|
|
||||||
db_session.commit()
|
|
||||||
return db_session
|
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import pytest
|
||||||
|
from unittest.mock import Mock # A ferramenta para criar nosso "dublê"
|
||||||
|
from pathlib import Path
|
||||||
|
from sqlalchemy import inspect, Column, Integer, String
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
from pilgrim.database import Database,Base
|
||||||
|
|
||||||
|
class MockUser(Base):
|
||||||
|
__tablename__ = 'mock_users'
|
||||||
|
id = Column(Integer, primary_key=True)
|
||||||
|
name = Column(String)
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def db_instance(tmp_path: Path):
|
||||||
|
fake_db_path = tmp_path / "test_pilgrim.db"
|
||||||
|
mock_config_manager = Mock()
|
||||||
|
mock_config_manager.database_url = str(fake_db_path)
|
||||||
|
db = Database(mock_config_manager)
|
||||||
|
return db, fake_db_path
|
||||||
|
|
||||||
|
def test_create_database(db_instance):
|
||||||
|
db, fake_db_path = db_instance
|
||||||
|
db.create()
|
||||||
|
assert fake_db_path.exists()
|
||||||
|
|
||||||
|
def test_table_creation(db_instance):
|
||||||
|
db, _ = db_instance
|
||||||
|
db.create()
|
||||||
|
inspector = inspect(db.engine)
|
||||||
|
assert "mock_users" in inspector.get_table_names()
|
||||||
|
|
||||||
|
def test_session_returned_corectly(db_instance):
|
||||||
|
db, _ = db_instance
|
||||||
|
session = db.session()
|
||||||
|
assert isinstance(session, Session)
|
||||||
|
session.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user