Skip to content

Commit

Permalink
feat: fix test + disable swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
Angel-Dijoux committed Jan 23, 2024
1 parent 81ebee2 commit 33c2686
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 84 deletions.
22 changes: 4 additions & 18 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
import sys

from flasgger import Swagger
from apispec.ext.marshmallow import MarshmallowPlugin
from apispec_webframeworks.flask import FlaskPlugin
from flask import Flask
from flask_cors import CORS
from flask_jwt_extended import JWTManager
Expand All @@ -10,17 +11,9 @@
from loguru import logger

from config import load_config
from src.config.swagger import (
get_swagger_api_spec,
swagger_config,
)
from src.models.schemas import schemas
from flasgger.utils import apispec_to_template

from .errors import register_error_handlers
from .middlewares import after_request
from apispec.ext.marshmallow import MarshmallowPlugin
from apispec_webframeworks.flask import FlaskPlugin

db: SQLAlchemy = SQLAlchemy()
plugins = [
Expand All @@ -44,13 +37,6 @@ def create_app(environment=None):
with app.app_context():
register_blueprints(app)

template = apispec_to_template(
app=app,
spec=get_swagger_api_spec(config=config, plugins=plugins),
definitions=schemas,
)
Swagger(app, config=swagger_config, template=template)

app.after_request(after_request)
register_error_handlers(app)

Expand All @@ -61,9 +47,9 @@ def register_blueprints(app: Flask):
from src.blueprints.auth import auth
from src.blueprints.favoris import favoris
from src.blueprints.formations import formations
from src.blueprints.utils import utils
from src.blueprints.legal.views import legal
from src.blueprints.graphql import graphql
from src.blueprints.legal.views import legal
from src.blueprints.utils import utils

app.register_blueprint(utils)
app.register_blueprint(auth)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_search_formations_should_return_formations_without_favorite(
mock_search_formations.return_value = MOKED_RESEARCH

# Act
formations = search_formations("STHR", 1)
formations = search_formations(limit=1, offset=None, query="STHR1")

# Assert
moked_formation = MOKED_RESEARCH["results"]
Expand All @@ -68,7 +68,7 @@ def test_search_formations_should_return_formations_without_favorite(
)

assert formations == waited_result
mock_search_formations.assert_called_once_with("STHR", 1, None)
mock_search_formations.assert_called_once_with(limit=1, offset=None, query="STHR1")


def test_authenticated_search_formations_should_return_formations_with_favorite(
Expand All @@ -87,7 +87,9 @@ def test_authenticated_search_formations_should_return_formations_with_favorite(
db_session.commit()

# Act
formations = auth_search_formations(user.id, "STHR", 1)
formations = auth_search_formations(
user_id=user.id, query="STHR2", limit=1, offset=None
)

# Assert
moked_formation = MOKED_RESEARCH["results"]
Expand All @@ -97,4 +99,4 @@ def test_authenticated_search_formations_should_return_formations_with_favorite(
)

assert formations == waited_result
mock_search_formations.assert_called_once_with("STHR", 1, None)
mock_search_formations.assert_called_once_with(query="STHR2", limit=1, offset=None)
13 changes: 6 additions & 7 deletions src/models/base_model.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
from sqlalchemy import Column, DateTime, func
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import func


Model = declarative_base(name="Model")
from src import db


class BaseModel(Model):
class BaseModel(db.Model):
__abstract__: bool = True
__allow_unmapped__: bool = True

created_at = Column(DateTime, nullable=False, default=func.now())
updated_at = Column(
DateTime, nullable=False, default=func.now(), onupdate=func.now()
created_at = db.Column(db.DateTime, nullable=False, default=func.now())
updated_at = db.Column(
db.DateTime, nullable=False, default=func.now(), onupdate=func.now()
)

def to_dict(self):
Expand Down
20 changes: 11 additions & 9 deletions src/models/formation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from src.models.base_model import BaseModel
from src.models.helpers.UUIDType import UUIDType

from src import db


def default_uuid5():
namespace = uuid.uuid4()
Expand All @@ -16,16 +18,16 @@ def default_uuid5():
class Formation(BaseModel):
__tablename__ = "formation"

id: uuid.UUID = Column(
id: uuid.UUID = db.Column(
UUIDType,
default=default_uuid5,
primary_key=True,
)
code_nsf: int = Column(Integer, nullable=False)
type: str = Column(String(255), nullable=False)
libelle: str = Column(String(255), nullable=False)
tutelle: str = Column(String(255), nullable=False)
url: str = Column(String(255), nullable=False, unique=True)
domain: str = Column(Text, nullable=False)
niveau_de_sortie: str = Column(String(255), nullable=False)
duree: str = Column(String(255), nullable=False)
code_nsf: int = db.Column(db.Integer, nullable=False)
type: str = db.Column(db.String(255), nullable=False)
libelle: str = db.Column(db.String(255), nullable=False)
tutelle: str = db.Column(db.String(255), nullable=False)
url: str = db.Column(db.String(255), nullable=False, unique=True)
domain: str = db.Column(db.Text, nullable=False)
niveau_de_sortie: str = db.Column(db.String(255), nullable=False)
duree: str = db.Column(db.String(255), nullable=False)
4 changes: 0 additions & 4 deletions src/models/schemas/__init__.py

This file was deleted.

24 changes: 0 additions & 24 deletions src/models/schemas/schemas.py

This file was deleted.

17 changes: 8 additions & 9 deletions src/models/user.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from typing import Optional

from sqlalchemy import Column, Integer, String, Text
import strawberry

from src import db
from src.models.base_model import BaseModel
from src.models.user_favori import UserFavori
from sqlalchemy.orm import relationship


# Create User row

Expand All @@ -14,13 +13,13 @@
class User(BaseModel):
__tablename__ = "user"

id: int = Column(Integer, primary_key=True)
username: str = Column(String(80), unique=True, nullable=False)
email: str = Column(String(200), unique=True, nullable=False)
password = Column(Text(), nullable=False)
profile_pic_url: Optional[str] = Column(Text)
id: int = db.Column(db.Integer, primary_key=True)
username: str = db.Column(db.String(80), unique=True, nullable=False)
email: str = db.Column(db.String(200), unique=True, nullable=False)
password = db.Column(db.Text(), nullable=False)
profile_pic_url: Optional[str] = db.Column(db.Text)

favoris: list[UserFavori] = relationship(
favoris: list[UserFavori] = db.relationship(
"UserFavori",
secondary=UserFavori.__tablename__,
primaryjoin="User.id == UserFavori.user_id",
Expand Down
19 changes: 10 additions & 9 deletions src/models/user_favori.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
from sqlalchemy import Column, ForeignKey, Integer
from src.models.base_model import BaseModel
from sqlalchemy import ForeignKey
from sqlalchemy_serializer import SerializerMixin

from src import db
from src.models import Formation
from src.models.base_model import BaseModel
from src.models.helpers.UUIDType import UUIDType
from sqlalchemy_serializer import SerializerMixin
from sqlalchemy.orm import relationship


class UserFavori(BaseModel, SerializerMixin):
__tablename__ = "user_favori"

serialize_only = "formation_id"

formation_id = Column(
formation_id = db.Column(
UUIDType,
ForeignKey("formation.id", ondelete="CASCADE"),
primary_key=True,
index=True,
)

user_id = Column(
Integer,
user_id = db.Column(
db.Integer,
ForeignKey("user.id", ondelete="CASCADE"),
primary_key=True,
index=True,
)

users = relationship("User", back_populates="favoris")
formation: list[Formation] = relationship("Formation")
users = db.relationship("User", back_populates="favoris")
formation: list[Formation] = db.relationship("Formation")

0 comments on commit 33c2686

Please sign in to comment.