Merge pull request #118 from eReuse/change/#117-deactivate-merge

Change/#117 deactivate merge
This commit is contained in:
cayop 2021-02-11 21:19:25 +01:00 committed by GitHub
commit d2c7150320
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 139 additions and 93 deletions

View File

@ -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]

View File

@ -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,8 +1023,11 @@ class Rate(JoinedWithOneDeviceMixin, ActionWithOneDevice):
return args
def __str__(self) -> str:
if self.version:
return '{} (v.{})'.format(self.rating_range, self.version)
return '{}'.format(self.rating_range)
@classmethod
def compute(cls, device) -> 'RateComputer':
raise NotImplementedError()

View File

@ -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):

View File

@ -195,6 +195,33 @@ class Device(Thing):
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:
"""The URL where to GET this device."""

View File

@ -51,8 +51,8 @@
</div>
<div class="col-md-6">
<ul>
{% for key, value in device.physical_properties.items() %}
<li>{{ key }}: {{ value }}
{% for key, value in device.public_properties.items() %}
<li>{{ key }}: {{ value }}</li>
{% endfor %}
</ul>
{% if isinstance(device, d.Computer) %}
@ -151,26 +151,6 @@
</td>
</tr>
{% endif %}
{% if device.rate and device.rate.price %}
<tr class="active">
<td class="text-right">
Algorithm price
</td>
<td>
{{ device.rate.price }}
</td>
</tr>
{% endif %}
{% if device.price %}
<tr class="active">
<td class="text-right">
Actual price
</td>
<td>
{{ device.price }}
</td>
</tr>
{% endif %}
</tbody>
</table>
</div>
@ -179,7 +159,7 @@
<small>Latest one.</small>
</div>
<ol>
{% for action in device.actions|reverse %}
{% for action in device.public_actions %}
<li>
<strong>
{{ action.type }}

View File

@ -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'] == {

View File

@ -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)