diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e3c4d45..84372524 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ ml). - [bugfix] #100 fixing bug of scheme live - [bugfix] #101 fixing bug when 2 users have one device and launch one live - [changes] #114 clean blockchain of all models +- [changes] #118 deactivate manual merge +- [changes] #118 clean datas of public information of devices - [remove] #114 remove proof system ## [1.0.3-beta] diff --git a/ereuse_devicehub/resources/action/models.py b/ereuse_devicehub/resources/action/models.py index 53116a5c..1211825b 100644 --- a/ereuse_devicehub/resources/action/models.py +++ b/ereuse_devicehub/resources/action/models.py @@ -619,7 +619,8 @@ class BenchmarkDataStorage(Benchmark): write_speed = Column(Float(decimal_return_scale=2), nullable=False) def __str__(self) -> str: - return 'Read: {} MB/s, write: {} MB/s'.format(self.read_speed, self.write_speed) + return 'Read: {0:.2f} MB/s, write: {0:.2f} MB/s'.format( + self.read_speed, self.write_speed) class BenchmarkWithRate(Benchmark): @@ -628,7 +629,7 @@ class BenchmarkWithRate(Benchmark): rate = Column(Float, nullable=False) def __str__(self) -> str: - return '{} points'.format(self.rate) + return '{0:.2f} points'.format(self.rate) class BenchmarkProcessor(BenchmarkWithRate): @@ -1022,7 +1023,10 @@ class Rate(JoinedWithOneDeviceMixin, ActionWithOneDevice): return args def __str__(self) -> str: - return '{} (v.{})'.format(self.rating_range, self.version) + if self.version: + return '{} (v.{})'.format(self.rating_range, self.version) + + return '{}'.format(self.rating_range) @classmethod def compute(cls, device) -> 'RateComputer': diff --git a/ereuse_devicehub/resources/device/definitions.py b/ereuse_devicehub/resources/device/definitions.py index 7960efad..e96302f1 100644 --- a/ereuse_devicehub/resources/device/definitions.py +++ b/ereuse_devicehub/resources/device/definitions.py @@ -33,7 +33,7 @@ class DeviceDef(Resource): path = '/<{value}:dev1_id>/merge/<{value}:dev2_id>'.format(value=self.ID_CONVERTER.value) - self.add_url_rule(path, view_func=device_merge, methods={'POST'}) + # self.add_url_rule(path, view_func=device_merge, methods={'POST'}) class ComputerDef(DeviceDef): diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index a9efc105..215fcfb3 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -194,6 +194,33 @@ class Device(Thing): if isinstance(c, ColumnProperty) and not getattr(c, 'foreign_keys', None) and c.key not in self._NON_PHYSICAL_PROPS} + + @property + def public_properties(self) -> Dict[str, object or None]: + """Fields that describe the properties of a device than next show + in the public page. + + :return A dictionary: + - Column. + - Actual value of the column or None. + """ + non_public = ['amount', 'transfer_state', 'receiver_id'] + hide_properties = list(self._NON_PHYSICAL_PROPS) + non_public + return {c.key: getattr(self, c.key, None) + for c in inspect(self.__class__).attrs + if isinstance(c, ColumnProperty) + and not getattr(c, 'foreign_keys', None) + and c.key not in hide_properties} + + @property + def public_actions(self) -> List[object]: + """Actions than we want show in public page as traceability log section + :return a list of actions: + """ + hide_actions = ['Price'] + actions = [ac for ac in self.actions if not ac.t in hide_actions] + actions.reverse() + return actions @property def url(self) -> urlutils.URL: diff --git a/ereuse_devicehub/resources/device/templates/devices/layout.html b/ereuse_devicehub/resources/device/templates/devices/layout.html index eb672c91..de46ecf3 100644 --- a/ereuse_devicehub/resources/device/templates/devices/layout.html +++ b/ereuse_devicehub/resources/device/templates/devices/layout.html @@ -51,8 +51,8 @@
{% if isinstance(device, d.Computer) %} @@ -151,26 +151,6 @@ {% endif %} - {% if device.rate and device.rate.price %} - - - Algorithm price - - - {{ device.rate.price }} - - - {% endif %} - {% if device.price %} - - - Actual price - - - {{ device.price }} - - - {% endif %}
@@ -179,7 +159,7 @@ Latest one.
    - {% for action in device.actions|reverse %} + {% for action in device.public_actions %}
  1. {{ action.type }} diff --git a/tests/test_basic.py b/tests/test_basic.py index bcab605e..b5e52805 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -27,87 +27,88 @@ def test_dependencies(): def test_api_docs(client: Client): """Tests /apidocs correct initialization.""" docs, _ = client.get('/apidocs') + # import pdb; pdb.set_trace() assert set(docs['paths'].keys()) == { '/actions/', '/apidocs', - '/batteries/{dev1_id}/merge/{dev2_id}', - '/bikes/{dev1_id}/merge/{dev2_id}', - '/cameras/{dev1_id}/merge/{dev2_id}', - '/cellphones/{dev1_id}/merge/{dev2_id}', - '/components/{dev1_id}/merge/{dev2_id}', - '/computer-accessories/{dev1_id}/merge/{dev2_id}', - '/computer-monitors/{dev1_id}/merge/{dev2_id}', - '/computers/{dev1_id}/merge/{dev2_id}', - '/cookings/{dev1_id}/merge/{dev2_id}', - '/data-storages/{dev1_id}/merge/{dev2_id}', - '/dehumidifiers/{dev1_id}/merge/{dev2_id}', + '/allocates/', + '/deallocates/', '/deliverynotes/', - '/desktops/{dev1_id}/merge/{dev2_id}', '/devices/', '/devices/static/{filename}', - '/devices/{dev1_id}/merge/{dev2_id}', - '/displays/{dev1_id}/merge/{dev2_id}', - '/diy-and-gardenings/{dev1_id}/merge/{dev2_id}', - '/documents/devices/', + '/documents/static/{filename}', '/documents/actions/', '/documents/erasures/', - '/documents/lots/', - '/documents/static/{filename}', + '/documents/devices/', + '/documents/stamps/', '/documents/stock/', '/documents/check/', - '/documents/stamps/', - '/drills/{dev1_id}/merge/{dev2_id}', - '/graphic-cards/{dev1_id}/merge/{dev2_id}', - '/hard-drives/{dev1_id}/merge/{dev2_id}', - '/homes/{dev1_id}/merge/{dev2_id}', - '/hubs/{dev1_id}/merge/{dev2_id}', - '/keyboards/{dev1_id}/merge/{dev2_id}', - '/label-printers/{dev1_id}/merge/{dev2_id}', - '/laptops/{dev1_id}/merge/{dev2_id}', + '/documents/lots/', + '/versions/', + '/manufacturers/', + '/licences/', + '/lives/', '/lots/', '/lots/{id}/children', '/lots/{id}/devices', - '/manufacturers/', - '/memory-card-readers/{dev1_id}/merge/{dev2_id}', - '/mice/{dev1_id}/merge/{dev2_id}', - '/microphones/{dev1_id}/merge/{dev2_id}', - '/mixers/{dev1_id}/merge/{dev2_id}', - '/mobiles/{dev1_id}/merge/{dev2_id}', - '/monitors/{dev1_id}/merge/{dev2_id}', - '/motherboards/{dev1_id}/merge/{dev2_id}', - '/network-adapters/{dev1_id}/merge/{dev2_id}', - '/networkings/{dev1_id}/merge/{dev2_id}', - '/pack-of-screwdrivers/{dev1_id}/merge/{dev2_id}', - '/printers/{dev1_id}/merge/{dev2_id}', - '/processors/{dev1_id}/merge/{dev2_id}', - '/rackets/{dev1_id}/merge/{dev2_id}', - '/ram-modules/{dev1_id}/merge/{dev2_id}', - '/recreations/{dev1_id}/merge/{dev2_id}', - '/routers/{dev1_id}/merge/{dev2_id}', - '/sais/{dev1_id}/merge/{dev2_id}', - '/servers/{dev1_id}/merge/{dev2_id}', - '/smartphones/{dev1_id}/merge/{dev2_id}', - '/solid-state-drives/{dev1_id}/merge/{dev2_id}', - '/sound-cards/{dev1_id}/merge/{dev2_id}', - '/sounds/{dev1_id}/merge/{dev2_id}', - '/stairs/{dev1_id}/merge/{dev2_id}', - '/switches/{dev1_id}/merge/{dev2_id}', - '/tablets/{dev1_id}/merge/{dev2_id}', + '/metrics/', '/tags/', '/tags/{tag_id}/device/{device_id}', - '/television-sets/{dev1_id}/merge/{dev2_id}', '/users/', - '/users/login/', - '/video-scalers/{dev1_id}/merge/{dev2_id}', - '/videoconferences/{dev1_id}/merge/{dev2_id}', - '/videos/{dev1_id}/merge/{dev2_id}', - '/wireless-access-points/{dev1_id}/merge/{dev2_id}', - '/versions/', - '/allocates/', - '/deallocates/', - '/metrics/', - '/licences/', - '/lives/', + '/users/login/' + # '/devices/{dev1_id}/merge/{dev2_id}', + # '/batteries/{dev1_id}/merge/{dev2_id}', + # '/bikes/{dev1_id}/merge/{dev2_id}', + # '/cameras/{dev1_id}/merge/{dev2_id}', + # '/cellphones/{dev1_id}/merge/{dev2_id}', + # '/components/{dev1_id}/merge/{dev2_id}', + # '/computer-accessories/{dev1_id}/merge/{dev2_id}', + # '/computer-monitors/{dev1_id}/merge/{dev2_id}', + # '/computers/{dev1_id}/merge/{dev2_id}', + # '/cookings/{dev1_id}/merge/{dev2_id}', + # '/data-storages/{dev1_id}/merge/{dev2_id}', + # '/dehumidifiers/{dev1_id}/merge/{dev2_id}', + # '/desktops/{dev1_id}/merge/{dev2_id}', + # '/displays/{dev1_id}/merge/{dev2_id}', + # '/diy-and-gardenings/{dev1_id}/merge/{dev2_id}', + # '/drills/{dev1_id}/merge/{dev2_id}', + # '/graphic-cards/{dev1_id}/merge/{dev2_id}', + # '/hard-drives/{dev1_id}/merge/{dev2_id}', + # '/homes/{dev1_id}/merge/{dev2_id}', + # '/hubs/{dev1_id}/merge/{dev2_id}', + # '/keyboards/{dev1_id}/merge/{dev2_id}', + # '/label-printers/{dev1_id}/merge/{dev2_id}', + # '/laptops/{dev1_id}/merge/{dev2_id}', + # '/memory-card-readers/{dev1_id}/merge/{dev2_id}', + # '/mice/{dev1_id}/merge/{dev2_id}', + # '/microphones/{dev1_id}/merge/{dev2_id}', + # '/mixers/{dev1_id}/merge/{dev2_id}', + # '/mobiles/{dev1_id}/merge/{dev2_id}', + # '/monitors/{dev1_id}/merge/{dev2_id}', + # '/motherboards/{dev1_id}/merge/{dev2_id}', + # '/network-adapters/{dev1_id}/merge/{dev2_id}', + # '/networkings/{dev1_id}/merge/{dev2_id}', + # '/pack-of-screwdrivers/{dev1_id}/merge/{dev2_id}', + # '/printers/{dev1_id}/merge/{dev2_id}', + # '/processors/{dev1_id}/merge/{dev2_id}', + # '/rackets/{dev1_id}/merge/{dev2_id}', + # '/ram-modules/{dev1_id}/merge/{dev2_id}', + # '/recreations/{dev1_id}/merge/{dev2_id}', + # '/routers/{dev1_id}/merge/{dev2_id}', + # '/sais/{dev1_id}/merge/{dev2_id}', + # '/servers/{dev1_id}/merge/{dev2_id}', + # '/smartphones/{dev1_id}/merge/{dev2_id}', + # '/solid-state-drives/{dev1_id}/merge/{dev2_id}', + # '/sound-cards/{dev1_id}/merge/{dev2_id}', + # '/sounds/{dev1_id}/merge/{dev2_id}', + # '/stairs/{dev1_id}/merge/{dev2_id}', + # '/switches/{dev1_id}/merge/{dev2_id}', + # '/tablets/{dev1_id}/merge/{dev2_id}', + # '/television-sets/{dev1_id}/merge/{dev2_id}', + # '/video-scalers/{dev1_id}/merge/{dev2_id}', + # '/videoconferences/{dev1_id}/merge/{dev2_id}', + # '/videos/{dev1_id}/merge/{dev2_id}', + # '/wireless-access-points/{dev1_id}/merge/{dev2_id}', } assert docs['info'] == {'title': 'Devicehub', 'version': '0.2'} assert docs['components']['securitySchemes']['bearerAuth'] == { diff --git a/tests/test_merge.py b/tests/test_merge.py index 52d3436d..b6998342 100644 --- a/tests/test_merge.py +++ b/tests/test_merge.py @@ -14,6 +14,38 @@ from tests.conftest import file as import_snap @pytest.mark.mvp +def test_deactivate_merge(app: Devicehub, user: UserClient): + """ Check if is correct to do a manual merge """ + snapshot1, _ = user.post(import_snap('real-custom.snapshot.11'), res=m.Snapshot) + snapshot2, _ = user.post(import_snap('real-hp.snapshot.11'), res=m.Snapshot) + pc1_id = snapshot1['device']['id'] + pc2_id = snapshot2['device']['id'] + + with app.app_context(): + pc1 = d.Device.query.filter_by(id=pc1_id).one() + pc2 = d.Device.query.filter_by(id=pc2_id).one() + n_actions1 = len(pc1.actions) + n_actions2 = len(pc2.actions) + action1 = pc1.actions[0] + action2 = pc2.actions[0] + assert not action2 in pc1.actions + + tag = Tag(id='foo-bar', owner_id=user.user['id']) + pc2.tags.add(tag) + db.session.add(pc2) + db.session.commit() + + components1 = [com for com in pc1.components] + components2 = [com for com in pc2.components] + components1_excluded = [com for com in pc1.components if not com in components2] + assert pc1.hid != pc2.hid + assert not tag in pc1.tags + + uri = '/devices/%d/merge/%d' % (pc1_id, pc2_id) + _, code = user.post({'id': 1}, uri=uri, status=404) + assert code.status == '404 NOT FOUND' + +# @pytest.mark.mvp def test_simple_merge(app: Devicehub, user: UserClient): """ Check if is correct to do a manual merge """ snapshot1, _ = user.post(import_snap('real-custom.snapshot.11'), res=m.Snapshot) @@ -58,7 +90,7 @@ def test_simple_merge(app: Devicehub, user: UserClient): for com in components1_excluded: assert not com in pc1.components -@pytest.mark.mvp +# @pytest.mark.mvp def test_merge_two_device_with_differents_tags(app: Devicehub, user: UserClient): """ Check if is correct to do a manual merge of 2 diferents devices with diferents tags """ snapshot1, _ = user.post(import_snap('real-custom.snapshot.11'), res=m.Snapshot)