Merge pull request #94 from eReuse/change/#92-#93-drop-nullable
Change/#92 #93 drop nullable
This commit is contained in:
commit
43b6ad4401
|
@ -0,0 +1,41 @@
|
||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: 378b6b147b46
|
||||||
|
Revises: bf600ca861a4
|
||||||
|
Create Date: 2020-12-16 11:45:13.339624
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import context
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
import sqlalchemy_utils
|
||||||
|
import citext
|
||||||
|
import teal
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '378b6b147b46'
|
||||||
|
down_revision = 'bf600ca861a4'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def get_inv():
|
||||||
|
INV = context.get_x_argument(as_dictionary=True).get('inventory')
|
||||||
|
if not INV:
|
||||||
|
raise ValueError("Inventory value is not specified")
|
||||||
|
return INV
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.alter_column('computer', 'chassis', nullable=True, schema=f'{get_inv()}')
|
||||||
|
op.alter_column('display', 'size', nullable=True, schema=f'{get_inv()}')
|
||||||
|
op.alter_column('display', 'resolution_width', nullable=True, schema=f'{get_inv()}')
|
||||||
|
op.alter_column('display', 'resolution_height', nullable=True, schema=f'{get_inv()}')
|
||||||
|
op.alter_column('monitor', 'size', nullable=True, schema=f'{get_inv()}')
|
||||||
|
op.alter_column('monitor', 'resolution_width', nullable=True, schema=f'{get_inv()}')
|
||||||
|
op.alter_column('monitor', 'resolution_height', nullable=True, schema=f'{get_inv()}')
|
||||||
|
# pass
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
pass
|
|
@ -260,9 +260,8 @@ class TestBios(Test):
|
||||||
|
|
||||||
class VisualTest(Test):
|
class VisualTest(Test):
|
||||||
__doc__ = m.VisualTest.__doc__
|
__doc__ = m.VisualTest.__doc__
|
||||||
appearance_range = EnumField(AppearanceRange, required=True, data_key='appearanceRange')
|
appearance_range = EnumField(AppearanceRange, data_key='appearanceRange')
|
||||||
functionality_range = EnumField(FunctionalityRange,
|
functionality_range = EnumField(FunctionalityRange,
|
||||||
required=True,
|
|
||||||
data_key='functionalityRange')
|
data_key='functionalityRange')
|
||||||
labelling = Boolean()
|
labelling = Boolean()
|
||||||
|
|
||||||
|
|
|
@ -342,19 +342,19 @@ class Device(Thing):
|
||||||
|
|
||||||
class DisplayMixin:
|
class DisplayMixin:
|
||||||
"""Base class for the Display Component and the Monitor Device."""
|
"""Base class for the Display Component and the Monitor Device."""
|
||||||
size = Column(Float(decimal_return_scale=1), check_range('size', 2, 150), nullable=False)
|
size = Column(Float(decimal_return_scale=1), check_range('size', 2, 150), nullable=True)
|
||||||
size.comment = """The size of the monitor in inches."""
|
size.comment = """The size of the monitor in inches."""
|
||||||
technology = Column(DBEnum(DisplayTech))
|
technology = Column(DBEnum(DisplayTech))
|
||||||
technology.comment = """The technology the monitor uses to display
|
technology.comment = """The technology the monitor uses to display
|
||||||
the image.
|
the image.
|
||||||
"""
|
"""
|
||||||
resolution_width = Column(SmallInteger, check_range('resolution_width', 10, 20000),
|
resolution_width = Column(SmallInteger, check_range('resolution_width', 10, 20000),
|
||||||
nullable=False)
|
nullable=True)
|
||||||
resolution_width.comment = """The maximum horizontal resolution the
|
resolution_width.comment = """The maximum horizontal resolution the
|
||||||
monitor can natively support in pixels.
|
monitor can natively support in pixels.
|
||||||
"""
|
"""
|
||||||
resolution_height = Column(SmallInteger, check_range('resolution_height', 10, 20000),
|
resolution_height = Column(SmallInteger, check_range('resolution_height', 10, 20000),
|
||||||
nullable=False)
|
nullable=True)
|
||||||
resolution_height.comment = """The maximum vertical resolution the
|
resolution_height.comment = """The maximum vertical resolution the
|
||||||
monitor can natively support in pixels.
|
monitor can natively support in pixels.
|
||||||
"""
|
"""
|
||||||
|
@ -370,7 +370,9 @@ class DisplayMixin:
|
||||||
Regular values are ``4/3``, ``5/4``, ``16/9``, ``21/9``,
|
Regular values are ``4/3``, ``5/4``, ``16/9``, ``21/9``,
|
||||||
``14/10``, ``19/10``, ``16/10``.
|
``14/10``, ``19/10``, ``16/10``.
|
||||||
"""
|
"""
|
||||||
return Fraction(self.resolution_width, self.resolution_height)
|
if self.resolution_height and self.resolution_width:
|
||||||
|
return Fraction(self.resolution_width, self.resolution_height)
|
||||||
|
return 0
|
||||||
|
|
||||||
# noinspection PyUnresolvedReferences
|
# noinspection PyUnresolvedReferences
|
||||||
@aspect_ratio.expression
|
@aspect_ratio.expression
|
||||||
|
@ -390,7 +392,9 @@ class DisplayMixin:
|
||||||
return self.aspect_ratio > 4.001 / 3
|
return self.aspect_ratio > 4.001 / 3
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return '{0.t} {0.serial_number} {0.size}in ({0.aspect_ratio}) {0.technology}'.format(self)
|
if self.size:
|
||||||
|
return '{0.t} {0.serial_number} {0.size}in ({0.aspect_ratio}) {0.technology}'.format(self)
|
||||||
|
return '{0.t} {0.serial_number} 0in ({0.aspect_ratio}) {0.technology}'.format(self)
|
||||||
|
|
||||||
def __format__(self, format_spec: str) -> str:
|
def __format__(self, format_spec: str) -> str:
|
||||||
v = ''
|
v = ''
|
||||||
|
@ -398,7 +402,10 @@ class DisplayMixin:
|
||||||
v += '{0.t} {0.model}'.format(self)
|
v += '{0.t} {0.model}'.format(self)
|
||||||
if 's' in format_spec:
|
if 's' in format_spec:
|
||||||
v += '({0.manufacturer}) S/N {0.serial_number}'.format(self)
|
v += '({0.manufacturer}) S/N {0.serial_number}'.format(self)
|
||||||
v += '– {0.size}in ({0.aspect_ratio}) {0.technology}'.format(self)
|
if self.size:
|
||||||
|
v += '– {0.size}in ({0.aspect_ratio}) {0.technology}'.format(self)
|
||||||
|
else:
|
||||||
|
v += '– 0in ({0.aspect_ratio}) {0.technology}'.format(self)
|
||||||
return v
|
return v
|
||||||
|
|
||||||
|
|
||||||
|
@ -410,7 +417,7 @@ class Computer(Device):
|
||||||
``Server``. The property ``chassis`` defines it more granularly.
|
``Server``. The property ``chassis`` defines it more granularly.
|
||||||
"""
|
"""
|
||||||
id = Column(BigInteger, ForeignKey(Device.id), primary_key=True)
|
id = Column(BigInteger, ForeignKey(Device.id), primary_key=True)
|
||||||
chassis = Column(DBEnum(ComputerChassis), nullable=False)
|
chassis = Column(DBEnum(ComputerChassis), nullable=True)
|
||||||
chassis.comment = """The physical form of the computer.
|
chassis.comment = """The physical form of the computer.
|
||||||
|
|
||||||
It is a subset of the Linux definition of DMI / DMI decode.
|
It is a subset of the Linux definition of DMI / DMI decode.
|
||||||
|
@ -430,9 +437,12 @@ class Computer(Device):
|
||||||
receiver = db.relationship(User, primaryjoin=receiver_id == User.id)
|
receiver = db.relationship(User, primaryjoin=receiver_id == User.id)
|
||||||
deliverynote_address = db.Column(CIText(), nullable=True)
|
deliverynote_address = db.Column(CIText(), nullable=True)
|
||||||
|
|
||||||
def __init__(self, chassis, **kwargs) -> None:
|
def __init__(self, *args, **kwargs) -> None:
|
||||||
chassis = ComputerChassis(chassis)
|
if args:
|
||||||
super().__init__(chassis=chassis, **kwargs)
|
chassis = ComputerChassis(args[0])
|
||||||
|
super().__init__(chassis=chassis, **kwargs)
|
||||||
|
else:
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def actions(self) -> list:
|
def actions(self) -> list:
|
||||||
|
|
|
@ -101,7 +101,6 @@ class Computer(Device):
|
||||||
collection_class=OrderedSet,
|
collection_class=OrderedSet,
|
||||||
description='The components that are inside this computer.')
|
description='The components that are inside this computer.')
|
||||||
chassis = EnumField(enums.ComputerChassis,
|
chassis = EnumField(enums.ComputerChassis,
|
||||||
required=True,
|
|
||||||
description=m.Computer.chassis.comment)
|
description=m.Computer.chassis.comment)
|
||||||
ram_size = Integer(dump_only=True,
|
ram_size = Integer(dump_only=True,
|
||||||
data_key='ramSize',
|
data_key='ramSize',
|
||||||
|
@ -149,17 +148,17 @@ class Server(Computer):
|
||||||
|
|
||||||
class DisplayMixin:
|
class DisplayMixin:
|
||||||
__doc__ = m.DisplayMixin.__doc__
|
__doc__ = m.DisplayMixin.__doc__
|
||||||
size = Float(description=m.DisplayMixin.size.comment, validate=Range(2, 150), required=True)
|
size = Float(description=m.DisplayMixin.size.comment, validate=Range(2, 150))
|
||||||
technology = EnumField(enums.DisplayTech,
|
technology = EnumField(enums.DisplayTech,
|
||||||
description=m.DisplayMixin.technology.comment)
|
description=m.DisplayMixin.technology.comment)
|
||||||
resolution_width = Integer(data_key='resolutionWidth',
|
resolution_width = Integer(data_key='resolutionWidth',
|
||||||
validate=Range(10, 20000),
|
validate=Range(10, 20000),
|
||||||
description=m.DisplayMixin.resolution_width.comment,
|
description=m.DisplayMixin.resolution_width.comment,
|
||||||
required=True)
|
)
|
||||||
resolution_height = Integer(data_key='resolutionHeight',
|
resolution_height = Integer(data_key='resolutionHeight',
|
||||||
validate=Range(10, 20000),
|
validate=Range(10, 20000),
|
||||||
description=m.DisplayMixin.resolution_height.comment,
|
description=m.DisplayMixin.resolution_height.comment,
|
||||||
required=True)
|
)
|
||||||
refresh_rate = Integer(data_key='refreshRate', validate=Range(10, 1000))
|
refresh_rate = Integer(data_key='refreshRate', validate=Range(10, 1000))
|
||||||
contrast_ratio = Integer(data_key='contrastRatio', validate=Range(100, 100000))
|
contrast_ratio = Integer(data_key='contrastRatio', validate=Range(100, 100000))
|
||||||
touchable = Boolean(description=m.DisplayMixin.touchable.comment)
|
touchable = Boolean(description=m.DisplayMixin.touchable.comment)
|
||||||
|
|
|
@ -120,7 +120,6 @@ class DeviceSearch(db.Model):
|
||||||
(db.func.string_agg(Comp.type, ' '), search.Weight.B),
|
(db.func.string_agg(Comp.type, ' '), search.Weight.B),
|
||||||
('Computer', search.Weight.C),
|
('Computer', search.Weight.C),
|
||||||
('PC', search.Weight.C),
|
('PC', search.Weight.C),
|
||||||
(inflection.humanize(device.chassis.name), search.Weight.B),
|
|
||||||
))
|
))
|
||||||
|
|
||||||
properties = session \
|
properties = session \
|
||||||
|
|
|
@ -679,24 +679,17 @@ def test_snapshot_failed_missing_hdd_benchmark(app: Devicehub, user: UserClient)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.mvp
|
@pytest.mark.mvp
|
||||||
def test_snapshot_failed_null_chassis(app: Devicehub, user: UserClient):
|
def test_snapshot_not_failed_null_chassis(app: Devicehub, user: UserClient):
|
||||||
""" This test check if the file snapshot is create when some snapshot is wrong """
|
""" This test check if the file snapshot is create when some snapshot is wrong """
|
||||||
tmp_snapshots = app.config['TMP_SNAPSHOTS']
|
tmp_snapshots = app.config['TMP_SNAPSHOTS']
|
||||||
path_dir_base = os.path.join(tmp_snapshots, user.user['email'], 'errors')
|
path_dir_base = os.path.join(tmp_snapshots, user.user['email'], 'errors')
|
||||||
snapshot_error = file('failed.snapshot.422.null-chassis')
|
snapshot_error = file('desktop-9644w8n-lenovo-0169622.snapshot')
|
||||||
|
snapshot_error['device']['chassis'] = None
|
||||||
uuid = snapshot_error['uuid']
|
uuid = snapshot_error['uuid']
|
||||||
|
|
||||||
snapshot = {'software': '', 'version': '', 'uuid': ''}
|
snapshot, res = user.post(res=Snapshot, data=snapshot_error)
|
||||||
with pytest.raises(TypeError):
|
|
||||||
user.post(res=Snapshot, data=snapshot_error)
|
|
||||||
|
|
||||||
files = [x for x in os.listdir(path_dir_base) if uuid in x]
|
shutil.rmtree(tmp_snapshots)
|
||||||
if files:
|
|
||||||
path_snapshot = os.path.join(path_dir_base, files[0])
|
|
||||||
with open(path_snapshot) as file_snapshot:
|
|
||||||
snapshot = json.loads(file_snapshot.read())
|
|
||||||
|
|
||||||
shutil.rmtree(tmp_snapshots)
|
|
||||||
|
|
||||||
assert snapshot['software'] == snapshot_error['software']
|
assert snapshot['software'] == snapshot_error['software']
|
||||||
assert snapshot['version'] == snapshot_error['version']
|
assert snapshot['version'] == snapshot_error['version']
|
||||||
|
|
Reference in New Issue