Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "welearn-database"
version = "1.4.4"
version = "1.4.5.dev1"
description = "All stuff related to relationnal database from the WeLearn project"
authors = [
{name = "Théo",email = "theo.nardin@cri-paris.org"}
Expand Down
18 changes: 18 additions & 0 deletions tests/test_user_related.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from welearn_database.data.models.user_related import (
UserProfile,
)
from welearn_database.exceptions import EarlyEnumerationVerificationError


class TestUserRelatedCRUD(TestCase):
Expand Down Expand Up @@ -63,6 +64,23 @@ def test_create_and_read_inferred_user(self):
)
self.assertIsNotNone(result)

def test_create_and_read_inferred_user_with_university_data(self):
inferred_user = InferredUser(
id=uuid.uuid4(),
origin_referrer="test_ref",
university_title="test_university",
role="student",
)
self.session.add(inferred_user)
self.session.commit()
result = (
self.session.query(InferredUser)
.filter_by(origin_referrer="test_ref")
.first()
)
self.assertEqual(result.university_title, "test_university")
self.assertEqual(result.role, "student")

def test_create_and_read_session(self):
inferred_user = InferredUser(id=uuid.uuid4())
self.session.add(inferred_user)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""add_university_data

Revision ID: 8b780aea403a
Revises: f1ce0ad2845b
Create Date: 2026-06-03 11:34:02.441435

"""

from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision: str = "8b780aea403a"
down_revision: Union[str, None] = "f1ce0ad2845b"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# op.execute("""
# CREATE TYPE user_related.university_role AS ENUM ('student', 'teacher', 'staff')
# """)
op.add_column(
"inferred_user",
sa.Column("university_title", sa.String(), nullable=True),
schema="user_related",
)
op.add_column(
"inferred_user",
sa.Column(
"role",
sa.String(),
nullable=True,
),
schema="user_related",
)


def downgrade() -> None:
op.drop_column("inferred_user", "university_title", schema="user_related")
op.drop_column("inferred_user", "role", schema="user_related")
1 change: 0 additions & 1 deletion welearn_database/data/models/document_related.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
LargeBinary,
UniqueConstraint,
func,
text,
types,
)
from sqlalchemy.dialects.postgresql import ARRAY, ENUM, TIMESTAMP
Expand Down
2 changes: 2 additions & 0 deletions welearn_database/data/models/user_related.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ class InferredUser(Base):
types.Uuid, primary_key=True, nullable=False, server_default="gen_random_uuid()"
)
origin_referrer: Mapped[str | None]
university_title: Mapped[str | None]
role: Mapped[str | None]
created_at: Mapped[datetime] = mapped_column(
TIMESTAMP(timezone=False),
nullable=False,
Expand Down
23 changes: 20 additions & 3 deletions welearn_database/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
class InvalidURLScheme(Exception):
class WeLearnDatabaseException(Exception):
"""
Base class for all WeLearnDatabase exceptions
"""


class InvalidURLScheme(WeLearnDatabaseException):
"""
Scheme detected in URL is not accepted
"""
Expand All @@ -7,7 +13,7 @@ def __init__(self, msg="URL schema is not accepted", *args):
super().__init__(msg, *args)


class InvalidDOI(Exception):
class InvalidDOI(WeLearnDatabaseException):
"""
Scheme detected in DOI is not accepted
"""
Expand All @@ -16,7 +22,7 @@ def __init__(self, msg="DOI schema is not accepted", *args):
super().__init__(msg, *args)


class ContentIsTooShort(Exception):
class ContentIsTooShort(WeLearnDatabaseException):
"""
The string used as content is too short, it should be at least 25 characters long
"""
Expand All @@ -27,3 +33,14 @@ def __init__(
*args,
):
super().__init__(msg, *args)


class EarlyEnumerationVerificationError(WeLearnDatabaseException):
"""
SQLAlchemy detect an enumeration value that is not in the list of accepted values
"""

def __init__(
self, msg="Enumeration value is not in the list of accepted values", *args
):
super().__init__(msg, *args)
Loading