Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate tests inside Backend root directory #109

Merged
merged 1 commit into from
Mar 18, 2024
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 .github/workflows/backend-black.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
run: pip install -r requirements.txt && pip install -r requirements-test.txt && pip install -r requirements-dev.txt

- name: Run style check
working-directory: Backend/src
working-directory: Backend/
run: python -m black . --check

- name: Fail workflow on style check failure
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/backend-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ jobs:
run: pip install -r requirements.txt && pip install -r requirements-test.txt

- name: Run tests
working-directory: Backend/src
run: python -m pytest -s
working-directory: Backend/
run: python -m pytest .
env:
MONGO_URI : ${{ secrets.MONGO_URI }}
SECRET_KEY_SIGN : ${{ secrets.SECRET_KEY_SIGN }}
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/generate-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ jobs:
run: pip install -r requirements.txt

- name: Run generate docs
working-directory: Backend/src
working-directory: Backend/
run: |
python generate-docs.py
mv -f api-docs-spotify-electron.html ../api-docs-spotify-electron.html

- name: Add and commit changes
working-directory: Backend/
Expand Down
9 changes: 3 additions & 6 deletions Backend/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"request": "launch",
"module": "uvicorn",
"args": [
"main:app",
"src.main:app",
"--reload"
],
"cwd": "${workspaceFolder}/src/",
"cwd": "${workspaceFolder}/",
"jinja": true,
"justMyCode": false
},
Expand All @@ -25,10 +25,7 @@
"args": [
"tests"
],
"cwd": "${workspaceFolder}/src/",
"env": {
"PYTHONPATH": "${workspaceFolder}"
},
"cwd": "${workspaceFolder}/",
"console": "integratedTerminal",
"justMyCode": false
}
Expand Down
5 changes: 5 additions & 0 deletions Backend/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@
"flake8.args": [
"--max-line-length=88"
],
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
4 changes: 2 additions & 2 deletions Backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt

COPY ./src /app/src

WORKDIR /app/src
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
WORKDIR /code/
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000"]

#docker build -t spotify_electron_backend_image .
#docker run -d --name spotify_electron_backend -e MONGO_URI=mongo-uri SECRET_KEY_SIGN=secret-key DISTRIBUTION_ID=cloudfront-distribution-id -p 8000:8000 spotify_electron_backend_image
2 changes: 1 addition & 1 deletion Backend/src/generate-docs.py → Backend/generate-docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import json

from main import app
from src.main import app

