diff --git a/ereuse_devicehub/cli.py b/ereuse_devicehub/cli.py index 993d00f3..b99c0b5e 100644 --- a/ereuse_devicehub/cli.py +++ b/ereuse_devicehub/cli.py @@ -41,8 +41,7 @@ def get_version(ctx, param, value): @click.group(cls=DevicehubGroup, context_settings=Devicehub.cli_context_settings, add_version_option=False, - help=""" - Manages the Devicehub of the inventory {}. + help="""Manages the Devicehub of the inventory {}. Use 'export dhi=xx' to set the inventory that this CLI manages. For example 'export dhi=db1' and then executing diff --git a/ereuse_devicehub/client.py b/ereuse_devicehub/client.py index b7b38da1..3224dfd3 100644 --- a/ereuse_devicehub/client.py +++ b/ereuse_devicehub/client.py @@ -121,8 +121,7 @@ class Client(TealClient): class UserClient(Client): - """ - A client that identifies all of its requests with a specific user. + """A client that identifies all of its requests with a specific user. It will automatically perform login on the first request. """ diff --git a/ereuse_devicehub/config.py b/ereuse_devicehub/config.py index b471d135..dea5e2a5 100644 --- a/ereuse_devicehub/config.py +++ b/ereuse_devicehub/config.py @@ -26,8 +26,7 @@ class DevicehubConfig(Config): PASSWORD_SCHEMES = {'pbkdf2_sha256'} # type: Set[str] SQLALCHEMY_DATABASE_URI = 'postgresql://dhub:ereuse@localhost/devicehub' # type: str MIN_WORKBENCH = StrictVersion('11.0a1') # type: StrictVersion - """ - the minimum version of ereuse.org workbench that this devicehub + """The minimum version of ereuse.org workbench that this devicehub accepts. we recommend not changing this value. """ API_DOC_CONFIG_TITLE = 'Devicehub' @@ -42,6 +41,4 @@ class DevicehubConfig(Config): PRICE_SOFTWARE = PriceSoftware.Ereuse PRICE_VERSION = StrictVersion('1.0') PRICE_CURRENCY = Currency.EUR - """ - Official versions - """ + """Official versions.""" diff --git a/ereuse_devicehub/db.py b/ereuse_devicehub/db.py index 46f459c7..964de614 100644 --- a/ereuse_devicehub/db.py +++ b/ereuse_devicehub/db.py @@ -27,8 +27,7 @@ class DhSession(SchemaSession): class SQLAlchemy(SchemaSQLAlchemy): - """ - Superuser must create the required extensions in the public + """Superuser must create the required extensions in the public schema of the database, as it is in the `search_path` defined in teal. """ diff --git a/ereuse_devicehub/resources/action/models.py b/ereuse_devicehub/resources/action/models.py index 64b7fd8a..81576b6e 100644 --- a/ereuse_devicehub/resources/action/models.py +++ b/ereuse_devicehub/resources/action/models.py @@ -1,5 +1,4 @@ -""" -This file contains all actions can apply to a device and is sorted according +"""This file contains all actions can apply to a device and is sorted according to a structure based on: * Generic Actions @@ -72,34 +71,29 @@ class Action(Thing): id = Column(UUID(as_uuid=True), primary_key=True, default=uuid4) type = Column(Unicode, nullable=False) name = Column(CIText(), default='', nullable=False) - name.comment = """ - A name or title for the action. Used when searching for actions. + name.comment = """A name or title for the action. Used when searching + for actions. """ severity = Column(teal.db.IntEnum(Severity), default=Severity.Info, nullable=False) severity.comment = Severity.__doc__ closed = Column(Boolean, default=True, nullable=False) - closed.comment = """ - Whether the author has finished the action. - After this is set to True, no modifications are allowed. - By default actions are closed when performed. + closed.comment = """Whether the author has finished the action. + After this is set to True, no modifications are allowed. + By default actions are closed when performed. """ description = Column(Unicode, default='', nullable=False) - description.comment = """ - A comment about the action. - """ + description.comment = """A comment about the action.""" start_time = Column(db.TIMESTAMP(timezone=True)) - start_time.comment = """ - When the action starts. For some actions like reservations - the time when they are available, for others like renting - when the renting starts. + start_time.comment = """When the action starts. For some actions like + reservations the time when they are available, for others like renting + when the renting starts. """ end_time = Column(db.TIMESTAMP(timezone=True)) - end_time.comment = """ - When the action ends. For some actions like reservations - the time when they expire, for others like renting - the time the end rents. For punctual actions it is the time - they are performed; it differs with ``created`` in which - created is the where the system received the action. + end_time.comment = """When the action ends. For some actions like reservations + the time when they expire, for others like renting + the time the end rents. For punctual actions it is the time + they are performed; it differs with ``created`` in which + created is the where the system received the action. """ snapshot_id = Column(UUID(as_uuid=True), ForeignKey('snapshot.id', @@ -120,8 +114,7 @@ class Action(Thing): author = relationship(User, backref=backref('authored_actions', lazy=True, collection_class=set), primaryjoin=author_id == User.id) - author_id.comment = """ - The user that recorded this action in the system. + author_id.comment = """The user that recorded this action in the system. This does not necessarily has to be the person that produced the action in the real world. For that purpose see @@ -136,8 +129,8 @@ class Action(Thing): agent = relationship(Agent, backref=backref('actions_agent', lazy=True, **_sorted_actions), primaryjoin=agent_id == Agent.id) - agent_id.comment = """ - The direct performer or driver of the action. e.g. John wrote a book. + agent_id.comment = """The direct performer or driver of the action. + e.g. John wrote a book. It can differ with the user that registered the action in the system, which can be in their behalf. @@ -148,8 +141,7 @@ class Action(Thing): secondary=lambda: ActionComponent.__table__, order_by=lambda: Component.id, collection_class=OrderedSet) - components.comment = """ - The components that are affected by the action. + components.comment = """The components that are affected by the action. When performing actions to parent devices their components are affected too. @@ -165,9 +157,8 @@ class Action(Thing): parent = relationship(Computer, backref=backref('actions_parent', lazy=True, **_sorted_actions), primaryjoin=parent_id == Computer.id) - parent_id.comment = """ - For actions that are performed to components, the device parent - at that time. + parent_id.comment = """For actions that are performed to components, + the device parent at that time. For example: for a ``EraseBasic`` performed on a data storage, this would point to the computer that contained this data storage, if any. @@ -197,8 +188,7 @@ class Action(Thing): # noinspection PyMethodParameters @declared_attr def __mapper_args__(cls): - """ - Defines inheritance. + """Defines inheritance. From `the guide str: @@ -430,8 +419,7 @@ class Step(db.Model): # noinspection PyMethodParameters @declared_attr def __mapper_args__(cls): - """ - Defines inheritance. + """Defines inheritance. From `the guide str: @@ -578,8 +565,7 @@ class Benchmark(JoinedWithOneDeviceMixin, ActionWithOneDevice): @declared_attr def __mapper_args__(cls): - """ - Defines inheritance. + """Defines inheritance. From `the guide `_. """ shipping_date = Column(db.TIMESTAMP(timezone=True)) - shipping_date.comment = """ - When are the devices going to be ready for shipping? - """ + shipping_date.comment = """When are the devices going to be ready + for shipping? + """ invoice_number = Column(CIText()) - invoice_number.comment = """ - The id of the invoice so they can be linked. - """ + invoice_number.comment = """The id of the invoice so they can be linked.""" price_id = Column(UUID(as_uuid=True), ForeignKey(Price.id)) price = relationship(Price, backref=backref('trade', lazy=True, uselist=False), primaryjoin=price_id == Price.id) - price_id.comment = """ - The price set for this trade. - - If no price is set it is supposed that the trade was - not payed, usual in donations. + price_id.comment = """The price set for this trade. + If no price is set it is supposed that the trade was + not payed, usual in donations. """ to_id = Column(UUID(as_uuid=True), ForeignKey(Agent.id), nullable=False) # todo compute the org to = relationship(Agent, backref=backref('actions_to', lazy=True, **_sorted_actions), primaryjoin=to_id == Agent.id) - to_comment = """ - The agent that gets the device due this deal. - """ + to_comment = """The agent that gets the device due this deal.""" confirms_id = Column(UUID(as_uuid=True), ForeignKey(Organize.id)) confirms = relationship(Organize, backref=backref('confirmation', lazy=True, uselist=False), primaryjoin=confirms_id == Organize.id) - confirms_id.comment = """ - An organize action that this association confirms. - - For example, a ``Sell`` or ``Rent`` - can confirm a ``Reserve`` action. - """ + confirms_id.comment = """An organize action that this association confirms. + + For example, a ``Sell`` or ``Rent`` + can confirm a ``Reserve`` action. + """ class Sell(Trade): @@ -1482,8 +1487,7 @@ def actions_not_for_components(target: Action, value: Device, old_value, initiat @event.listens_for(ActionWithOneDevice.device, Events.set.__name__, propagate=True) def update_components_action_one(target: ActionWithOneDevice, device: Device, __, ___): - """ - Syncs the :attr:`.Action.components` with the components in + """Syncs the :attr:`.Action.components` with the components in :attr:`ereuse_devicehub.resources.device.models.Computer.components`. """ # For Add and Remove, ``components`` have different meanings @@ -1500,8 +1504,7 @@ def update_components_action_one(target: ActionWithOneDevice, device: Device, __ @event.listens_for(ActionWithMultipleDevices.devices, Events.append.__name__, propagate=True) def update_components_action_multiple(target: ActionWithMultipleDevices, value: Union[Set[Device], Device], _): - """ - Syncs the :attr:`.Action.components` with the components in + """Syncs the :attr:`.Action.components` with the components in :attr:`ereuse_devicehub.resources.device.models.Computer.components`. """ target.components.clear() @@ -1513,8 +1516,7 @@ def update_components_action_multiple(target: ActionWithMultipleDevices, @event.listens_for(ActionWithMultipleDevices.devices, Events.remove.__name__, propagate=True) def remove_components_action_multiple(target: ActionWithMultipleDevices, device: Device, __): - """ - Syncs the :attr:`.Action.components` with the components in + """Syncs the :attr:`.Action.components` with the components in :attr:`ereuse_devicehub.resources.device.models.Computer.components`. """ target.components.clear() @@ -1528,9 +1530,7 @@ def remove_components_action_multiple(target: ActionWithMultipleDevices, device: @event.listens_for(Install.device, Events.set.__name__, propagate=True) @event.listens_for(Benchmark.device, Events.set.__name__, propagate=True) def update_parent(target: Union[EraseBasic, Test, Install], device: Device, _, __): - """ - Syncs the :attr:`Action.parent` with the parent of the device. - """ + """Syncs the :attr:`Action.parent` with the parent of the device.""" target.parent = None if isinstance(device, Component): target.parent = device.parent diff --git a/ereuse_devicehub/resources/action/rate/rate.py b/ereuse_devicehub/resources/action/rate/rate.py index 3e11cb9f..5a132a3b 100644 --- a/ereuse_devicehub/resources/action/rate/rate.py +++ b/ereuse_devicehub/resources/action/rate/rate.py @@ -1,22 +1,23 @@ -import math from typing import Iterable +import math + from ereuse_devicehub.resources.device.models import Device class BaseRate: - """growing exponential from this value""" + """Growing exponential from this value.""" CEXP = 0 - """growing lineal starting on this value""" + """Growing lineal starting on this value.""" CLIN = 242 - """growing logarithmic starting on this value""" + """Growing logarithmic starting on this value.""" CLOG = 0.5 - """Processor has 50% of weight over total score, used in harmonic mean""" + """Processor has 50% of weight over total score, used in harmonic mean.""" PROCESSOR_WEIGHT = 0.5 - """Storage has 20% of weight over total score, used in harmonic mean""" + """Storage has 20% of weight over total score, used in harmonic mean.""" DATA_STORAGE_WEIGHT = 0.2 - """Ram has 30% of weight over total score, used in harmonic mean""" + """Ram has 30% of weight over total score, used in harmonic mean.""" RAM_WEIGHT = 0.3 def compute(self, device: Device): @@ -43,9 +44,7 @@ class BaseRate: return sum(weights) / sum(char / rate for char, rate in zip(weights, rates)) def harmonic_mean_rates(self, rate_processor, rate_storage, rate_ram): - """ - Merging components - """ + """Merging components using harmonic formula.""" total_weights = self.PROCESSOR_WEIGHT + self.DATA_STORAGE_WEIGHT + self.RAM_WEIGHT total_rate = self.PROCESSOR_WEIGHT / rate_processor \ + self.DATA_STORAGE_WEIGHT / rate_storage \ diff --git a/ereuse_devicehub/resources/action/rate/v1_0.py b/ereuse_devicehub/resources/action/rate/v1_0.py index eb1050f7..b29bcafa 100644 --- a/ereuse_devicehub/resources/action/rate/v1_0.py +++ b/ereuse_devicehub/resources/action/rate/v1_0.py @@ -13,14 +13,15 @@ class RateAlgorithm(BaseRate): """The algorithm that generates the Rate v1.0. Rate v1.0 rates only computers, counting their processor, ram, - data storage, appearance, and functionality. This rate is only + data storage, appearance and functionality. This rate is only triggered by a Snapshot from Workbench that has a VisualTest. The algorithm is as follows: 1. Specialized subclasses of :class:`BaseRate` compute a rating for each component. To perform this, each class normalizes first the characteristics and benchmarks of the components between - 0 and 1, and then they merge the values to a resulting score. + 0 and 1, and then they merge the values with specific formulas for + each components to get a resulting score. The classes are: * :class:`ProcessorRate`, using cores, speed, and ``BenchmarkProcessor``. @@ -103,9 +104,7 @@ class RateAlgorithm(BaseRate): class ProcessorRate(BaseRate): - """ - Calculate a ProcessorRate of all Processor devices - """ + """Calculate a ProcessorRate of all Processor devices.""" # processor.xMin, processor.xMax PROCESSOR_NORM = 3196.17, 17503.81 @@ -115,10 +114,10 @@ class ProcessorRate(BaseRate): DEFAULT_SCORE = 4000 def compute(self, processor: Processor): - """ Compute processor rate - We assume always exists a Benchmark Processor - Obs: cores and speed are possible NULL value - :return: result is a rate (score) of Processor characteristics + """Compute processor rate + We assume always exists a Benchmark Processor. + Obs: cores and speed are possible NULL value + :return: result is a rate (score) of Processor characteristics """ cores = processor.cores or self.DEFAULT_CORES speed = processor.speed or self.DEFAULT_SPEED @@ -146,9 +145,7 @@ class ProcessorRate(BaseRate): class RamRate(BaseRate): - """ - Calculate a RamRate of all RamModule devices - """ + """Calculate a RamRate of all RamModule devices.""" # ram.size.xMin; ram.size.xMax SIZE_NORM = 256, 8192 RAM_SPEED_NORM = 133, 1333 @@ -158,8 +155,7 @@ class RamRate(BaseRate): RAM_WEIGHTS = 0.7, 0.3 def compute(self, ram_devices: Iterable[RamModule]): - """ - If ram speed or ram size, we assume default values before declared + """If ram speed or ram size, we assume default values before declared. :return: result is a rate (score) of all RamModule components """ size = 0.0 @@ -204,9 +200,7 @@ class RamRate(BaseRate): class DataStorageRate(BaseRate): - """ - Calculate the rate of all DataStorage devices - """ + """Calculate the rate of all DataStorage devices.""" # drive.size.xMin; drive.size.xMax SIZE_NORM = 4, 265000 READ_SPEED_NORM = 2.7, 109.5 @@ -215,8 +209,7 @@ class DataStorageRate(BaseRate): DATA_STORAGE_WEIGHTS = 0.5, 0.25, 0.25 def compute(self, data_storage_devices: Iterable[DataStorage]): - """ - Obs: size != NULL and 0 value & read_speed and write_speed != NULL + """Obs: size != NULL and 0 value & read_speed and write_speed != NULL :return: result is a rate (score) of all DataStorage devices """ size = 0 diff --git a/ereuse_devicehub/resources/action/views.py b/ereuse_devicehub/resources/action/views.py index c844b2fc..de6805b4 100644 --- a/ereuse_devicehub/resources/action/views.py +++ b/ereuse_devicehub/resources/action/views.py @@ -46,8 +46,7 @@ class ActionView(View): return self.schema.jsonify(action) def snapshot(self, snapshot_json: dict, resource_def): - """ - Performs a Snapshot. + """Performs a Snapshot. See `Snapshot` section in docs for more info. """ diff --git a/ereuse_devicehub/resources/agent/models.py b/ereuse_devicehub/resources/agent/models.py index 6763ccca..ab9e073a 100644 --- a/ereuse_devicehub/resources/agent/models.py +++ b/ereuse_devicehub/resources/agent/models.py @@ -29,18 +29,13 @@ class Agent(Thing): id = Column(UUID(as_uuid=True), primary_key=True, default=uuid4) type = Column(Unicode, nullable=False) name = Column(CIText()) - name.comment = """ - The name of the organization or person. - """ + name.comment = """The name of the organization or person.""" tax_id = Column(Unicode(length=STR_SM_SIZE), check_lower('tax_id')) - tax_id.comment = """ - The Tax / Fiscal ID of the organization, - e.g. the TIN in the US or the CIF/NIF in Spain. + tax_id.comment = """The Tax / Fiscal ID of the organization, + e.g. the TIN in the US or the CIF/NIF in Spain. """ country = Column(DBEnum(enums.Country)) - country.comment = """ - Country issuing the tax_id number. - """ + country.comment = """Country issuing the tax_id number.""" telephone = Column(PhoneNumberType()) email = Column(EmailType, unique=True) @@ -52,8 +47,7 @@ class Agent(Thing): @declared_attr def __mapper_args__(cls): - """ - Defines inheritance. + """Defines inheritance. From `the guide list: - """ - All the actions where the device participated, including: + """All the actions where the device participated, including: 1. Actions performed directly to the device. 2. Actions performed to a component. @@ -170,8 +158,7 @@ class Device(Thing): @property def physical_properties(self) -> Dict[str, object or None]: - """ - Fields that describe the physical properties of a device. + """Fields that describe the physical properties of a device. :return A generator where each value is a tuple with tho fields: - Column. @@ -259,8 +246,7 @@ class Device(Thing): @declared_attr def __mapper_args__(cls): - """ - Defines inheritance. + """Defines inheritance. From `the guide 'Component': - """ - Gets a component that: - - has the same parent. - - Doesn't generate HID. - - Has same physical properties. + """Gets a component that: + + * has the same parent. + * Doesn't generate HID. + * Has same physical properties. :param parent: :param blacklist: A set of components to not to consider when looking for similar ones. @@ -573,17 +556,13 @@ class JoinedComponentTableMixin: class GraphicCard(JoinedComponentTableMixin, Component): memory = Column(SmallInteger, check_range('memory', min=1, max=10000)) - memory.comment = """ - The amount of memory of the Graphic Card in MB. - """ + memory.comment = """The amount of memory of the Graphic Card in MB.""" class DataStorage(JoinedComponentTableMixin, Component): """A device that stores information.""" size = Column(Integer, check_range('size', min=1, max=10 ** 8)) - size.comment = """ - The size of the data-storage in MB. - """ + size.comment = """The size of the data-storage in MB.""" interface = Column(DBEnum(DataStorageInterface)) @property @@ -616,9 +595,7 @@ class SolidStateDrive(DataStorage): class Motherboard(JoinedComponentTableMixin, Component): slots = Column(SmallInteger, check_range('slots', min=0)) - slots.comment = """ - PCI slots the motherboard has. - """ + slots.comment = """PCI slots the motherboard has.""" usb = Column(SmallInteger, check_range('usb', min=0)) firewire = Column(SmallInteger, check_range('firewire', min=0)) serial = Column(SmallInteger, check_range('serial', min=0)) @@ -629,13 +606,11 @@ class Motherboard(JoinedComponentTableMixin, Component): class NetworkMixin: speed = Column(SmallInteger, check_range('speed', min=10, max=10000)) - speed.comment = """ - The maximum speed this network adapter can handle, in mbps. + speed.comment = """The maximum speed this network adapter can handle, + in mbps. """ wireless = Column(Boolean, nullable=False, default=False) - wireless.comment = """ - Whether it is a wireless interface. - """ + wireless.comment = """Whether it is a wireless interface.""" def __format__(self, format_spec): v = super().__format__(format_spec) @@ -676,8 +651,7 @@ class SoundCard(JoinedComponentTableMixin, Component): class Display(JoinedComponentTableMixin, DisplayMixin, Component): - """ - The display of a device. This is used in all devices that have + """The display of a device. This is used in all devices that have displays but that it is not their main part, like laptops, mobiles, smart-watches, and so on; excluding ``ComputerMonitor`` and ``TelevisionSet``. diff --git a/ereuse_devicehub/resources/device/states.py b/ereuse_devicehub/resources/device/states.py index de72bf0f..bc69c664 100644 --- a/ereuse_devicehub/resources/device/states.py +++ b/ereuse_devicehub/resources/device/states.py @@ -20,8 +20,7 @@ class State(Enum): class Trading(State): - """ - Trading states. + """Trading states. :cvar Reserved: The device has been reserved. :cvar Cancelled: The device has been cancelled. @@ -44,8 +43,7 @@ class Trading(State): class Physical(State): - """ - Physical states. + """Physical states. :cvar ToBeRepaired: The device has been selected for reparation. :cvar Repaired: The device has been repaired. diff --git a/ereuse_devicehub/resources/device/static/ereuse-logo.svg b/ereuse_devicehub/resources/device/static/ereuse-logo.svg index 9c9608ab..605195fb 100644 --- a/ereuse_devicehub/resources/device/static/ereuse-logo.svg +++ b/ereuse_devicehub/resources/device/static/ereuse-logo.svg @@ -1,3 +1,40 @@ - + + + + + + + diff --git a/ereuse_devicehub/resources/device/static/magrama.svg b/ereuse_devicehub/resources/device/static/magrama.svg index b792c830..e50d7126 100644 --- a/ereuse_devicehub/resources/device/static/magrama.svg +++ b/ereuse_devicehub/resources/device/static/magrama.svg @@ -1,3 +1,195 @@ -PlataformaRAEE08006417910000001670001COCINAS41*Grandesaparatosconcomponentespeligrosos + + + + + P + l + a + t + a + f + o + r + m + a + R + A + E + E + 08006 + 4 + 17910 + 0 + 00001 + 6 + 70001 + C + O + C + I + N + A + S + 41* + G + r + a + n + d + e + s + a + p + a + r + a + t + os + c + o + n + c + o + m + p + o + n + e + nt + e + s + p + e + li + g + r + oso + s + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ereuse_devicehub/resources/device/static/photochromic-alone.svg b/ereuse_devicehub/resources/device/static/photochromic-alone.svg index 95cf4353..b3a873e7 100644 --- a/ereuse_devicehub/resources/device/static/photochromic-alone.svg +++ b/ereuse_devicehub/resources/device/static/photochromic-alone.svg @@ -1,3 +1,17 @@ - + + + + + + + + diff --git a/ereuse_devicehub/resources/device/static/photochromic-tag-web.svg b/ereuse_devicehub/resources/device/static/photochromic-tag-web.svg index 82ffafca..262ad79e 100644 --- a/ereuse_devicehub/resources/device/static/photochromic-tag-web.svg +++ b/ereuse_devicehub/resources/device/static/photochromic-tag-web.svg @@ -1,3 +1,34 @@ -6s + + + 6s + + + + + + + + + + + + + + diff --git a/ereuse_devicehub/resources/device/sync.py b/ereuse_devicehub/resources/device/sync.py index 39468854..a299f801 100644 --- a/ereuse_devicehub/resources/device/sync.py +++ b/ereuse_devicehub/resources/device/sync.py @@ -23,8 +23,7 @@ class Sync: def run(self, device: Device, components: Iterable[Component] or None) -> (Device, OrderedSet): - """ - Synchronizes the device and components with the database. + """Synchronizes the device and components with the database. Identifies if the device and components exist in the database and updates / inserts them as necessary. @@ -79,8 +78,7 @@ class Sync: component: Component, blacklist: Set[int], parent: Computer): - """ - Synchronizes one component to the DB. + """Synchronizes one component to the DB. This method is a specialization of :meth:`.execute_register` but for components that are inside parents. @@ -125,8 +123,7 @@ class Sync: return db_component, is_new def execute_register(self, device: Device) -> Device: - """ - Synchronizes one device to the DB. + """Synchronizes one device to the DB. This method tries to get an existing device using the HID or one of the tags, and... @@ -205,8 +202,7 @@ class Sync: @staticmethod def merge(device: Device, db_device: Device): - """ - Copies the physical properties of the device to the db_device. + """Copies the physical properties of the device to the db_device. This method mutates db_device. """ @@ -217,8 +213,7 @@ class Sync: @staticmethod def add_remove(device: Computer, components: Set[Component]) -> OrderedSet: - """ - Generates the Add and Remove actions (but doesn't add them to + """Generates the Add and Remove actions (but doesn't add them to session). :param device: A device which ``components`` attribute contains diff --git a/ereuse_devicehub/resources/device/templates/devices/layout.html b/ereuse_devicehub/resources/device/templates/devices/layout.html index 99846a8b..afd62ae9 100644 --- a/ereuse_devicehub/resources/device/templates/devices/layout.html +++ b/ereuse_devicehub/resources/device/templates/devices/layout.html @@ -2,222 +2,222 @@ - - - - Devicehub | {{ device.__format__('t') }} + + + + Devicehub | {{ device.__format__('t') }}
- +
- +
-

- This is your {{ device.t }}. -

+

+ This is your {{ device.t }}. +

-

- {% if device.trading %} - {{ device.trading }} - {% endif %} - {% if device.trading and device.physical %} - and - {% endif %} - {% if device.physical %} - {{ device.physical }} - {% endif %} -

-
-
-

You can verify the originality of your device.

-

- If your device comes with the following tag - - it means it has been refurbished by an eReuse.org - certified organization. -

-

- The tag is special –illuminate it with the torch of - your phone for 6 seconds and it will react like in - the following image: - - This is proof that this device is genuine. -

-
-
-

These are the specifications

-
- - - - - - - - - {% if device.processor_model %} - - - - - {% endif %} - {% if device.ram_size %} - - - - - {% endif %} - {% if device.data_storage_size %} - - - - - {% endif %} - {% if device.graphic_card_model %} - - - - - {% endif %} - {% if device.network_speeds %} - - - - - {% endif %} - {% if device.rate %} - - - - - {% endif %} - {% if device.rate and device.rate.price %} - - - - - {% endif %} - {% if device.price %} - - - - - {% endif %} - -
Range
- CPU – {{ device.processor_model }} - - {% if device.rate %} - {{ device.rate.processor_range }} - ({{ device.rate.processor }}) - {% endif %} -
- RAM – {{ device.ram_size // 1000 }} GB - {{ macros.component_type(device.components, 'RamModule') }} - - {% if device.rate %} - {{ device.rate.ram_range }} - ({{ device.rate.ram }}) - {% endif %} -
- Data Storage – {{ device.data_storage_size // 1000 }} GB - {{ macros.component_type(device.components, 'SolidStateDrive') }} - {{ macros.component_type(device.components, 'HardDrive') }} - - {% if device.rate %} - {{ device.rate.data_storage_range }} - ({{ device.rate.data_storage }}) - {% endif %} -
- Graphics – {{ device.graphic_card_model }} - {{ macros.component_type(device.components, 'GraphicCard') }} -
- Network – - {% if device.network_speeds[0] %} - Ethernet - {% if device.network_speeds[0] != None %} - max. {{ device.network_speeds[0] }} Mbps - {% endif %} - {% endif %} - {% if device.network_speeds[0] and device.network_speeds[1] %} - + - {% endif %} - {% if device.network_speeds[1] %} - WiFi - {% if device.network_speeds[1] != None %} - max. {{ device.network_speeds[1] }} Mbps - {% endif %} - {% endif %} - {{ macros.component_type(device.components, 'NetworkAdapter') }} -
- Total rate - - {{ device.rate.rating_range }} - ({{ device.rate.rating }}) -
- Algorithm price - - {{ device.rate.price }} -
- Actual price - - {{ device.price }} -
-
-

This is the traceability log of your device

-
- Latest one. -
-
    - {% for action in device.actions|reverse %} -
  1. - - {{ action.type }} - - — - {{ action }} -
    -
    - - {{ action._date_str }} - +

    + {% if device.trading %} + {{ device.trading }} + {% endif %} + {% if device.trading and device.physical %} + and + {% endif %} + {% if device.physical %} + {{ device.physical }} + {% endif %} +

    +
    +
    +

    You can verify the originality of your device.

    +

    + If your device comes with the following tag + + it means it has been refurbished by an eReuse.org + certified organization. +

    +

    + The tag is special –illuminate it with the torch of + your phone for 6 seconds and it will react like in + the following image: + + This is proof that this device is genuine. +

    +
    +
    +

    These are the specifications

    +
    + + + + + + + + + {% if device.processor_model %} + + + + + {% endif %} + {% if device.ram_size %} + + + + + {% endif %} + {% if device.data_storage_size %} + + + + + {% endif %} + {% if device.graphic_card_model %} + + + + + {% endif %} + {% if device.network_speeds %} + + + + + {% endif %} + {% if device.rate %} + + + + + {% endif %} + {% if device.rate and device.rate.price %} + + + + + {% endif %} + {% if device.price %} + + + + + {% endif %} + +
    Range
    + CPU – {{ device.processor_model }} + + {% if device.rate %} + {{ device.rate.processor_range }} + ({{ device.rate.processor }}) + {% endif %} +
    + RAM – {{ device.ram_size // 1000 }} GB + {{ macros.component_type(device.components, 'RamModule') }} + + {% if device.rate %} + {{ device.rate.ram_range }} + ({{ device.rate.ram }}) + {% endif %} +
    + Data Storage – {{ device.data_storage_size // 1000 }} GB + {{ macros.component_type(device.components, 'SolidStateDrive') }} + {{ macros.component_type(device.components, 'HardDrive') }} + + {% if device.rate %} + {{ device.rate.data_storage_range }} + ({{ device.rate.data_storage }}) + {% endif %} +
    + Graphics – {{ device.graphic_card_model }} + {{ macros.component_type(device.components, 'GraphicCard') }} +
    + Network – + {% if device.network_speeds[0] %} + Ethernet + {% if device.network_speeds[0] != None %} + max. {{ device.network_speeds[0] }} Mbps + {% endif %} + {% endif %} + {% if device.network_speeds[0] and device.network_speeds[1] %} + + + {% endif %} + {% if device.network_speeds[1] %} + WiFi + {% if device.network_speeds[1] != None %} + max. {{ device.network_speeds[1] }} Mbps + {% endif %} + {% endif %} + {{ macros.component_type(device.components, 'NetworkAdapter') }} +
    + Total rate + + {{ device.rate.rating_range }} + ({{ device.rate.rating }}) +
    + Algorithm price + + {{ device.rate.price }} +
    + Actual price + + {{ device.price }} +
    - {% if action.certificate %} - See the certificate - {% endif %} -
  2. - {% endfor %} -
-
- Oldest one. -
-
-
+

This is the traceability log of your device

+
+ Latest one. +
+
    + {% for action in device.actions|reverse %} +
  1. + + {{ action.type }} + + — + {{ action }} +
    +
    + + {{ action._date_str }} + +
    + {% if action.certificate %} + See the certificate + {% endif %} +
  2. + {% endfor %} +
+
+ Oldest one. +
+ +
diff --git a/ereuse_devicehub/resources/device/templates/devices/macros.html b/ereuse_devicehub/resources/device/templates/devices/macros.html index fdd9d5e7..9d13c11b 100644 --- a/ereuse_devicehub/resources/device/templates/devices/macros.html +++ b/ereuse_devicehub/resources/device/templates/devices/macros.html @@ -1,18 +1,18 @@ {% macro component_type(components, type) %} -
    - {% for c in components if c.t == type %} -
  • - {{ c.__format__('t') }} -

    - {{ c.__format__('s') }} -

    -
  • - {% endfor %} -
+
    + {% for c in components if c.t == type %} +
  • + {{ c.__format__('t') }} +

    + {{ c.__format__('s') }} +

    +
  • + {% endfor %} +
{% endmacro %} {% macro rate(range) %} - + {{ range }} {% endmacro %} diff --git a/ereuse_devicehub/resources/device/views.py b/ereuse_devicehub/resources/device/views.py index 58907ff1..61d1555b 100644 --- a/ereuse_devicehub/resources/device/views.py +++ b/ereuse_devicehub/resources/device/views.py @@ -78,8 +78,7 @@ class DeviceView(View): page = f.Integer(validate=v.Range(min=1), missing=1) def get(self, id): - """ - Devices view + """Devices view --- description: Gets a device or multiple devices. parameters: diff --git a/ereuse_devicehub/resources/documents/device_row.py b/ereuse_devicehub/resources/documents/device_row.py index 4ced847e..f81a727a 100644 --- a/ereuse_devicehub/resources/documents/device_row.py +++ b/ereuse_devicehub/resources/documents/device_row.py @@ -56,9 +56,7 @@ class DeviceRow(OrderedDict): self.components() def components(self): - """ - Function to get all components information of a device - """ + """Function to get all components information of a device.""" assert isinstance(self.device, d.Computer) # todo put an input specific order (non alphabetic) & where are a list of types components for type in sorted(current_app.resources[d.Component.t].subresources_types): # type: str @@ -75,8 +73,8 @@ class DeviceRow(OrderedDict): i += 1 def fill_component(self, type, i, component=None): - """ - Function to put specific information of components in OrderedDict (csv) + """Function to put specific information of components + in OrderedDict (csv) :param type: type of component :param component: device.components """ @@ -85,11 +83,13 @@ class DeviceRow(OrderedDict): self['{} {} Model'.format(type, i)] = component.serial_number if component else '' self['{} {} Serial Number'.format(type, i)] = component.serial_number if component else '' - """ Particular fields for component GraphicCard """ + """Particular fields for component GraphicCard.""" if isinstance(component, d.GraphicCard): self['{} {} Memory (MB)'.format(type, i)] = component.memory - """ Particular fields for component DataStorage.t -> (HardDrive, SolidStateDrive) """ + """Particular fields for component DataStorage.t -> + (HardDrive, SolidStateDrive) + """ if isinstance(component, d.DataStorage): self['{} {} Size (MB)'.format(type, i)] = component.size self['{} {} Privacy'.format(type, i)] = component.privacy @@ -109,16 +109,14 @@ class DeviceRow(OrderedDict): except: self['{} {} Writing speed'.format(type, i)] = '' - """ Particular fields for component Processor """ + """Particular fields for component Processor.""" if isinstance(component, d.Processor): self['{} {} Number of cores'.format(type, i)] = component.cores self['{} {} Speed (GHz)'.format(type, i)] = component.speed - """ Particular fields for component RamModule """ + """Particular fields for component RamModule.""" if isinstance(component, d.RamModule): self['{} {} Size (MB)'.format(type, i)] = component.size self['{} {} Speed (MHz)'.format(type, i)] = component.speed - # todo add Display size, ... - # todo add NetworkAdapter speedLink? - # todo add some ComputerAccessories + # todo add Display, NetworkAdapter, etc... diff --git a/ereuse_devicehub/resources/documents/documents.py b/ereuse_devicehub/resources/documents/documents.py index dd5ee1c8..e95a9694 100644 --- a/ereuse_devicehub/resources/documents/documents.py +++ b/ereuse_devicehub/resources/documents/documents.py @@ -110,11 +110,7 @@ class DevicesDocumentView(DeviceView): return self.generate_post_csv(query) def generate_post_csv(self, query): - """ - Get device query and put information in csv format - :param query: - :return: - """ + """Get device query and put information in csv format.""" data = StringIO() cw = csv.writer(data) first = True diff --git a/ereuse_devicehub/resources/documents/templates/documents/erasure.html b/ereuse_devicehub/resources/documents/templates/documents/erasure.html index 518358df..d6554dab 100644 --- a/ereuse_devicehub/resources/documents/templates/documents/erasure.html +++ b/ereuse_devicehub/resources/documents/templates/documents/erasure.html @@ -1,95 +1,95 @@ {% extends "documents/layout.html" %} {% block body %} -
-

Resumé

- - - - - - - - - - - - - {% for erasure in erasures %} - - {% if erasure.parent.serial_number %} - - {% else %} - - {% endif %} - - - - - - - {% endfor %} - -
S/NTagsS/N Data StorageType of erasureResultDate
- {{ erasure.parent.serial_number.upper() }} - - {{ erasure.parent.tags.__format__('') }} - - {{ erasure.device.serial_number.upper() }} - - {{ erasure.type }} - - {{ erasure.severity }} - - {{ erasure.date_str }} -
-
-
-

Details

- {% for erasure in erasures %} -
-

{{ erasure.device.__format__('t') }}

+
+

Resumé

+ + + + + + + + + + + + + {% for erasure in erasures %} + + {% if erasure.parent.serial_number %} + + {% else %} + + {% endif %} + + + + + + + {% endfor %} + +
S/NTagsS/N Data StorageType of erasureResultDate
+ {{ erasure.parent.serial_number.upper() }} + + {{ erasure.parent.tags.__format__('') }} + + {{ erasure.device.serial_number.upper() }} + + {{ erasure.type }} + + {{ erasure.severity }} + + {{ erasure.date_str }} +
+
+
+

Details

+ {% for erasure in erasures %} +
+

{{ erasure.device.__format__('t') }}

+
+
Data storage:
+
{{ erasure.device.__format__('ts') }}
+
Computer:
+
{{ erasure.parent.__format__('ts') }}
+
Tags:
+
{{ erasure.parent.tags }}
+
Erasure:
+
{{ erasure.__format__('ts') }}
+ {% if erasure.steps %} +
Erasure steps:
+
+
    + {% for step in erasure.steps %} +
  1. {{ step.__format__('') }}
  2. + {% endfor %} +
+
+ {% endif %} +
+
+ {% endfor %} +
+
+

Glossary

-
Data storage:
-
{{ erasure.device.__format__('ts') }}
-
Computer:
-
{{ erasure.parent.__format__('ts') }}
-
Tags:
-
{{ erasure.parent.tags }}
-
Erasure:
-
{{ erasure.__format__('ts') }}
- {% if erasure.steps %} -
Erasure steps:
+
Erase Basic
-
    - {% for step in erasure.steps %} -
  1. {{ step.__format__('') }}
  2. - {% endfor %} -
+ A software-based fast non-100%-secured way of erasing data storage, + using shred. +
+
Erase Sectors
+
+ A secured-way of erasing data storages, checking sector-by-sector + the erasure, using badblocks.
- {% endif %}
-
- {% endfor %} -
-
-

Glossary

-
-
Erase Basic
-
- A software-based fast non-100%-secured way of erasing data storage, - using shred. -
-
Erase Sectors
-
- A secured-way of erasing data storages, checking sector-by-sector - the erasure, using badblocks. -
-
-
- - +
+ + {% endblock %} diff --git a/ereuse_devicehub/resources/documents/templates/documents/layout.html b/ereuse_devicehub/resources/documents/templates/documents/layout.html index 5bf2aa56..45f16861 100644 --- a/ereuse_devicehub/resources/documents/templates/documents/layout.html +++ b/ereuse_devicehub/resources/documents/templates/documents/layout.html @@ -2,25 +2,25 @@ - - - - - Devicehub | {{ title }} + + + + + Devicehub | {{ title }}
-
- -
- {% block body %}{% endblock %} +
+ +
+ {% block body %}{% endblock %}
diff --git a/ereuse_devicehub/resources/lot/models.py b/ereuse_devicehub/resources/lot/models.py index f7ec096f..5d08ab88 100644 --- a/ereuse_devicehub/resources/lot/models.py +++ b/ereuse_devicehub/resources/lot/models.py @@ -24,16 +24,13 @@ class Lot(Thing): description = db.Column(CIText()) description.comment = """A comment about the lot.""" closed = db.Column(db.Boolean, default=False, nullable=False) - closed.comment = """ - A closed lot cannot be modified anymore. - """ + closed.comment = """A closed lot cannot be modified anymore.""" devices = db.relationship(Device, backref=db.backref('lots', lazy=True, collection_class=set), secondary=lambda: LotDevice.__table__, lazy=True, collection_class=set) - """ - The **children** devices that the lot has. + """The **children** devices that the lot has. Note that the lot can have more devices, if they are inside descendant lots. @@ -67,8 +64,7 @@ class Lot(Thing): def __init__(self, name: str, closed: bool = closed.default.arg, description: str = None) -> None: - """ - Initializes a lot + """Initializes a lot :param name: :param closed: """ @@ -173,9 +169,7 @@ class LotDevice(db.Model): nullable=False, default=lambda: g.user.id) author = db.relationship(User, primaryjoin=author_id == User.id) - author_id.comment = """ - The user that put the device in the lot. - """ + author_id.comment = """The user that put the device in the lot.""" class Path(db.Model): @@ -191,9 +185,7 @@ class Path(db.Model): primaryjoin=Lot.id == lot_id) path = db.Column(LtreeType, nullable=False) created = db.Column(db.TIMESTAMP(timezone=True), server_default=db.text('CURRENT_TIMESTAMP')) - created.comment = """ - When Devicehub created this. - """ + created.comment = """When Devicehub created this.""" __table_args__ = ( # dag.delete_edge needs to disable internally/temporarily the unique constraint diff --git a/ereuse_devicehub/resources/lot/views.py b/ereuse_devicehub/resources/lot/views.py index 4904d09c..4e3a9f06 100644 --- a/ereuse_devicehub/resources/lot/views.py +++ b/ereuse_devicehub/resources/lot/views.py @@ -23,8 +23,7 @@ class LotFormat(Enum): class LotView(View): class FindArgs(MarshmallowSchema): - """ - Allowed arguments for the ``find`` + """Allowed arguments for the ``find`` method (GET collection) endpoint """ format = EnumField(LotFormat, missing=None) @@ -56,8 +55,7 @@ class LotView(View): @teal.cache.cache(datetime.timedelta(minutes=5)) def find(self, args: dict): - """ - Gets lots. + """Gets lots. By passing the value `UiTree` in the parameter `format` of the query you get a recursive nested suited for ui-tree:: diff --git a/ereuse_devicehub/resources/models.py b/ereuse_devicehub/resources/models.py index 0c0a26b4..721e9258 100644 --- a/ereuse_devicehub/resources/models.py +++ b/ereuse_devicehub/resources/models.py @@ -20,16 +20,14 @@ class Thing(db.Model): nullable=False, index=True, server_default=db.text('CURRENT_TIMESTAMP')) - updated.comment = """ - The last time Devicehub recorded a change for this thing. + updated.comment = """The last time Devicehub recorded a change for + this thing. """ created = db.Column(db.TIMESTAMP(timezone=True), nullable=False, index=True, server_default=db.text('CURRENT_TIMESTAMP')) - created.comment = """ - When Devicehub created this. - """ + created.comment = """When Devicehub created this.""" def __init__(self, **kwargs) -> None: # We need to set 'created' before sqlalchemy inits the class diff --git a/ereuse_devicehub/resources/tag/model.py b/ereuse_devicehub/resources/tag/model.py index b0502a44..81b331e4 100644 --- a/ereuse_devicehub/resources/tag/model.py +++ b/ereuse_devicehub/resources/tag/model.py @@ -39,8 +39,8 @@ class Tag(Thing): collection_class=set) """The organization that issued the tag.""" provider = Column(URL()) - provider.comment = """ - The tag provider URL. If None, the provider is this Devicehub. + provider.comment = """The tag provider URL. If None, the provider is + this Devicehub. """ device_id = Column(BigInteger, # We don't want to delete the tag on device deletion, only set to null @@ -50,9 +50,8 @@ class Tag(Thing): primaryjoin=Device.id == device_id) """The device linked to this tag.""" secondary = Column(db.CIText(), index=True) - secondary.comment = """ - A secondary identifier for this tag. It has the same - constraints as the main one. Only needed in special cases. + secondary.comment = """A secondary identifier for this tag. + It has the same constraints as the main one. Only needed in special cases. """ __table_args__ = ( @@ -116,7 +115,7 @@ class Tag(Thing): @classmethod def is_printable_q(cls): - """Return a SQLAlchemy filter expression for printable queries""" + """Return a SQLAlchemy filter expression for printable queries.""" return cls.org_id == Organization.get_default_org_id() def __repr__(self) -> str: diff --git a/ereuse_devicehub/resources/tag/view.py b/ereuse_devicehub/resources/tag/view.py index 9cfe6d7d..af8add44 100644 --- a/ereuse_devicehub/resources/tag/view.py +++ b/ereuse_devicehub/resources/tag/view.py @@ -50,7 +50,7 @@ class TagView(View): class TagDeviceView(View): - """Endpoints to work with the device of the tag; /tags/23/device""" + """Endpoints to work with the device of the tag; /tags/23/device.""" def one(self, id): """Gets the device from the tag.""" @@ -78,8 +78,7 @@ class TagDeviceView(View): def get_device_from_tag(id: str): - """ - Gets the device by passing a tag id. + """Gets the device by passing a tag id. Example: /tags/23/device. diff --git a/ereuse_devicehub/resources/user/models.py b/ereuse_devicehub/resources/user/models.py index b471724a..1dd2cad7 100644 --- a/ereuse_devicehub/resources/user/models.py +++ b/ereuse_devicehub/resources/user/models.py @@ -28,8 +28,7 @@ class User(Thing): # todo set restriction that user has, at least, one active db def __init__(self, email, password=None, inventories=None) -> None: - """ - Creates an user. + """Creates an user. :param email: :param password: :param inventories: A set of Inventory where the user has diff --git a/ereuse_devicehub/resources/user/schemas.py b/ereuse_devicehub/resources/user/schemas.py index 91a7be92..e8d0d768 100644 --- a/ereuse_devicehub/resources/user/schemas.py +++ b/ereuse_devicehub/resources/user/schemas.py @@ -29,8 +29,7 @@ class User(Thing): load_only=(), dump_only=(), partial=False): - """ - Instantiates the User. + """Instantiates the User. By default we exclude token from both load/dump so they are not taken / set in normal usage by mistake. diff --git a/tests/files/pc-components.db.yaml b/tests/files/pc-components.db.yaml index 8d3efa48..c3c9d9ec 100644 --- a/tests/files/pc-components.db.yaml +++ b/tests/files/pc-components.db.yaml @@ -5,11 +5,11 @@ device: model: d1ml manufacturer: d1mr components: -- type: GraphicCard - serial_number: gc1s - model: gc1ml - manufacturer: gc1mr -- type: RamModule - serial_number: rm1s - model: rm1ml - manufacturer: rm1mr + - type: GraphicCard + serial_number: gc1s + model: gc1ml + manufacturer: gc1mr + - type: RamModule + serial_number: rm1s + model: rm1ml + manufacturer: rm1mr diff --git a/tests/files/workbench-10.snapshot.yaml b/tests/files/workbench-10.snapshot.yaml index ed17aedc..a1c5d457 100644 --- a/tests/files/workbench-10.snapshot.yaml +++ b/tests/files/workbench-10.snapshot.yaml @@ -32,8 +32,8 @@ components: passedLifetime: 16947, powerCycleCount: 1694, reallocatedSectorCount: 0, reportedUncorrectableErrors: 0, status: Completed without error, type: Short offline} type: HDD - - { '@type': GraphicCard, manufacturer: Intel Corporation, memory: 256.0, model: 4 - Series Chipset Integrated Graphics Controller, serialNumber: null} + - { '@type': GraphicCard, manufacturer: Intel Corporation, memory: 256.0, model: 4 + Series Chipset Integrated Graphics Controller, serialNumber: null} - '@type': Motherboard connectors: {firewire: 0, pcmcia: 0, serial: 1, usb: 8} manufacturer: LENOVO @@ -41,22 +41,22 @@ components: serialNumber: null totalSlots: 0 usedSlots: 2 - - { '@type': NetworkAdapter, manufacturer: Intel Corporation, model: 82567LM-3 Gigabit - Network Connection, serialNumber: '00:21:86:2c:5e:d6', speed: 1000} - - { '@type': SoundCard, manufacturer: Intel Corporation, model: 82801JD/DO HD Audio - Controller, serialNumber: null} + - { '@type': NetworkAdapter, manufacturer: Intel Corporation, model: 82567LM-3 Gigabit + Network Connection, serialNumber: '00:21:86:2c:5e:d6', speed: 1000} + - { '@type': SoundCard, manufacturer: Intel Corporation, model: 82801JD/DO HD Audio + Controller, serialNumber: null} condition: appearance: {general: B} functionality: {general: A} date: '2018-05-09T10:32:15' debug: - capabilities: { dmi-2.5: DMI version 2.5, smbios-2.5: SMBIOS version 2.5, smp: Symmetric - Multi-Processing, smp-1.4: SMP specification v1.4} + capabilities: { dmi-2.5: DMI version 2.5, smbios-2.5: SMBIOS version 2.5, smp: Symmetric + Multi-Processing, smp-1.4: SMP specification v1.4} children: - children: - - capabilities: { acpi: ACPI, biosbootspecification: BIOS boot specification, cdboot: Booting - from CD-ROM/DVD, edd: Enhanced Disk Drive extensions, escd: ESCD, ls120boot: Booting - from LS-120, pci: PCI bus, pnp: Plug-and-Play, shadowing: BIOS shadowing, + - capabilities: { acpi: ACPI, biosbootspecification: BIOS boot specification, cdboot: Booting + from CD-ROM/DVD, edd: Enhanced Disk Drive extensions, escd: ESCD, ls120boot: Booting + from LS-120, pci: PCI bus, pnp: Plug-and-Play, shadowing: BIOS shadowing, smartbattery: Smart battery, upgrade: BIOS EEPROM can be upgraded, usb: USB legacy emulation} capacity: 4128768 @@ -71,9 +71,9 @@ debug: vendor: LENOVO version: 5CKT48AUS - businfo: cpu@0 - capabilities: { acpi: thermal control (ACPI), aperfmperf: true, apic: on-chip - advanced programmable interrupt controller (APIC), arch_perfmon: true, boot: boot - processor, bts: true, clflush: true, cmov: conditional move instruction, + capabilities: { acpi: thermal control (ACPI), aperfmperf: true, apic: on-chip + advanced programmable interrupt controller (APIC), arch_perfmon: true, boot: boot + processor, bts: true, clflush: true, cmov: conditional move instruction, constant_tsc: true, cpufreq: CPU Frequency scaling, cx16: true, cx8: compare and exchange 8-byte, de: debugging extensions, ds_cpl: true, dtes64: true, dtherm: true, dts: debug trace and EMON store MSRs, eagerfpu: true, est: true, @@ -149,16 +149,16 @@ debug: version: 6.7.10 width: 64 - children: - - { claimed: true, class: memory, clock: 1067000000, description: DIMM DDR2 Synchronous - 1067 MHz (0.9 ns), handle: 'DMI:001F', id: 'bank:0', physid: '0', product: '000000000000000000000000000000000000', + - { claimed: true, class: memory, clock: 1067000000, description: DIMM DDR2 Synchronous + 1067 MHz (0.9 ns), handle: 'DMI:001F', id: 'bank:0', physid: '0', product: '000000000000000000000000000000000000', serial: '00000000', size: 2147483648, slot: J6G1, units: bytes, vendor: Unknown, width: 40960} - {claimed: true, class: memory, clock: 1067000000, description: 'DIMM DDR2 Synchronous 1067 MHz (0.9 ns) [empty]', handle: 'DMI:0020', id: 'bank:1', physid: '1', product: 012345678901234567890123456789012345, serial: '01234567', slot: J6G2, vendor: 48spaces} - - { claimed: true, class: memory, clock: 1067000000, description: DIMM DDR2 Synchronous - 1067 MHz (0.9 ns), handle: 'DMI:0021', id: 'bank:2', physid: '2', product: '000000000000000000000000000000000000', + - { claimed: true, class: memory, clock: 1067000000, description: DIMM DDR2 Synchronous + 1067 MHz (0.9 ns), handle: 'DMI:0021', id: 'bank:2', physid: '2', product: '000000000000000000000000000000000000', serial: '00000000', size: 2147483648, slot: J6H1, units: bytes, vendor: Unknown, width: 41984} - {claimed: true, class: memory, clock: 1067000000, description: 'DIMM DDR2 @@ -205,7 +205,7 @@ debug: - businfo: pci@0000:00:00.0 children: - businfo: pci@0000:00:02.0 - capabilities: { bus_master: bus mastering, cap_list: PCI capabilities listing, + capabilities: { bus_master: bus mastering, cap_list: PCI capabilities listing, msi: Message Signalled Interrupts, pm: Power Management, rom: extension ROM, vga_controller: true} claimed: true @@ -265,8 +265,8 @@ debug: version: '03' width: 32 - businfo: pci@0000:00:03.3 - capabilities: { '16550': true, bus_master: bus mastering, cap_list: PCI capabilities - listing, msi: Message Signalled Interrupts, pm: Power Management} + capabilities: { '16550': true, bus_master: bus mastering, cap_list: PCI capabilities + listing, msi: Message Signalled Interrupts, pm: Power Management} claimed: true class: communication clock: 66000000 @@ -280,8 +280,8 @@ debug: version: '03' width: 32 - businfo: pci@0000:00:19.0 - capabilities: { 1000bt-fd: 1Gbit/s (full duplex), 100bt: 100Mbit/s, 100bt-fd: 100Mbit/s - (full duplex), 10bt: 10Mbit/s, 10bt-fd: 10Mbit/s (full duplex), autonegotiation: Auto-negotiation, + capabilities: { 1000bt-fd: 1Gbit/s (full duplex), 100bt: 100Mbit/s, 100bt-fd: 100Mbit/s + (full duplex), 10bt: 10Mbit/s, 10bt-fd: 10Mbit/s (full duplex), autonegotiation: Auto-negotiation, bus_master: bus mastering, cap_list: PCI capabilities listing, ethernet: true, msi: Message Signalled Interrupts, physical: Physical interface, pm: Power Management, tp: twisted pair} @@ -575,8 +575,8 @@ debug: version: '02' width: 32 - businfo: pci@0000:00:1f.2 - capabilities: { ahci_1.0: true, bus_master: bus mastering, cap_list: PCI capabilities - listing, msi: Message Signalled Interrupts, pm: Power Management, storage: true} + capabilities: { ahci_1.0: true, bus_master: bus mastering, cap_list: PCI capabilities + listing, msi: Message Signalled Interrupts, pm: Power Management, storage: true} claimed: true class: storage clock: 66000000 @@ -620,7 +620,7 @@ debug: table} children: - businfo: scsi@0:0.0.0,1 - capabilities: { dir_nlink: directories with 65000+ subdirs, ext2: EXT2/EXT3, + capabilities: { dir_nlink: directories with 65000+ subdirs, ext2: EXT2/EXT3, ext4: true, extended_attributes: Extended Attributes, extents: extent-based allocation, huge_files: 16TB+ files, initialized: initialized volume, journaled: true, large_files: 4GB+ files, primary: Primary partition} @@ -672,8 +672,8 @@ debug: - capabilities: {emulated: Emulated device} children: - businfo: scsi@1:0.0.0 - capabilities: { audio: Audio CD playback, cd-r: CD-R burning, cd-rw: CD-RW - burning, dvd: DVD playback, dvd-r: DVD-R burning, dvd-ram: DVD-RAM burning, + capabilities: { audio: Audio CD playback, cd-r: CD-R burning, cd-rw: CD-RW + burning, dvd: DVD playback, dvd-r: DVD-R burning, dvd-ram: DVD-RAM burning, removable: support is removable} claimed: true class: disk diff --git a/tests/test_agent.py b/tests/test_agent.py index bb6b7714..2a3a360b 100644 --- a/tests/test_agent.py +++ b/tests/test_agent.py @@ -102,8 +102,7 @@ def test_membership_repeating_id(): @pytest.mark.usefixtures(app_context.__name__) def test_default_org_exists(config: DevicehubConfig): - """ - Ensures that the default organization is created on app + """Ensures that the default organization is created on app initialization and that is accessible for the method :meth:`ereuse_devicehub.resources.user.Organization.get_default_org`. """ diff --git a/tests/test_device.py b/tests/test_device.py index 0e1650b6..bfb2e383 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -31,9 +31,7 @@ from tests.conftest import file @pytest.mark.usefixtures(conftest.app_context.__name__) def test_device_model(): - """ - Tests that the correctness of the device model and its relationships. - """ + """Tests that the correctness of the device model and its relationships.""" pc = d.Desktop(model='p1mo', manufacturer='p1ma', serial_number='p1s', @@ -180,8 +178,7 @@ def test_add_remove(): @pytest.mark.usefixtures(conftest.app_context.__name__) def test_sync_run_components_empty(): - """ - Syncs a device that has an empty components list. The system should + """Syncs a device that has an empty components list. The system should remove all the components from the device. """ s = conftest.file('pc-components.db') @@ -198,8 +195,7 @@ def test_sync_run_components_empty(): @pytest.mark.usefixtures(conftest.app_context.__name__) def test_sync_run_components_none(): - """ - Syncs a device that has a None components. The system should + """Syncs a device that has a None components. The system should keep all the components from the device. """ s = conftest.file('pc-components.db') @@ -216,10 +212,7 @@ def test_sync_run_components_none(): @pytest.mark.usefixtures(conftest.app_context.__name__) def test_sync_execute_register_desktop_new_desktop_no_tag(): - """ - Syncs a new d.Desktop with HID and without a tag, creating it. - :return: - """ + """Syncs a new d.Desktop with HID and without a tag, creating it.""" # Case 1: device does not exist on DB pc = d.Desktop(**conftest.file('pc-components.db')['device']) db_pc = Sync().execute_register(pc) @@ -228,9 +221,7 @@ def test_sync_execute_register_desktop_new_desktop_no_tag(): @pytest.mark.usefixtures(conftest.app_context.__name__) def test_sync_execute_register_desktop_existing_no_tag(): - """ - Syncs an existing d.Desktop with HID and without a tag. - """ + """Syncs an existing d.Desktop with HID and without a tag.""" pc = d.Desktop(**conftest.file('pc-components.db')['device']) db.session.add(pc) db.session.commit() @@ -244,8 +235,7 @@ def test_sync_execute_register_desktop_existing_no_tag(): @pytest.mark.usefixtures(conftest.app_context.__name__) def test_sync_execute_register_desktop_no_hid_no_tag(): - """ - Syncs a d.Desktop without HID and no tag. + """Syncs a d.Desktop without HID and no tag. This should fail as we don't have a way to identify it. """ @@ -258,8 +248,7 @@ def test_sync_execute_register_desktop_no_hid_no_tag(): @pytest.mark.usefixtures(conftest.app_context.__name__) def test_sync_execute_register_desktop_tag_not_linked(): - """ - Syncs a new d.Desktop with HID and a non-linked tag. + """Syncs a new d.Desktop with HID and a non-linked tag. It is OK if the tag was not linked, it will be linked in this process. """ @@ -277,8 +266,7 @@ def test_sync_execute_register_desktop_tag_not_linked(): @pytest.mark.usefixtures(conftest.app_context.__name__) def test_sync_execute_register_no_hid_tag_not_linked(tag_id: str): - """ - Validates registering a d.Desktop without HID and a non-linked tag. + """Validates registering a d.Desktop without HID and a non-linked tag. In this case it is ok still, as the non-linked tag proves that the d.Desktop was not existing before (otherwise the tag would @@ -300,8 +288,7 @@ def test_sync_execute_register_no_hid_tag_not_linked(tag_id: str): @pytest.mark.usefixtures(conftest.app_context.__name__) def test_sync_execute_register_tag_does_not_exist(): - """ - Ensures not being able to register if the tag does not exist, + """Ensures not being able to register if the tag does not exist, even if the device has HID or it existed before. Tags have to be created before trying to link them through a Snapshot. @@ -313,8 +300,7 @@ def test_sync_execute_register_tag_does_not_exist(): @pytest.mark.usefixtures(conftest.app_context.__name__) def test_sync_execute_register_tag_linked_same_device(): - """ - If the tag is linked to the device, regardless if it has HID, + """If the tag is linked to the device, regardless if it has HID, the system should match the device through the tag. (If it has HID it validates both HID and tag point at the same device, this his checked in ). @@ -334,8 +320,7 @@ def test_sync_execute_register_tag_linked_same_device(): @pytest.mark.usefixtures(conftest.app_context.__name__) def test_sync_execute_register_tag_linked_other_device_mismatch_between_tags(): - """ - Checks that sync raises an error if finds that at least two passed-in + """Checks that sync raises an error if finds that at least two passed-in tags are not linked to the same device. """ pc1 = d.Desktop(**conftest.file('pc-components.db')['device']) @@ -356,8 +341,7 @@ def test_sync_execute_register_tag_linked_other_device_mismatch_between_tags(): @pytest.mark.usefixtures(conftest.app_context.__name__) def test_sync_execute_register_mismatch_between_tags_and_hid(): - """ - Checks that sync raises an error if it finds that the HID does + """Checks that sync raises an error if it finds that the HID does not point at the same device as the tag does. In this case we set HID -> pc1 but tag -> pc2 @@ -463,7 +447,8 @@ def test_manufacturer(user: UserClient): @pytest.mark.xfail(reason='Develop functionality') def test_manufacturer_enforced(): """Ensures that non-computer devices can submit only - manufacturers from the Manufacturer table.""" + manufacturers from the Manufacturer table. + """ def test_device_properties_format(app: Devicehub, user: UserClient): diff --git a/tests/test_device_find.py b/tests/test_device_find.py index e0e34eb0..d13bcc1d 100644 --- a/tests/test_device_find.py +++ b/tests/test_device_find.py @@ -56,8 +56,7 @@ def test_device_sort(): @pytest.fixture() def device_query_dummy(app: Devicehub): - """ - 3 computers, where: + """3 computers, where: 1. s1 Desktop with a Processor 2. s2 Desktop with an SSD diff --git a/tests/test_dispatcher.py b/tests/test_dispatcher.py index 6d210a4b..79919209 100644 --- a/tests/test_dispatcher.py +++ b/tests/test_dispatcher.py @@ -28,7 +28,7 @@ def test_dispatcher_default(dispatcher: PathDispatcher): def test_dispatcher_return_app(dispatcher: PathDispatcher): - """The dispatcher returns the correct app for the URL""" + """The dispatcher returns the correct app for the URL.""" # Note that the dispatcher does not check if the URL points # to a well-known endpoint for the app. # Only if can route it to an app. And then the app checks @@ -39,7 +39,7 @@ def test_dispatcher_return_app(dispatcher: PathDispatcher): def test_dispatcher_users(dispatcher: PathDispatcher): - """Users special endpoint returns an app""" + """Users special endpoint returns an app.""" # For now returns the first app, as all apps # can answer {}/users/login app = dispatcher({'SCRIPT_NAME:': '/', 'PATH_INFO': '/users/'}, noop) diff --git a/tests/test_event.py b/tests/test_event.py index b8f3f32b..2a884f62 100644 --- a/tests/test_event.py +++ b/tests/test_event.py @@ -22,8 +22,7 @@ from tests.conftest import create_user, file @pytest.mark.usefixtures(conftest.app_context.__name__) def test_author(): - """ - Checks the default created author. + """Checks the default created author. Note that the author can be accessed after inserting the row. """ @@ -337,7 +336,8 @@ def test_price_custom_client(user: UserClient): def test_ereuse_price(): """Tests the several ways of creating eReuse Price, emulating from an AggregateRate and ensuring that the different Range - return correct results.""" + return correct results. + """ # important to check Range.low no returning warranty2 # Range.verylow not returning nothing diff --git a/tests/test_inventory.py b/tests/test_inventory.py index e41b6857..94614bb9 100644 --- a/tests/test_inventory.py +++ b/tests/test_inventory.py @@ -13,8 +13,7 @@ from ereuse_devicehub.resources.inventory import Inventory from ereuse_devicehub.resources.user import User from tests.conftest import TestConfig -""" -Tests the management of inventories in a multi-inventory environment +"""Tests the management of inventories in a multi-inventory environment (several Devicehub instances that point at different schemas). """ diff --git a/tests/test_lot.py b/tests/test_lot.py index 937e1db8..f4467c08 100644 --- a/tests/test_lot.py +++ b/tests/test_lot.py @@ -9,8 +9,7 @@ from ereuse_devicehub.resources.enums import ComputerChassis from ereuse_devicehub.resources.lot.models import Lot, LotDevice from tests import conftest -""" -In case of error, debug with: +"""In case of error, debug with: try: with db.session.begin_nested(): @@ -67,7 +66,7 @@ def test_lot_model_children(): def test_lot_modify_patch_endpoint_and_delete(user: UserClient): - """Creates and modifies lot properties through the endpoint""" + """Creates and modifies lot properties through the endpoint.""" l, _ = user.post({'name': 'foo', 'description': 'baz'}, res=Lot) assert l['name'] == 'foo' assert l['description'] == 'baz' @@ -310,7 +309,8 @@ def test_post_get_lot(user: UserClient): def test_lot_post_add_children_view_ui_tree_normal(user: UserClient): """Tests adding children lots to a lot through the view and - GETting the results.""" + GETting the results. + """ parent, _ = user.post(({'name': 'Parent'}), res=Lot) child, _ = user.post(({'name': 'Child'}), res=Lot) parent, _ = user.post({}, @@ -347,7 +347,8 @@ def test_lot_post_add_children_view_ui_tree_normal(user: UserClient): def test_lot_post_add_remove_device_view(app: Devicehub, user: UserClient): """Tests adding a device to a lot using POST and - removing it with DELETE.""" + removing it with DELETE. + """ # todo check with components with app.app_context(): device = Desktop(serial_number='foo', diff --git a/tests/test_rate.py b/tests/test_rate.py index 19ebbd9d..9a092fe4 100644 --- a/tests/test_rate.py +++ b/tests/test_rate.py @@ -1,7 +1,6 @@ from decimal import Decimal from distutils.version import StrictVersion -import math import pytest from ereuse_devicehub.client import UserClient @@ -96,8 +95,7 @@ def test_price_from_rate(): def test_when_rate_must_not_compute(user: UserClient): - """ - Test to check if rate is computed in case of should not be calculated: + """Test to check if rate is computed in case of should not be calculated: 1. Snapshot haven't visual test 2. Snapshot software aren't Workbench 3. Device type are not Computer diff --git a/tests/test_rate_workbench_v1.py b/tests/test_rate_workbench_v1.py index 2ccbf0fd..6bb1c9ba 100644 --- a/tests/test_rate_workbench_v1.py +++ b/tests/test_rate_workbench_v1.py @@ -1,15 +1,13 @@ -""" -This file test all corner cases when compute score v1.0. +"""This file test all corner cases when compute score v1.0. + +First test to compute rate for every component in isolation. -First test to compute rate for every component in isolation -todo rewrite some corner cases using range(min,max) characteristics - in devices/schemas Components in Score v1: -DataStorage -RamModule -Processor -Then some test compute rate with all components that use the a1lgorithm +Then some test compute rate with all components that use the algorithm Excluded cases in tests @@ -31,9 +29,8 @@ from tests import conftest def test_rate_data_storage_rate(): - """ - Test to check if compute data storage rate have same value than previous score version; - id = pc_1193, pc_1201, pc_79, pc_798 + """Test to check if compute data storage rate have same value than + previous score version. """ hdd_1969 = HardDrive(size=476940) @@ -67,10 +64,8 @@ def test_rate_data_storage_rate(): def test_rate_data_storage_size_is_null(): - """ - Test where input DataStorage.size = NULL, BenchmarkDataStorage.read_speed = 0, + """Test where input DataStorage.size = NULL, BenchmarkDataStorage.read_speed = 0, BenchmarkDataStorage.write_speed = 0 is like no DataStorage has been detected; - id = pc_2992 """ hdd_null = HardDrive(size=None) @@ -81,9 +76,7 @@ def test_rate_data_storage_size_is_null(): def test_rate_no_data_storage(): - """ - Test without data storage devices - """ + """Test without data storage devices.""" hdd_null = HardDrive() hdd_null.actions_one.add(BenchmarkDataStorage(read_speed=0, write_speed=0)) @@ -92,9 +85,8 @@ def test_rate_no_data_storage(): def test_rate_ram_rate(): - """ - Test to check if compute ram rate have same value than previous score version - only with 1 RamModule; id = pc_1201 + """Test to check if compute ram rate have same value than previous + score version only with 1 RamModule. """ ram1 = RamModule(size=2048, speed=1333) @@ -105,9 +97,8 @@ def test_rate_ram_rate(): def test_rate_ram_rate_2modules(): - """ - Test to check if compute ram rate have same value than previous score version - with 2 RamModule; id = pc_1193 + """Test to check if compute ram rate have same value than previous + score version with 2 RamModule. """ ram1 = RamModule(size=4096, speed=1600) @@ -119,9 +110,8 @@ def test_rate_ram_rate_2modules(): def test_rate_ram_rate_4modules(): - """ - Test to check if compute ram rate have same value than previous score version - with 2 RamModule; id = pc_79 + """Test to check if compute ram rate have same value than previous + score version with 2 RamModule. """ ram1 = RamModule(size=512, speed=667) @@ -135,8 +125,8 @@ def test_rate_ram_rate_4modules(): def test_rate_ram_module_size_is_0(): - """ - Test where input data RamModule.size = 0; is like no RamModule has been detected; id = pc_798 + """Test where input data RamModule.size = 0; is like no RamModule + has been detected. """ ram0 = RamModule(size=0, speed=888) @@ -146,10 +136,7 @@ def test_rate_ram_module_size_is_0(): def test_rate_ram_speed_is_null(): - """ - Test where RamModule.speed is NULL (not detected) but has size. - Pc ID = 795(1542), 745(1535), 804(1549) - """ + """Test where RamModule.speed is NULL (not detected) but has size.""" ram0 = RamModule(size=2048, speed=None) @@ -165,9 +152,7 @@ def test_rate_ram_speed_is_null(): def test_rate_no_ram_module(): - """ - Test without RamModule - """ + """Test without RamModule.""" ram0 = RamModule() ram_rate = RamRate().compute([ram0]) @@ -175,9 +160,8 @@ def test_rate_no_ram_module(): def test_rate_processor_rate(): - """ - Test to check if compute processor rate have same value than previous score version - only with 1 core; id = 79 + """Test to check if compute processor rate have same value than previous + score version only with 1 core. """ cpu = Processor(cores=1, speed=1.6) @@ -190,9 +174,8 @@ def test_rate_processor_rate(): def test_rate_processor_rate_2cores(): - """ - Test to check if compute processor rate have same value than previous score version - with 2 cores; id = pc_1193, pc_1201 + """Test to check if compute processor rate have same value than previous + score version with 2 cores. """ cpu = Processor(cores=2, speed=3.4) @@ -211,13 +194,8 @@ def test_rate_processor_rate_2cores(): assert math.isclose(processor_rate, 3.93, rel_tol=0.002) -# TODO JN if delete processor default score for benchmark_cpu - - def test_rate_processor_with_null_cores(): - """ - Test with processor device have null number of cores - """ + """Test with processor device have null number of cores.""" cpu = Processor(cores=None, speed=3.3) cpu.actions_one.add(BenchmarkProcessor(rate=0)) @@ -227,9 +205,7 @@ def test_rate_processor_with_null_cores(): def test_rate_processor_with_null_speed(): - """ - Test with processor device have null speed value - """ + """Test with processor device have null speed value.""" cpu = Processor(cores=1, speed=None) cpu.actions_one.add(BenchmarkProcessor(rate=0)) @@ -238,13 +214,9 @@ def test_rate_processor_with_null_speed(): assert math.isclose(processor_rate, 1.06, rel_tol=0.001) -# TODO JN add price asserts in rate computers?? - - @pytest.mark.usefixtures(conftest.auth_app_context.__name__) def test_rate_computer_1193(): - """ - Test rate computer characteristics: + """Test rate computer characteristics: - 2 module ram - processor with 2 cores @@ -297,8 +269,7 @@ def test_rate_computer_1193(): @pytest.mark.usefixtures(conftest.auth_app_context.__name__) def test_rate_computer_1201(): - """ - Test rate computer characteristics: + """Test rate computer characteristics: - only 1 module ram - processor 2 cores @@ -349,8 +320,7 @@ def test_rate_computer_1201(): @pytest.mark.usefixtures(conftest.auth_app_context.__name__) def test_rate_computer_multiple_ram_module(): - """ - Test rate computer characteristics: + """Test rate computer characteristics: - only 1 module ram - processor 2 cores @@ -408,8 +378,7 @@ def test_rate_computer_multiple_ram_module(): @pytest.mark.usefixtures(conftest.auth_app_context.__name__) def test_rate_computer_one_ram_module(): - """ - Test rate computer characteristics: + """Test rate computer characteristics: - only 1 module ram - processor 2 cores @@ -463,4 +432,5 @@ def test_rate_computer_one_ram_module(): @pytest.mark.xfail(reason='Data Storage rate actually requires a DSSBenchmark') def test_rate_computer_with_data_storage_without_benchmark(): """For example if the data storage was introduced manually - or comes from an old version without benchmark.""" + or comes from an old version without benchmark. + """ diff --git a/tests/test_reports.py b/tests/test_reports.py index 752c6163..3e7ebc89 100644 --- a/tests/test_reports.py +++ b/tests/test_reports.py @@ -3,8 +3,6 @@ from datetime import datetime from io import StringIO from pathlib import Path -import pytest - from ereuse_devicehub.client import UserClient from ereuse_devicehub.resources.action.models import Snapshot from ereuse_devicehub.resources.documents import documents @@ -12,9 +10,7 @@ from tests.conftest import file def test_export_basic_snapshot(user: UserClient): - """ - Test export device information in a csv file - """ + """Test export device information in a csv file.""" snapshot, _ = user.post(file('basic.snapshot'), res=Snapshot) csv_str, _ = user.get(res=documents.DocumentDef.t, item='devices/', @@ -41,9 +37,7 @@ def test_export_basic_snapshot(user: UserClient): def test_export_full_snapshot(user: UserClient): - """ - Test a export device with all information and a lot of components - """ + """Test a export device with all information and a lot of components.""" snapshot, _ = user.post(file('real-eee-1001pxd.snapshot.11'), res=Snapshot) csv_str, _ = user.get(res=documents.DocumentDef.t, item='devices/', @@ -71,8 +65,8 @@ def test_export_full_snapshot(user: UserClient): def test_export_empty(user: UserClient): - """ - Test to check works correctly exporting csv without any information (no snapshot) + """Test to check works correctly exporting csv without any information, + export a placeholder device. """ csv_str, _ = user.get(res=documents.DocumentDef.t, accept='text/csv', @@ -85,9 +79,7 @@ def test_export_empty(user: UserClient): def test_export_computer_monitor(user: UserClient): - """ - Test a export device type computer monitor - """ + """Test a export device type computer monitor.""" snapshot, _ = user.post(file('computer-monitor.snapshot'), res=Snapshot) csv_str, _ = user.get(res=documents.DocumentDef.t, item='devices/', @@ -111,9 +103,7 @@ def test_export_computer_monitor(user: UserClient): def test_export_keyboard(user: UserClient): - """ - Test a export device type keyboard - """ + """Test a export device type keyboard.""" snapshot, _ = user.post(file('keyboard.snapshot'), res=Snapshot) csv_str, _ = user.get(res=documents.DocumentDef.t, item='devices/', @@ -136,8 +126,7 @@ def test_export_keyboard(user: UserClient): def test_export_multiple_different_devices(user: UserClient): - """ - Test function 'Export' of multiple different device types (like + """Test function 'Export' of multiple different device types (like computers, keyboards, monitors, etc..) """ # Open fixture csv and transform to list diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index a0b629a3..fc5045e7 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -26,8 +26,7 @@ from tests.conftest import file @pytest.mark.usefixtures('auth_app_context') def test_snapshot_model(): - """ - Tests creating a Snapshot with its relationships ensuring correct + """Tests creating a Snapshot with its relationships ensuring correct DB mapping. """ device = m.Desktop(serial_number='a1', chassis=ComputerChassis.Tower) @@ -62,8 +61,7 @@ def test_snapshot_schema(app: Devicehub): def test_snapshot_post(user: UserClient): - """ - Tests the post snapshot endpoint (validation, etc), data correctness, + """Tests the post snapshot endpoint (validation, etc), data correctness, and relationship correctness. """ # TODO add all action_types to check, how to add correctly?? @@ -98,8 +96,7 @@ def test_snapshot_post(user: UserClient): def test_snapshot_component_add_remove(user: UserClient): - """ - Tests adding and removing components and some don't generate HID. + """Tests adding and removing components and some don't generate HID. All computers generate HID. """ @@ -212,8 +209,7 @@ def test_snapshot_component_add_remove(user: UserClient): def _test_snapshot_computer_no_hid(user: UserClient): - """ - Tests inserting a computer that doesn't generate a HID, neither + """Tests inserting a computer that doesn't generate a HID, neither some of its components. """ # PC with 2 components. PC doesn't have HID and neither 1st component @@ -384,18 +380,14 @@ def test_test_data_storage(user: UserClient): @pytest.mark.xfail(reason='Not implemented yet, new rate is need it') def test_snapshot_computer_monitor(user: UserClient): - """ - Tests that a snapshot of computer monitor device create correctly. - """ + """Tests that a snapshot of computer monitor device create correctly.""" s = file('computer-monitor.snapshot') snapshot_and_check(user, s, action_types=('RateMonitor',)) @pytest.mark.xfail(reason='Not implemented yet, new rate is need it') def test_snapshot_mobile_smartphone_imei_manual_rate(user: UserClient): - """ - Tests that a snapshot of smartphone device is creat correctly. - """ + """Tests that a snapshot of smartphone device is creat correctly.""" s = file('smartphone.snapshot') snapshot = snapshot_and_check(user, s, action_types=('VisualTest',)) mobile, _ = user.get(res=m.Device, item=snapshot['device']['id']) @@ -404,24 +396,21 @@ def test_snapshot_mobile_smartphone_imei_manual_rate(user: UserClient): @pytest.mark.xfail(reason='Test not developed') def test_snapshot_components_none(): - """ - Tests that a snapshot without components does not - remove them from the computer. + """Tests that a snapshot without components does not remove them + from the computer. """ # TODO JN is really necessary in which cases?? @pytest.mark.xfail(reason='Test not developed') def test_snapshot_components_empty(): - """ - Tests that a snapshot whose components are an empty list remove + """Tests that a snapshot whose components are an empty list remove all its components. """ def assert_similar_device(device1: dict, device2: dict): - """ - Like :class:`ereuse_devicehub.resources.device.models.Device. + """Like :class:`ereuse_devicehub.resources.device.models.Device. is_similar()` but adapted for testing. """ assert isinstance(device1, dict) and device1 @@ -431,9 +420,8 @@ def assert_similar_device(device1: dict, device2: dict): def assert_similar_components(components1: List[dict], components2: List[dict]): - """ - Asserts that the components in components1 are - similar than the components in components2. + """Asserts that the components in components1 are similar than + the components in components2. """ assert len(components1) == len(components2) key = itemgetter('serialNumber') @@ -447,8 +435,7 @@ def snapshot_and_check(user: UserClient, input_snapshot: dict, action_types: Tuple[str, ...] = tuple(), perform_second_snapshot=True) -> dict: - """ - Performs a Snapshot and then checks if the result is ok: + """Performs a Snapshot and then checks if the result is ok: - There have been performed the types of actions and in the same order as described in the passed-in ``action_types``. diff --git a/tests/test_tag.py b/tests/test_tag.py index 93f1bace..a18cf950 100644 --- a/tests/test_tag.py +++ b/tests/test_tag.py @@ -80,8 +80,7 @@ def test_tag_post(app: Devicehub, user: UserClient): def test_tag_post_etag(user: UserClient): - """ - Ensures users cannot create eReuse.org tags through POST; + """Ensures users cannot create eReuse.org tags through POST; only terminal. """ user.post({'id': 'FO-123456'}, res=Tag, status=CannotCreateETag) @@ -121,8 +120,7 @@ def test_tag_get_device_from_tag_endpoint_no_tag(user: UserClient): def test_tag_get_device_from_tag_endpoint_multiple_tags(app: Devicehub, user: UserClient): - """ - As above, but when there are two tags with the same ID, the + """As above, but when there are two tags with the same ID, the system should not return any of both (to be deterministic) so it should raise an exception. """ diff --git a/tests/test_user.py b/tests/test_user.py index 8f56e66f..22e3b9ff 100644 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -18,8 +18,7 @@ from tests.conftest import app_context, create_user @pytest.mark.usefixtures(app_context.__name__) def test_create_user_method_with_agent(app: Devicehub): - """ - Tests creating an user through the main method. + """Tests creating an user through the main method. This method checks that the token is correct, too. """ @@ -63,8 +62,7 @@ def test_hash_password(): def test_login_success(client: Client, app: Devicehub): - """ - Tests successfully performing login. + """Tests successfully performing login. This checks that: - User is returned. diff --git a/tests/test_workbench.py b/tests/test_workbench.py index 22d12940..8948c429 100644 --- a/tests/test_workbench.py +++ b/tests/test_workbench.py @@ -1,10 +1,8 @@ -""" -Tests that emulates the behaviour of a WorkbenchServer. -""" +"""Tests that emulates the behaviour of a WorkbenchServer.""" import json -import math import pathlib +import math import pytest from ereuse_devicehub.client import UserClient @@ -17,8 +15,7 @@ from tests.conftest import file def test_workbench_server_condensed(user: UserClient): - """ - As :def:`.test_workbench_server_phases` but all the actions + """As :def:`.test_workbench_server_phases` but all the actions condensed in only one big ``Snapshot`` file, as described in the docs. """ @@ -72,8 +69,7 @@ def test_workbench_server_condensed(user: UserClient): @pytest.mark.xfail(reason='Functionality not yet developed.') def test_workbench_server_phases(user: UserClient): - """ - Tests the phases described in the docs section `Snapshots from + """Tests the phases described in the docs section `Snapshots from Workbench `_. """ @@ -170,8 +166,7 @@ def test_real_toshiba_11(user: UserClient): def test_snapshot_real_eee_1001pxd_with_rate(user: UserClient): - """ - Checks the values of the device, components, + """Checks the values of the device, components, actions and their relationships of a real pc. """ s = file('real-eee-1001pxd.snapshot.11')