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__/
*.pyc
**/*.egg-info/
*.coverage
*.sqlite3
*.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
import apsw
@ -276,6 +277,8 @@ class Database(object):
return Product(product_id, name, price_member, price_non_member)
def change_product(self, product: Product):
if product.id == -1:
raise ValueError('Invalid product ID')
with self.transaction() as c:
c.execute('''
UPDATE products
@ -291,6 +294,8 @@ class Database(object):
})
def delete_product(self, product: Product):
if product.id == -1:
raise ValueError('Invalid product ID')
with self.transaction() as c:
c.execute('''
DELETE FROM products
@ -298,6 +303,8 @@ class Database(object):
''', [product.id])
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:
c.execute('''
SELECT count
@ -342,6 +349,8 @@ class Database(object):
})
def restock(self, product: Product, count: int):
if product.id == -1:
raise ValueError('Invalid product ID')
with self.transaction() as c:
c.execute('''
UPDATE products

View file

@ -49,11 +49,13 @@ class DatabaseTest(unittest.TestCase):
"""
with self.db as db:
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.execute("SELECT * FROM users")
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):
"""
@ -63,7 +65,7 @@ class DatabaseTest(unittest.TestCase):
try:
with db.transaction() as c:
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')
except ValueError as e:

View file

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

View file

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