diff --git a/ereuse_devicehub/migrations/versions/378b6b147b46_nullable.py b/ereuse_devicehub/migrations/versions/378b6b147b46_nullable.py new file mode 100644 index 00000000..4bc48443 --- /dev/null +++ b/ereuse_devicehub/migrations/versions/378b6b147b46_nullable.py @@ -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 diff --git a/ereuse_devicehub/resources/action/schemas.py b/ereuse_devicehub/resources/action/schemas.py index 4d07d405..b29aa06a 100644 --- a/ereuse_devicehub/resources/action/schemas.py +++ b/ereuse_devicehub/resources/action/schemas.py @@ -260,9 +260,8 @@ class TestBios(Test): class VisualTest(Test): __doc__ = m.VisualTest.__doc__ - appearance_range = EnumField(AppearanceRange, required=True, data_key='appearanceRange') + appearance_range = EnumField(AppearanceRange, data_key='appearanceRange') functionality_range = EnumField(FunctionalityRange, - required=True, data_key='functionalityRange') labelling = Boolean() diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index af566eb9..87f673ce 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -342,19 +342,19 @@ class Device(Thing): class DisplayMixin: """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.""" technology = Column(DBEnum(DisplayTech)) technology.comment = """The technology the monitor uses to display the image. """ resolution_width = Column(SmallInteger, check_range('resolution_width', 10, 20000), - nullable=False) + nullable=True) resolution_width.comment = """The maximum horizontal resolution the monitor can natively support in pixels. """ resolution_height = Column(SmallInteger, check_range('resolution_height', 10, 20000), - nullable=False) + nullable=True) resolution_height.comment = """The maximum vertical resolution the monitor can natively support in pixels. """ @@ -370,7 +370,9 @@ class DisplayMixin: Regular values are ``4/3``, ``5/4``, ``16/9``, ``21/9``, ``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 @aspect_ratio.expression @@ -390,7 +392,9 @@ class DisplayMixin: return self.aspect_ratio > 4.001 / 3 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: v = '' @@ -398,7 +402,10 @@ class DisplayMixin: v += '{0.t} {0.model}'.format(self) if 's' in format_spec: 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 @@ -410,7 +417,7 @@ class Computer(Device): ``Server``. The property ``chassis`` defines it more granularly. """ 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. 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) deliverynote_address = db.Column(CIText(), nullable=True) - def __init__(self, chassis, **kwargs) -> None: - chassis = ComputerChassis(chassis) - super().__init__(chassis=chassis, **kwargs) + def __init__(self, *args, **kwargs) -> None: + if args: + chassis = ComputerChassis(args[0]) + super().__init__(chassis=chassis, **kwargs) + else: + super().__init__(*args, **kwargs) @property def actions(self) -> list: diff --git a/ereuse_devicehub/resources/device/schemas.py b/ereuse_devicehub/resources/device/schemas.py index d3671c1b..ea5b3211 100644 --- a/ereuse_devicehub/resources/device/schemas.py +++ b/ereuse_devicehub/resources/device/schemas.py @@ -101,7 +101,6 @@ class Computer(Device): collection_class=OrderedSet, description='The components that are inside this computer.') chassis = EnumField(enums.ComputerChassis, - required=True, description=m.Computer.chassis.comment) ram_size = Integer(dump_only=True, data_key='ramSize', @@ -149,17 +148,17 @@ class Server(Computer): class DisplayMixin: __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, description=m.DisplayMixin.technology.comment) resolution_width = Integer(data_key='resolutionWidth', validate=Range(10, 20000), description=m.DisplayMixin.resolution_width.comment, - required=True) + ) resolution_height = Integer(data_key='resolutionHeight', validate=Range(10, 20000), description=m.DisplayMixin.resolution_height.comment, - required=True) + ) refresh_rate = Integer(data_key='refreshRate', validate=Range(10, 1000)) contrast_ratio = Integer(data_key='contrastRatio', validate=Range(100, 100000)) touchable = Boolean(description=m.DisplayMixin.touchable.comment) diff --git a/ereuse_devicehub/resources/device/search.py b/ereuse_devicehub/resources/device/search.py index 381b5406..f8786d18 100644 --- a/ereuse_devicehub/resources/device/search.py +++ b/ereuse_devicehub/resources/device/search.py @@ -120,7 +120,6 @@ class DeviceSearch(db.Model): (db.func.string_agg(Comp.type, ' '), search.Weight.B), ('Computer', search.Weight.C), ('PC', search.Weight.C), - (inflection.humanize(device.chassis.name), search.Weight.B), )) properties = session \ diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index 278aa299..416b8afe 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -679,24 +679,17 @@ def test_snapshot_failed_missing_hdd_benchmark(app: Devicehub, user: UserClient) @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 """ tmp_snapshots = app.config['TMP_SNAPSHOTS'] 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'] - snapshot = {'software': '', 'version': '', 'uuid': ''} - with pytest.raises(TypeError): - user.post(res=Snapshot, data=snapshot_error) + snapshot, res = user.post(res=Snapshot, data=snapshot_error) - files = [x for x in os.listdir(path_dir_base) if uuid in x] - 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) + shutil.rmtree(tmp_snapshots) assert snapshot['software'] == snapshot_error['software'] assert snapshot['version'] == snapshot_error['version']