Skip to content

Commit

Permalink
Merge pull request #78 from AntonioMrtz/feat/MiddlewareJwt
Browse files Browse the repository at this point in the history
Feat/middleware jwt
  • Loading branch information
AntonioMrtz authored Oct 6, 2023
2 parents 667641b + 520f607 commit ffefdb6
Show file tree
Hide file tree
Showing 39 changed files with 1,000 additions and 362 deletions.
12 changes: 6 additions & 6 deletions Backend API/src/__tests__/test_API/api_all_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
client = TestClient(app)


def patch_history_playback(user_name: str, song_name: str):
def patch_history_playback(user_name: str, song_name: str, headers: dict):
response = client.patch(
f"/usuarios/{user_name}/historial/?nombre_cancion={song_name}")
f"/usuarios/{user_name}/historial/?nombre_cancion={song_name}", headers=headers)
return response


def patch_playlist_saved(user_name: str, playlist_name: str):
def patch_playlist_saved(user_name: str, playlist_name: str, headers: dict):
response = client.patch(
f"/usuarios/{user_name}/playlists_guardadas/?nombre_playlist={playlist_name}")
f"/usuarios/{user_name}/playlists_guardadas/?nombre_playlist={playlist_name}", headers=headers)
return response


def delete_playlist_saved(user_name: str, playlist_name: str):
def delete_playlist_saved(user_name: str, playlist_name: str, headers: dict):
response = client.delete(
f"/usuarios/{user_name}/playlists_guardadas/?nombre_playlist={playlist_name}")
f"/usuarios/{user_name}/playlists_guardadas/?nombre_playlist={playlist_name}", headers=headers)
return response


Expand Down
18 changes: 10 additions & 8 deletions Backend API/src/__tests__/test_API/api_test_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
client = TestClient(app)


def get_artist(name: str):
def get_artist(name: str, headers: dict):

response = client.get(f"/artistas/{name}")
response = client.get(f"/artistas/{name}", headers=headers)
return response


Expand All @@ -21,7 +21,7 @@ def create_artist(name: str, photo: str, password: str):
return response


def update_artist(name: str, photo: str, playlists: list, saved_playlists: list, playback_history: list, uploaded_songs: list):
def update_artist(name: str, photo: str, playlists: list, saved_playlists: list, playback_history: list, uploaded_songs: list, headers: dict):

url = f"/artistas/{name}/?foto={photo}"

Expand All @@ -32,8 +32,10 @@ def update_artist(name: str, photo: str, playlists: list, saved_playlists: list,
"canciones_creadas": uploaded_songs
}

file_type_header = {"Content-Type": "application/json"}

response = client.put(
url, json=payload, headers={"Content-Type": "application/json"}
url, json=payload, headers={**file_type_header, **headers}
)

return response
Expand All @@ -44,11 +46,11 @@ def delete_artist(name: str):
return response


def get_artists():
response = client.get(f"/artistas/")
def get_artists(headers: dict):
response = client.get(f"/artistas/", headers=headers)
return response


def get_play_count_artist(name: str):
response = client.get(f"/artistas/{name}/reproducciones")
def get_play_count_artist(name: str, headers: dict):
response = client.get(f"/artistas/{name}/reproducciones", headers=headers)
return response
8 changes: 4 additions & 4 deletions Backend API/src/__tests__/test_API/api_test_dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
client = TestClient(app)


def get_playlist_dto(name: str):
def get_playlist_dto(name: str, headers: dict):

response = client.get(f"/playlists/dto/{name}")
response = client.get(f"/playlists/dto/{name}", headers=headers)
return response


def get_song_dto(name: str):
response = client.get(f"/canciones/dto/{name}")
def get_song_dto(name: str, headers: dict):
response = client.get(f"/canciones/dto/{name}", headers=headers)
return response
28 changes: 17 additions & 11 deletions Backend API/src/__tests__/test_API/api_test_playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,40 @@
client = TestClient(app)


def create_playlist(name: str, descripcion: str, foto: str, creador: str):
def create_playlist(name: str, descripcion: str, foto: str, headers: dict):

url = f"/playlists/?nombre={name}&foto={foto}&descripcion={descripcion}&creador={creador}"
url = f"/playlists/?nombre={name}&foto={foto}&descripcion={descripcion}"

payload = []

