Added product tests
This commit is contained in:
@ -17,7 +17,9 @@ class DatabaseController(ABC):
|
||||
def __init__(self):
|
||||
self._conn = None
|
||||
try:
|
||||
self._conn = sqlite3.connect(self.__sqlitefile)
|
||||
# Creates a connection and specifies a flag to parse all types back down into
|
||||
# Python declared types e.g. date & time
|
||||
self._conn = sqlite3.connect(self.__sqlitefile, detect_types=sqlite3.PARSE_DECLTYPES)
|
||||
except sqlite3.Error as e:
|
||||
# Close the connection if still open
|
||||
if self._conn:
|
||||
|
@ -2,7 +2,7 @@ from .database import DatabaseController
|
||||
from models.products.product import Product
|
||||
|
||||
class ProductController(DatabaseController):
|
||||
FIELDS = ['id', 'name', 'image', 'description', 'cost', 'category', 'sellerID', 'postedDate', 'quantity']
|
||||
FIELDS = ['id', 'name', 'image', 'description', 'cost', 'category', 'sellerID', 'postedDate', 'quantityAvailable']
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
@ -20,7 +20,7 @@ class ProductController(DatabaseController):
|
||||
]
|
||||
|
||||
self._conn.execute(
|
||||
"INSERT INTO Products (name, cost, image, description, category, sellerID, postedDate, quantityAvailable) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
"INSERT INTO Products (name, image, description, cost, categoryID, sellerID, postedDate, quantityAvailable) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
params
|
||||
)
|
||||
self._conn.commit()
|
||||
@ -46,7 +46,7 @@ class ProductController(DatabaseController):
|
||||
for product in rows:
|
||||
params = dict(zip(self.FIELDS, product))
|
||||
obj = self.new_instance(Product, params)
|
||||
products.push(obj)
|
||||
products.append(obj)
|
||||
|
||||
return products
|
||||
|
||||
|
Reference in New Issue
Block a user