HTML_TEMPLATE = """<!DOCTYPE html>
<html>
Expand Down
File renamed without changes.
15 changes: 11 additions & 4 deletions Backend/src/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
from fastapi import FastAPI, Request, Response
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from middleware.middleware import CheckJwtAuth
from routers import artistas, canciones, generos, login, playlists, search, usuarios
from services.security_service import check_jwt_is_valid
from src.middleware.middleware import CheckJwtAuth
from src.routers import (
artistas,
canciones,
generos,
login,
playlists,
search,
usuarios,
)

app = FastAPI(
title="SpotifyElectronAPI",
Expand Down
2 changes: 1 addition & 1 deletion Backend/src/middleware/middleware.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from fastapi import Request, Response
from services.security_service import check_jwt_is_valid
from src.services.security_service import check_jwt_is_valid
from starlette.middleware.base import BaseHTTPMiddleware


Expand Down
2 changes: 1 addition & 1 deletion Backend/src/model/Artist.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from dataclasses import dataclass

from model.User import User
from src.model.User import User


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion Backend/src/model/DTO/SongDTO.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from dataclasses import dataclass

from model.Genre import Genre
from src.model.Genre import Genre


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion Backend/src/model/Playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from dataclasses import dataclass
from datetime import datetime

import services.song_service as song_service
import src.services.song_service as song_service


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion Backend/src/model/Song.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from dataclasses import dataclass

from model.Genre import Genre
from src.model.Genre import Genre


@dataclass
Expand Down
4 changes: 2 additions & 2 deletions Backend/src/routers/artistas.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import json
from typing import Annotated, Union

import services.artist_service as artist_service
import src.services.artist_service as artist_service
from fastapi import APIRouter, Header, HTTPException
from fastapi.responses import Response
from services.security_service import get_jwt_token
from src.services.security_service import get_jwt_token

router = APIRouter(
prefix="/artistas",
Expand Down
15 changes: 10 additions & 5 deletions Backend/src/routers/canciones.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import json
from typing import Annotated, Union

import services.dto_service as dto_service
import services.song_service as song_service_streaming
from fastapi import APIRouter, Header, HTTPException, UploadFile
import src.services.dto_service as dto_service
import src.services.song_service as song_service_streaming
from fastapi import (
APIRouter,
Header,
HTTPException,
UploadFile,
)
from fastapi.responses import Response
from model.Genre import Genre
from services.security_service import get_jwt_token
from src.model.Genre import Genre
from src.services.security_service import get_jwt_token

router = APIRouter(
prefix="/canciones",
Expand Down
2 changes: 1 addition & 1 deletion Backend/src/routers/generos.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import services.genre_service as genre_service
import src.services.genre_service as genre_service
from fastapi import APIRouter
from fastapi.responses import Response

Expand Down
2 changes: 1 addition & 1 deletion Backend/src/routers/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from datetime import datetime, timedelta, timezone
from typing import Annotated

import services.security_service as security_service
import src.services.security_service as security_service
from fastapi import APIRouter, Depends
from fastapi.responses import Response
from fastapi.security import OAuth2PasswordRequestForm
Expand Down
6 changes: 3 additions & 3 deletions Backend/src/routers/playlists.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import json
from typing import Annotated, Optional, Union

import services.dto_service as dto_service
import services.playlist_service as playlist_service
import src.services.dto_service as dto_service
import src.services.playlist_service as playlist_service
from fastapi import APIRouter, Header, HTTPException
from fastapi.responses import Response
from services.security_service import get_jwt_token
from src.services.security_service import get_jwt_token

router = APIRouter(
prefix="/playlists",
Expand Down
2 changes: 1 addition & 1 deletion Backend/src/routers/search.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import services.search_service as search_service
import src.services.search_service as search_service
from fastapi import APIRouter
from fastapi.responses import Response

Expand Down
8 changes: 4 additions & 4 deletions Backend/src/routers/usuarios.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from typing import Annotated, Union

import services.all_users_service as all_users_service
import services.security_service as security_service
import services.user_service as user_service
import src.services.all_users_service as all_users_service
import src.services.security_service as security_service
import src.services.user_service as user_service
from fastapi import APIRouter, Header, HTTPException
from fastapi.responses import Response
from services.security_service import get_jwt_token
from src.services.security_service import get_jwt_token

router = APIRouter(
prefix="/usuarios",
Expand Down
12 changes: 6 additions & 6 deletions Backend/src/services/all_users_service.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from sys import modules

import services.artist_service as artist_service
import services.user_service as user_service
from database.Database import Database
import src.services.artist_service as artist_service
import src.services.user_service as user_service
from src.database.Database import Database
from fastapi import HTTPException
from model.TokenData import TokenData
from model.UserType import User_Type
from services.utils import checkValidParameterString
from src.model.TokenData import TokenData
from src.model.UserType import User_Type
from src.services.utils import checkValidParameterString

if "pytest" in modules:
user_collection = Database().connection["test.usuario"]
Expand Down
8 changes: 4 additions & 4 deletions Backend/src/services/artist_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from sys import modules

import bcrypt
from database.Database import Database
from src.database.Database import Database
from fastapi import HTTPException
from model.Artist import Artist
from model.TokenData import TokenData
from services.utils import checkValidParameterString
from src.model.Artist import Artist
from src.model.TokenData import TokenData
from src.services.utils import checkValidParameterString

if "pytest" in modules:
artist_collection = Database().connection["test.artista"]
Expand Down
10 changes: 5 additions & 5 deletions Backend/src/services/dto_service.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from sys import modules

from database.Database import Database
from src.database.Database import Database
from fastapi import HTTPException
from model.DTO.PlaylistDTO import PlaylistDTO
from model.DTO.SongDTO import SongDTO
from model.Genre import Genre
from services.utils import checkValidParameterString
from src.model.DTO.PlaylistDTO import PlaylistDTO
from src.model.DTO.SongDTO import SongDTO
from src.model.Genre import Genre
from src.services.utils import checkValidParameterString

if "pytest" in modules:
song_collection = Database().connection["test.canciones.streaming"]
Expand Down
2 changes: 1 addition & 1 deletion Backend/src/services/genre_service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json

from model.Genre import Genre
from src.model.Genre import Genre


def get_genres() -> str:
Expand Down
14 changes: 7 additions & 7 deletions Backend/src/services/playlist_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
from datetime import datetime
from sys import modules

import services.dto_service as dto_service
from database.Database import Database
import src.services.dto_service as dto_service
from src.database.Database import Database
from fastapi import HTTPException
from model.Playlist import Playlist
from model.TokenData import TokenData
from services.all_users_service import (
from src.model.Playlist import Playlist
from src.model.TokenData import TokenData
from src.services.all_users_service import (
add_playlist_to_owner,
check_user_exists,
delete_playlist_from_owner,
)
from services.song_service import get_song
from services.utils import checkValidParameterString
from src.services.song_service import get_song
from src.services.utils import checkValidParameterString

if "pytest" in modules:
playlistCollection = Database().connection["test.playlist"]
Expand Down
10 changes: 5 additions & 5 deletions Backend/src/services/search_service.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import json

import services.artist_service as artist_service
import services.playlist_service as playlist_service
import services.song_service as song_service
import services.user_service as user_service
import src.services.artist_service as artist_service
import src.services.playlist_service as playlist_service
import src.services.song_service as song_service
import src.services.user_service as user_service
from fastapi import HTTPException
from services.utils import checkValidParameterString
from src.services.utils import checkValidParameterString


def search_by_name(name: str) -> str:
Expand Down
16 changes: 8 additions & 8 deletions Backend/src/services/security_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
from fastapi import Depends, HTTPException, status
from fastapi.security import OAuth2PasswordBearer
from jose import JWTError, jwt
from model.Artist import Artist
from model.TokenData import TokenData
from model.User import User
from model.UserType import User_Type
from services.all_users_service import check_user_exists, isArtistOrUser
from services.artist_service import get_artist
from services.user_service import get_user
from services.utils import checkValidParameterString
from src.model.Artist import Artist
from src.model.TokenData import TokenData
from src.model.User import User
from src.model.UserType import User_Type
from src.services.all_users_service import check_user_exists, isArtistOrUser
from src.services.artist_service import get_artist
from src.services.user_service import get_user
from src.services.utils import checkValidParameterString

SECRET_KEY = os.getenv("SECRET_KEY_SIGN")
ALGORITHM = "HS256"
Expand Down
12 changes: 6 additions & 6 deletions Backend/src/services/song_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
import boto3
import librosa
from botocore.exceptions import ClientError
from database.Database import Database
from src.database.Database import Database
from dotenv import load_dotenv
from fastapi import HTTPException
from gridfs import GridFS
from model.Genre import Genre
from model.Song import Song
from model.TokenData import TokenData
from src.model.Genre import Genre
from src.model.Song import Song
from src.model.TokenData import TokenData
from pymongo.errors import PyMongoError
from services.artist_service import (
from src.services.artist_service import (
add_song_artist,
check_artists_exists,
delete_song_artist,
)
from services.utils import checkValidParameterString
from src.services.utils import checkValidParameterString

""" Insert songs with format [files,chunks] https://www.mongodb.com/docs/manual/core/gridfs/"""

Expand Down
Loading
Loading