1
0
Fork 0
forked from s3lph/matemat

Merge branch 'ci' into master

This commit is contained in:
s3lph 2018-05-30 00:25:52 +02:00
commit e94f8bd29d
6 changed files with 28 additions and 6 deletions

2
.gitignore vendored
View file

@ -3,6 +3,8 @@
**/__pycache__/ **/__pycache__/
*.pyc *.pyc
**/*.egg-info/
*.coverage
*.sqlite3 *.sqlite3
*.db *.db

11
.gitlab-ci.yml Normal file
View file

@ -0,0 +1,11 @@
---
image: debian:buster
test:
script:
- apt-get update -qy
- apt-get install -y --no-install-recommends python3-dev python3-pip python3-coverage python3-setuptools build-essential
- pip3 install wheel
- pip3 install -r requirements.txt
- python3-coverage run --branch -m unittest discover matemat
- python3-coverage report -m

View file

@ -1,3 +1,4 @@
from typing import List, Optional from typing import List, Optional
import apsw import apsw
@ -276,6 +277,8 @@ class Database(object):
return Product(product_id, name, price_member, price_non_member) return Product(product_id, name, price_member, price_non_member)
def change_product(self, product: Product): def change_product(self, product: Product):
if product.id == -1:
raise ValueError('Invalid product ID')
with self.transaction() as c: with self.transaction() as c:
c.execute(''' c.execute('''
UPDATE products UPDATE products
@ -291,6 +294,8 @@ class Database(object):
}) })
def delete_product(self, product: Product): def delete_product(self, product: Product):
if product.id == -1:
raise ValueError('Invalid product ID')
with self.transaction() as c: with self.transaction() as c:
c.execute(''' c.execute('''
DELETE FROM products DELETE FROM products
@ -298,6 +303,8 @@ class Database(object):
''', [product.id]) ''', [product.id])
def increment_consumption(self, user: User, product: Product, count: int = 1): def increment_consumption(self, user: User, product: Product, count: int = 1):
if product.id == -1:
raise ValueError('Invalid product ID')
with self.transaction() as c: with self.transaction() as c:
c.execute(''' c.execute('''
SELECT count SELECT count
@ -342,6 +349,8 @@ class Database(object):
}) })
def restock(self, product: Product, count: int): def restock(self, product: Product, count: int):
if product.id == -1:
raise ValueError('Invalid product ID')
with self.transaction() as c: with self.transaction() as c:
c.execute(''' c.execute('''
UPDATE products UPDATE products

View file

@ -49,11 +49,13 @@ class DatabaseTest(unittest.TestCase):
""" """
with self.db as db: with self.db as db:
with db.transaction() as c: with db.transaction() as c:
c.execute("INSERT INTO users VALUES (1, 'testuser', NULL, 'supersecurepassword', NULL, 1, 1, 0, NULL)") c.execute('''
INSERT INTO users VALUES (1, 'testuser', NULL, 'supersecurepassword', NULL, 1, 1, 0, 42)
''')
c = db._sqlite_db.cursor() c = db._sqlite_db.cursor()
c.execute("SELECT * FROM users") c.execute("SELECT * FROM users")
user = c.fetchone() user = c.fetchone()
self.assertEqual((1, 'testuser', None, 'supersecurepassword', None, 1, 1, 0, None), user) self.assertEqual((1, 'testuser', None, 'supersecurepassword', None, 1, 1, 0, 42), user)
def test_transaction_rollback(self): def test_transaction_rollback(self):
""" """
@ -63,7 +65,7 @@ class DatabaseTest(unittest.TestCase):
try: try:
with db.transaction() as c: with db.transaction() as c:
c.execute(""" c.execute("""
INSERT INTO users VALUES (1, 'testuser', NULL, 'supersecurepassword', NULL, 1, 1, 0, NULL) INSERT INTO users VALUES (1, 'testuser', NULL, 'supersecurepassword', NULL, 1, 1, 0, 42)
""") """)
raise ValueError('This should trigger a rollback') raise ValueError('This should trigger a rollback')
except ValueError as e: except ValueError as e:

View file

@ -6,8 +6,6 @@ class Product(object):
name: str, name: str,
price_member: int, price_member: int,
price_non_member: int): price_non_member: int):
if product_id == -1:
raise ValueError('Invalid product ID')
self._product_id: int = product_id self._product_id: int = product_id
self._name: str = name self._name: str = name
self._price_member: int = price_member self._price_member: int = price_member

View file

@ -2,7 +2,7 @@ from setuptools import setup
setup( setup(
name='matemat', name='matemat',
version='2.00', version='2.0',
packages=['matemat'], packages=['matemat'],
url='', url='',
license='', license='',