file_type_header = {"Content-Type": "application/json"}

response = client.post(
url, json=payload, headers={"Content-Type": "application/json"}
url, json=payload, headers={**file_type_header, **headers}
)

return response


def get_playlist(name: str):
def get_playlist(name: str, headers: dict):

response = client.get(f"/playlists/{name}")
response = client.get(f"/playlists/{name}", headers=headers)
return response


def get_playlists(song_names: str):
def get_playlists(song_names: str, headers: dict):

response = client.get(f"/playlists/multiple/{song_names}")
response = client.get(f"/playlists/multiple/{song_names}", headers=headers)
return response


def update_playlist(
name: str,
descripcion: str,
foto: str,
nuevo_nombre: str = ""):
headers: dict,
nuevo_nombre: str = ""
):

if nuevo_nombre == "":
url = f"/playlists/{name}/?foto={foto}&descripcion={descripcion}"
Expand All @@ -44,8 +48,10 @@ def update_playlist(

payload = []

file_type_header = {"Content-Type": "application/json"}

response = client.put(
url, json=payload, headers={"Content-Type": "application/json"}
url, json=payload, headers={**file_type_header, **headers}
)

return response
Expand All @@ -56,6 +62,6 @@ def delete_playlist(name: str):
return response


def get_all_playlists():
response = client.get(f"/playlists/")
def get_all_playlists(headers:dict):
response = client.get(f"/playlists/",headers=headers)
return response
24 changes: 12 additions & 12 deletions Backend API/src/__tests__/test_API/api_test_song.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
def create_song(
name: str,
file_path: str,
artista: str,
genero: str,
foto: str):
foto: str,
headers: dict):

url = f"/canciones/?nombre={name}&artista={artista}&genero={genero}&foto={foto}"
url = f"/canciones/?nombre={name}&genero={genero}&foto={foto}"

with open(file_path, 'rb') as file:
response = client.post(url, files={'file': file})
response = client.post(url, files={'file': file}, headers=headers)
return response


def get_song(name: str):
def get_song(name: str, headers: dict):

response = client.get(f"/canciones/{name}")
response = client.get(f"/canciones/{name}", headers=headers)
return response


Expand All @@ -30,22 +30,22 @@ def delete_song(name: str):
return response


def get_songs():
response = client.get(f"/canciones/")
def get_songs(headers: dict):
response = client.get(f"/canciones/", headers=headers)
return response


def patch_song_number_plays(name: str):
def patch_song_number_plays(name: str, headers: dict):

patch_url = f"/canciones/{name}/numberOfPlays"

response = client.patch(patch_url)
response = client.patch(patch_url, headers=headers)
return response


def get_songs_by_genre(genre : str):
def get_songs_by_genre(genre: str, headers: dict):

get_url = f"/canciones/generos/{genre}"

response = client.get(get_url)
response = client.get(get_url, headers=headers)
return response
10 changes: 6 additions & 4 deletions Backend API/src/__tests__/test_API/api_test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
client = TestClient(app)


def get_user(name: str):
def get_user(name: str, headers: dict):

response = client.get(f"/usuarios/{name}")
response = client.get(f"/usuarios/{name}", headers=headers)
return response


Expand All @@ -21,7 +21,7 @@ def create_user(name: str, photo: str, password: str):
return response


def update_user(name: str, photo: str, playlists: list, saved_playlists: list, playback_history: list):
def update_user(name: str, photo: str, playlists: list, saved_playlists: list, playback_history: list, headers: dict):

url = f"/usuarios/{name}/?foto={photo}"

Expand All @@ -31,8 +31,10 @@ def update_user(name: str, photo: str, playlists: list, saved_playlists: list, p
"playlists_guardadas": saved_playlists
}

file_type_header = {"Content-Type": "application/json"}

response = client.put(
url, json=payload, headers={"Content-Type": "application/json"}
url, json=payload, headers={**file_type_header, **headers}
)

return response
Expand Down
14 changes: 14 additions & 0 deletions Backend API/src/__tests__/test_API/api_token.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from test_API.api_login import post_login
import pytest


def get_user_jwt_header(username : str , password : str):

response = post_login(user_name=username,password=password)
assert response.status_code==200

jwt = response.json()

return {
"authorization": f"{jwt}",
}
Loading

0 comments on commit ffefdb6

Please sign in to comment.