Added tests for Parts, Packages, PartTaype

This commit is contained in:
Julian Knauer 2020-05-11 20:19:10 +02:00
parent 48554ccf8b
commit aaac3a879a
2 changed files with 78 additions and 11 deletions

View File

@ -4,11 +4,15 @@ INSERT INTO users (username, password, email)
-- Part type
INSERT INTO types (label)
VALUES ('Transistor');
-- Package
INSERT INTO types (label)
VALUES ('Diode');
-- Package
INSERT INTO packages (label)
VALUES ('THT');
INSERT INTO packages (label)
VALUES ('TO-92');
-- Parts
INSERT INTO parts (name, description, value, stock, parttype_id, package_id, last_update)
VALUES ('BC547','NPN Epitaxial Silicon Transistor','',100,1,1,datetime('now'));
VALUES ('BC547','NPN Epitaxial Silicon Transistor','',100,1,2,datetime('now'));
INSERT INTO parts (name, description, value, stock, parttype_id, package_id, last_update)
VALUES ('LED','⌀:4,75mm','Red',12,2,2,datetime('now'));
VALUES ('LED','⌀:4,75mm','Red',12,2,1,datetime('now'));

View File

@ -1,26 +1,89 @@
from homebench import db
from homebench.parts.models import Part
from homebench.parts.models import Part, PartType, Package
def test_parts(app):
def test_part_add(app):
with app.app_context():
assert Part.query.count() == 2
part = Part(name='Test', description='Part test', value='empty',
stock=9000, package_id=2, parttype_id=2)
db.session.add(part)
db.session.commit()
assert Part.query.count() == 3
def test_work_with_part(app):
def test_part_update(app):
with app.app_context():
part = Part.query.filter_by(name='I Do not exist').first()
part = Part.query.filter_by(name='I do not exist').first()
assert not part
part = Part.query.filter_by(name='LED').first()
assert part
assert part.stock == 12
part.stock -= 1
assert part.stock == 11
part = Part.query.filter_by(name='LED').first()
assert part
part.name = 'I do exist'
part = Part.query.filter_by(name='I do exist').first()
assert part
def test_part_delete(app):
with app.app_context():
assert Part.query.count() == 2
part = Part.query.first()
db.session.delete(part)
assert Part.query.count() == 1
def test_parttype_add(app):
with app.app_context():
assert PartType.query.count() == 2
parttype = PartType(label='Test')
db.session.add(parttype)
assert PartType.query.count() == 3
def test_parttype_delete(app):
with app.app_context():
assert PartType.query.count() == 2
parttype = PartType.query.first()
db.session.delete(parttype)
assert PartType.query.count() == 1
def test_parttype_update(app):
with app.app_context():
parttype = PartType.query.filter_by(label='I do not exist').first()
assert not parttype
parttype = PartType.query.filter_by(label='Diode').first()
assert parttype
parttype.label = 'I do exist'
parttype = PartType.query.filter_by(label='I do exist').first()
assert parttype
def test_package_add(app):
with app.app_context():
assert Package.query.count() == 2
package = Package(label='Test')
db.session.add(package)
assert Package.query.count() == 3
def test_package_delete(app):
with app.app_context():
assert Package.query.count() == 2
package = Package.query.first()
db.session.delete(package)
assert Package.query.count() == 1
def test_package_update(app):
with app.app_context():
package = Package.query.filter_by(label='I do not exist').first()
assert not package
package = Package.query.filter_by(label='THT').first()
assert package
package.label = 'I do exist'
package = Package.query.filter_by(label='I do exist').first()
assert package