add tests and automated tests
Some checks failed
Deploy Bookshelf / deploy (push) Failing after 0s

This commit is contained in:
Julien Aldon
2026-01-29 10:45:41 +01:00
parent 84369911cd
commit 4639c6d900
7 changed files with 598 additions and 118 deletions

View File

@@ -1,6 +1,4 @@
from database import connection
def get_books(page, limit=50, order="Auteur", search=""):
def get_books(db, page, limit=50, order="Auteur", search=""):
"""
:param limit: Item limit
:type limit: int
@@ -9,8 +7,8 @@ def get_books(page, limit=50, order="Auteur", search=""):
:param order: Book fields are : Auteur, Titre, Editeur, Type
:type order: str
"""
cursor = connection.cursor()
connection.ping(reconnect=True)
cursor = db.cursor()
db.ping(reconnect=True)
if search == "":
t = f"""
SELECT * from Books order by %s asc LIMIT %s OFFSET %s;
@@ -54,9 +52,9 @@ def get_books(page, limit=50, order="Auteur", search=""):
return False
return r, n
def remove_book(id):
cursor = connection.cursor()
connection.ping(reconnect=True)
def remove_book(db, id):
cursor = db.cursor()
db.ping(reconnect=True)
t = f"""
DELETE FROM Books where biblio_Index=%s;
"""
@@ -64,18 +62,18 @@ def remove_book(id):
cursor.execute(t, (id))
except:
return False
connection.commit()
db.commit()
return True
def edit_book(id, newContent):
def edit_book(db, id, newContent):
"""
:param id: item to update
:type id: str
:param newContent: New values to update
:type newContent: dict
"""
cursor = connection.cursor()
connection.ping(reconnect=True)
cursor = db.cursor()
db.ping(reconnect=True)
t = f"""
UPDATE Books
SET Auteur=%s, Titre=%s, Editeur=%s, Type=%s
@@ -85,16 +83,16 @@ def edit_book(id, newContent):
cursor.execute(t, (newContent['author'], newContent['title'], newContent['editor'], newContent['type'], id))
except:
return False
connection.commit()
db.commit()
return True
def add_book(newContent):
def add_book(db, newContent):
"""
:param newContent: New values to add
:type newContent: dict
"""
connection.ping(reconnect=True)
cursor = connection.cursor()
db.ping(reconnect=True)
cursor = db.cursor()
t = f"""
INSERT INTO Books (Auteur, Titre, Editeur, Type)
VALUES (%s, %s, %s, %s);
@@ -103,12 +101,12 @@ def add_book(newContent):
cursor.execute(t, (newContent['author'], newContent['title'], newContent['editor'], newContent['type']))
except:
return False
connection.commit()
db.commit()
return True
def add_film(newContent):
connection.ping(reconnect=True)
cursor = connection.cursor()
def add_film(db, newContent):
db.ping(reconnect=True)
cursor = db.cursor()
t = f"""
INSERT INTO Films (Title, Director, Producer, Actors, Length, Type)
VALUES (%s, %s, %s, %s, %s, %s);
@@ -117,11 +115,11 @@ def add_film(newContent):
cursor.execute(t, (newContent['title'], newContent['director'], newContent['producer'], newContent['actors'], newContent['length'], newContent['type']))
except:
return False
connection.commit()
db.commit()
return True
def remove_film(id):
cursor = connection.cursor()
def remove_film(db, id):
cursor = db.cursor()
t = f"""
DELETE FROM Films where Number=%s;
"""
@@ -129,12 +127,12 @@ def remove_film(id):
cursor.execute(t, (id))
except:
return False
connection.commit()
db.commit()
return True
def edit_film(id, newContent):
connection.ping(reconnect=True)
cursor = connection.cursor()
def edit_film(db, id, newContent):
db.ping(reconnect=True)
cursor = db.cursor()
t = f"""
UPDATE Films
SET Title=%s, Director=%s, Producer=%s, Actors=%s, Length=%s, Type=%s
@@ -144,12 +142,12 @@ def edit_film(id, newContent):
cursor.execute(t, (newContent['title'], newContent['director'], newContent['producer'], newContent['actors'], newContent['length'], newContent['type'], id))
except:
return False
connection.commit()
db.commit()
return True
def get_films(page, limit=50, order="Director"):
connection.ping(reconnect=True)
cursor = connection.cursor()
def get_films(db, page, limit=50, order="Director"):
db.ping(reconnect=True)
cursor = db.cursor()
t = f"""
SELECT * from Films order by %s asc LIMIT %s OFFSET %s;
"""
@@ -159,9 +157,9 @@ def get_films(page, limit=50, order="Director"):
return False
return cursor.fetchall()
def get_field_values(table, field):
connection.ping(reconnect=True)
cursor = connection.cursor()
def get_field_values(db, table, field):
db.ping(reconnect=True)
cursor = db.cursor()
t = f"""
SELECT DISTINCT {field} FROM {table} ORDER BY {field} asc;
"""
@@ -173,9 +171,9 @@ def get_field_values(table, field):
res = cursor.fetchall()
return [a[field] for a in res]
def get_user(username):
connection.ping(reconnect=True)
cursor = connection.cursor()
def get_user(db, username):
db.ping(reconnect=True)
cursor = db.cursor()
t = f"""
SELECT * from Users WHERE username=%s;
"""