Skip to content

Commit

Permalink
Update odr_core test suite
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Cronin <[email protected]>
  • Loading branch information
robert-cronin committed Aug 30, 2024
1 parent 849a05c commit 971d68b
Show file tree
Hide file tree
Showing 23 changed files with 240 additions and 240 deletions.
2 changes: 1 addition & 1 deletion modules/odr_core/odr_core/models/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import declarative_base
# Create Base class
Base = declarative_base()
26 changes: 14 additions & 12 deletions modules/odr_core/odr_core/models/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@
ARRAY,
DateTime,
)
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.orm import relationship
from sqlalchemy.sql import func
from odr_core.models.base import Base
from sqlalchemy import Enum as SQLAlchemyEnum
import enum


class ContentType(enum.Enum):
IMAGE = "image"
VIDEO = "video"
VOICE = "voice"
MUSIC = "music"
TEXT = "text"
IMAGE = "IMAGE"
VIDEO = "VIDEO"
VOICE = "VOICE"
MUSIC = "MUSIC"
TEXT = "TEXT"


class ContentStatus(enum.Enum):
PENDING = "pending"
AVAILABLE = "available"
UNAVAILABLE = "unavailable"
DELISTED = "delisted"
PENDING = "PENDING"
AVAILABLE = "AVAILABLE"
UNAVAILABLE = "UNAVAILABLE"
DELISTED = "DELISTED"


class ContentSourceType(enum.Enum):
Expand All @@ -44,13 +44,15 @@ class Content(Base):
id = Column(Integer, primary_key=True, index=True)
name = Column(String, nullable=True)
type = Column(Enum(ContentType))
type = Column(SQLAlchemyEnum(ContentType))
hash = Column(String, index=True)
phash = Column(String, index=True)
url = Column(String, nullable=True)
width = Column(Integer, nullable=True)
height = Column(Integer, nullable=True)
format = Column(String)
size = Column(Integer)
status = Column(Enum(ContentStatus), default=ContentStatus.PENDING)
status = Column(SQLAlchemyEnum(ContentStatus), default=ContentStatus.PENDING)
license = Column(String)
license_url = Column(String, nullable=True)
flags = Column(Integer, default=0)
Expand Down Expand Up @@ -91,7 +93,7 @@ class ContentSource(Base):
content_id = Column(Integer, ForeignKey("contents.id"))
type = Column(Enum(ContentSourceType))
value = Column(String, unique=True)
source_metadata = Column(JSONB, nullable=True)
source_metadata = Column(String, nullable=True) # JSON
created_at = Column(DateTime(timezone=True), server_default=func.now())
updated_at = Column(DateTime(timezone=True), onupdate=func.now())

Expand Down
3 changes: 0 additions & 3 deletions modules/odr_core/odr_core/models/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,5 @@ class UserTeam(Base):
team_id = Column(Integer, ForeignKey("teams.id"), primary_key=True)
role = Column(String) # e.g., 'admin', 'member'

user = relationship("User", back_populates="team_users")
team = relationship("Team", back_populates="team_users")

created_at = Column(DateTime(timezone=True), server_default=func.now())
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
25 changes: 13 additions & 12 deletions modules/odr_core/odr_core/schemas/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@


class ContentType(str, Enum):
IMAGE = "image"
VIDEO = "video"
VOICE = "voice"
MUSIC = "music"
TEXT = "text"
IMAGE = "IMAGE"
VIDEO = "VIDEO"
VOICE = "VOICE"
MUSIC = "MUSIC"
TEXT = "TEXT"


class ContentStatus(str, Enum):
PENDING = "pending"
AVAILABLE = "available"
UNAVAILABLE = "unavailable"
DELISTED = "delisted"
PENDING = "PENDING"
AVAILABLE = "AVAILABLE"
UNAVAILABLE = "UNAVAILABLE"
DELISTED = "DELISTED"


class ContentSourceType(str, Enum):
URL = "url"
PATH = "path"
HUGGING_FACE = "hugging_face"
URL = "URL"
PATH = "PATH"
HUGGING_FACE = "HUGGING_FACE"


class ContentAuthorBase(BaseModel):
Expand Down Expand Up @@ -79,6 +79,7 @@ class ContentBase(BaseModel):
phash: str
width: Optional[int] = None
height: Optional[int] = None
url: List[HttpUrl] = []
format: str
size: int
status: ContentStatus = ContentStatus.PENDING
Expand Down
9 changes: 9 additions & 0 deletions modules/odr_core/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[pytest]
pythonpath = .
testpaths = tests
python_files = test_*.py
python_classes = Test*
python_functions = test_*
markers =
unit: marks unit tests
integration: marks integration tests
40 changes: 40 additions & 0 deletions modules/odr_core/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import pytest
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from odr_core.models.base import Base
from odr_core.schemas.user import UserCreate
from odr_core.crud.user import create_user

# Use an in-memory SQLite database for testing
SQLALCHEMY_DATABASE_URL = "sqlite:///:memory:"


@pytest.fixture(scope="session")
def engine():
return create_engine(SQLALCHEMY_DATABASE_URL)


@pytest.fixture(scope="session")
def TestingSessionLocal(engine):
return sessionmaker(autocommit=False, autoflush=False, bind=engine)


@pytest.fixture(scope="function")
def db(TestingSessionLocal, engine):
Base.metadata.create_all(bind=engine)
db = TestingSessionLocal()
try:
yield db
finally:
db.close()
Base.metadata.drop_all(bind=engine)


@pytest.fixture(scope="function")
def test_user(db):
user_data = UserCreate(
username="testuser",
email="[email protected]",
password="testpassword"
)
return create_user(db, user_data)
Empty file.
Empty file.
Empty file.
File renamed without changes.
File renamed without changes.
68 changes: 0 additions & 68 deletions modules/odr_core/tests/test_user.py

This file was deleted.

93 changes: 0 additions & 93 deletions modules/odr_core/tests/test_user_crud.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
def test_settings():
assert settings.get_db_url().startswith("postgresql://")
assert settings.API_V1_STR == "/api/v1"
assert settings.PROJECT_NAME == "Open Data Repository"
assert settings.PROJECT_NAME == "OMI-DataModel"


if __name__ == "__main__":
Expand Down
Empty file.
Empty file.
Loading

0 comments on commit 971d68b

Please sign in to comment.