diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 5aadda0f4..3b6f94563 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -37,7 +37,7 @@ jobs: cache: "pip" - name: Install dependencies - run: pip install -r requirements.txt -r requirements.dev.txt + run: pip install -r requirements.txt - name: Run Pyright uses: jakebailey/pyright-action@v1 diff --git a/requirements.dev.txt b/requirements.dev.txt index 03ccc1605..8597bf385 100644 --- a/requirements.dev.txt +++ b/requirements.dev.txt @@ -7,6 +7,3 @@ pre-commit # needed for pip-compile, needed to generate requirements.txt pip-tools pigar - -# needed to run tests -pytest==8.0.2 diff --git a/requirements.in b/requirements.in index e9bada41f..ee9f08804 100644 --- a/requirements.in +++ b/requirements.in @@ -3,6 +3,7 @@ APIFlask==2.0.2 Authlib==1.2.0 boto3==1.34.83 +click==8.1.7 Flask==3.0.0 Flask-Cors==4.0.0 Flask-SQLAlchemy==3.1.1 @@ -11,6 +12,8 @@ numpy==1.26.0 openai==1.17.0 pandas==2.1.1 psycopg2-binary==2.9.9 +pytest==8.0.2 python-dotenv==1.0.0 redis==5.0.1 +requests==2.28.1 SQLAlchemy==2.0.22 diff --git a/requirements.txt b/requirements.txt index 1888b3650..3254970b1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -28,10 +28,15 @@ certifi==2024.2.2 # via # httpcore # httpx + # requests cffi==1.16.0 # via cryptography +charset-normalizer==2.1.1 + # via requests click==8.1.7 - # via flask + # via + # -r requirements.in + # flask cryptography==42.0.5 # via authlib distro==1.9.0 @@ -64,6 +69,9 @@ idna==3.7 # via # anyio # httpx + # requests +iniconfig==2.0.0 + # via pytest itsdangerous==2.1.2 # via flask jinja2==3.1.2 @@ -92,9 +100,12 @@ packaging==24.0 # via # apispec # marshmallow + # pytest # webargs pandas==2.1.1 # via -r requirements.in +pluggy==1.4.0 + # via pytest psycopg2-binary==2.9.9 # via -r requirements.in pycparser==2.22 @@ -103,6 +114,8 @@ pydantic==2.7.0 # via openai pydantic-core==2.18.1 # via pydantic +pytest==8.0.2 + # via -r requirements.in python-dateutil==2.9.0.post0 # via # botocore @@ -113,6 +126,8 @@ pytz==2024.1 # via pandas redis==5.0.1 # via -r requirements.in +requests==2.28.1 + # via -r requirements.in s3transfer==0.10.1 # via boto3 six==1.16.0 @@ -136,8 +151,10 @@ typing-extensions==4.11.0 # sqlalchemy tzdata==2024.1 # via pandas -urllib3==2.2.1 - # via botocore +urllib3==1.26.18 + # via + # botocore + # requests webargs==8.4.0 # via apiflask werkzeug==3.0.2 diff --git a/server/controllers/emails.py b/server/controllers/emails.py index de48f7707..cccc7afe7 100644 --- a/server/controllers/emails.py +++ b/server/controllers/emails.py @@ -526,20 +526,23 @@ def get_threads(): Get a list of all threads. """ - thread_list = db.session.execute( - select(Thread).order_by(Thread.resolved, Thread.last_email.desc()) - ).all() - email_list = [ - { - "id": thread.id, - "resolved": thread.resolved, - "emailList": [ - thread_email.map() - for thread_email in db.session.execute( - select(Email).where(Email.thread_id == thread.id) - ).all() - ], - } - for thread in thread_list - ] + thread_list = db.session.execute(select(Thread)).all() + print("thread list", thread_list) + # thread_list = db.session.execute( + # select(Thread).order_by(Thread.resolved, Thread.last_email.desc()) + # ).all() + # email_list = [ + # { + # "id": thread.id, + # "resolved": thread.resolved, + # "emailList": [ + # thread_email.map() + # for thread_email in db.session.execute( + # select(Email).where(Email.thread_id == thread.id) + # ).all() + # ], + # } + # for thread in thread_list + # ] + email_list = [] return email_list diff --git a/server/models/document.py b/server/models/document.py index 20e5cc9a4..4ed4bd1be 100644 --- a/server/models/document.py +++ b/server/models/document.py @@ -26,7 +26,7 @@ class Document(db.Model): response_count(int): The number of responses the document has. """ - __tablename__ = "Documents" + __tablename__ = "document" id: Mapped[str] = mapped_column(primary_key=True, init=False) question: Mapped[str] = mapped_column(nullable=False) diff --git a/server/models/document_response.py b/server/models/document_response.py index c9f0e9add..1e3bee48d 100644 --- a/server/models/document_response.py +++ b/server/models/document_response.py @@ -1,6 +1,6 @@ """Association table for Document and Response.""" -from sqlalchemy import Column, ForeignKey, Integer, Table +from sqlalchemy import Column, ForeignKey, Table from server import db @@ -9,14 +9,12 @@ db.Model.metadata, Column( "document_id", - Integer, - ForeignKey("Documents.id", ondelete="CASCADE"), + ForeignKey("document.id", ondelete="CASCADE"), primary_key=True, ), Column( "response_id", - Integer, - ForeignKey("Responses.id", ondelete="CASCADE"), + ForeignKey("response.id", ondelete="CASCADE"), primary_key=True, ), ) diff --git a/server/models/email.py b/server/models/email.py index 449811863..e2547bc7e 100644 --- a/server/models/email.py +++ b/server/models/email.py @@ -30,7 +30,7 @@ class Email(db.Model): thread(Thread): The thread the email belongs to. """ - __tablename__ = "Emails" + __tablename__ = "email" id: Mapped[str] = mapped_column(primary_key=True, init=False) date: Mapped[datetime.datetime] = mapped_column(nullable=False) @@ -45,7 +45,7 @@ class Email(db.Model): is_reply: Mapped[bool] = mapped_column(nullable=False) - thread_id: Mapped[str] = mapped_column(ForeignKey("Threads.id"), nullable=False) + thread_id: Mapped[str] = mapped_column(ForeignKey("thread.id"), nullable=False) thread: Mapped["Thread"] = relationship(back_populates="emails", init=False) def map(self): diff --git a/server/models/response.py b/server/models/response.py index e4785a461..8acdee2fb 100644 --- a/server/models/response.py +++ b/server/models/response.py @@ -32,7 +32,7 @@ class Response(db.Model): email(Email): The original email. """ - __tablename__ = "Responses" + __tablename__ = "response" __table_args__ = (UniqueConstraint("email_id", name="unique_email_id"),) id: Mapped[str] = mapped_column(primary_key=True, init=False) @@ -49,7 +49,7 @@ class Response(db.Model): confidence: Mapped[float] = mapped_column(nullable=False) - email_id: Mapped[str] = mapped_column(ForeignKey("Emails.id", ondelete="CASCADE")) + email_id: Mapped[str] = mapped_column(ForeignKey("email.id", ondelete="CASCADE")) email: Mapped["Email"] = relationship( back_populates="response", init=False, single_parent=True ) diff --git a/server/models/thread.py b/server/models/thread.py index 953d1d10b..66e28aef7 100644 --- a/server/models/thread.py +++ b/server/models/thread.py @@ -23,14 +23,14 @@ class Thread(db.Model): emails(list): The emails in the thread. """ - __tablename__ = "Threads" + __tablename__ = "thread" id: Mapped[str] = mapped_column(primary_key=True, init=False) last_email: Mapped[Optional[str]] = mapped_column(nullable=True, init=False) resolved: Mapped[bool] = mapped_column(nullable=False, default=False) emails: Mapped[List["Email"]] = relationship( - "Email", + "email", back_populates="thread", default_factory=list, cascade="all, delete-orphan", @@ -43,5 +43,5 @@ def first_sender(self): email = db.session.execute( select(Email).where(Email.thread_id == self.id) - ).scalar_one_or_none() + ).scalar() return email.sender if email else None