Merge pull request #118 from eReuse/change/#117-deactivate-merge
Change/#117 deactivate merge
This commit is contained in:
commit
d2c7150320
|
@ -19,6 +19,8 @@ ml).
|
||||||
- [bugfix] #100 fixing bug of scheme live
|
- [bugfix] #100 fixing bug of scheme live
|
||||||
- [bugfix] #101 fixing bug when 2 users have one device and launch one live
|
- [bugfix] #101 fixing bug when 2 users have one device and launch one live
|
||||||
- [changes] #114 clean blockchain of all models
|
- [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
|
- [remove] #114 remove proof system
|
||||||
|
|
||||||
## [1.0.3-beta]
|
## [1.0.3-beta]
|
||||||
|
|
|
@ -619,7 +619,8 @@ class BenchmarkDataStorage(Benchmark):
|
||||||
write_speed = Column(Float(decimal_return_scale=2), nullable=False)
|
write_speed = Column(Float(decimal_return_scale=2), nullable=False)
|
||||||
|
|
||||||
def __str__(self) -> str:
|
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):
|
class BenchmarkWithRate(Benchmark):
|
||||||
|
@ -628,7 +629,7 @@ class BenchmarkWithRate(Benchmark):
|
||||||
rate = Column(Float, nullable=False)
|
rate = Column(Float, nullable=False)
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return '{} points'.format(self.rate)
|
return '{0:.2f} points'.format(self.rate)
|
||||||
|
|
||||||
|
|
||||||
class BenchmarkProcessor(BenchmarkWithRate):
|
class BenchmarkProcessor(BenchmarkWithRate):
|
||||||
|
@ -1022,7 +1023,10 @@ class Rate(JoinedWithOneDeviceMixin, ActionWithOneDevice):
|
||||||
return args
|
return args
|
||||||
|
|
||||||
def __str__(self) -> str:
|
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
|
@classmethod
|
||||||
def compute(cls, device) -> 'RateComputer':
|
def compute(cls, device) -> 'RateComputer':
|
||||||
|
|
|
@ -33,7 +33,7 @@ class DeviceDef(Resource):
|
||||||
|
|
||||||
path = '/<{value}:dev1_id>/merge/<{value}:dev2_id>'.format(value=self.ID_CONVERTER.value)
|
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):
|
class ComputerDef(DeviceDef):
|
||||||
|
|
|
@ -194,6 +194,33 @@ class Device(Thing):
|
||||||
if isinstance(c, ColumnProperty)
|
if isinstance(c, ColumnProperty)
|
||||||
and not getattr(c, 'foreign_keys', None)
|
and not getattr(c, 'foreign_keys', None)
|
||||||
and c.key not in self._NON_PHYSICAL_PROPS}
|
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
|
@property
|
||||||
def url(self) -> urlutils.URL:
|
def url(self) -> urlutils.URL:
|
||||||
|
|
|
@ -51,8 +51,8 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<ul>
|
<ul>
|
||||||
{% for key, value in device.physical_properties.items() %}
|
{% for key, value in device.public_properties.items() %}
|
||||||
<li>{{ key }}: {{ value }}
|
<li>{{ key }}: {{ value }}</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
{% if isinstance(device, d.Computer) %}
|
{% if isinstance(device, d.Computer) %}
|
||||||
|
@ -151,26 +151,6 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% 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>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
@ -179,7 +159,7 @@
|
||||||
<small>Latest one.</small>
|
<small>Latest one.</small>
|
||||||
</div>
|
</div>
|
||||||
<ol>
|
<ol>
|
||||||
{% for action in device.actions|reverse %}
|
{% for action in device.public_actions %}
|
||||||
<li>
|
<li>
|
||||||
<strong>
|
<strong>
|
||||||
{{ action.type }}
|
{{ action.type }}
|
||||||
|
|
|
@ -27,87 +27,88 @@ def test_dependencies():
|
||||||
def test_api_docs(client: Client):
|
def test_api_docs(client: Client):
|
||||||
"""Tests /apidocs correct initialization."""
|
"""Tests /apidocs correct initialization."""
|
||||||
docs, _ = client.get('/apidocs')
|
docs, _ = client.get('/apidocs')
|
||||||
|
# import pdb; pdb.set_trace()
|
||||||
assert set(docs['paths'].keys()) == {
|
assert set(docs['paths'].keys()) == {
|
||||||
'/actions/',
|
'/actions/',
|
||||||
'/apidocs',
|
'/apidocs',
|
||||||
'/batteries/{dev1_id}/merge/{dev2_id}',
|
'/allocates/',
|
||||||
'/bikes/{dev1_id}/merge/{dev2_id}',
|
'/deallocates/',
|
||||||
'/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}',
|
|
||||||
'/deliverynotes/',
|
'/deliverynotes/',
|
||||||
'/desktops/{dev1_id}/merge/{dev2_id}',
|
|
||||||
'/devices/',
|
'/devices/',
|
||||||
'/devices/static/{filename}',
|
'/devices/static/{filename}',
|
||||||
'/devices/{dev1_id}/merge/{dev2_id}',
|
'/documents/static/{filename}',
|
||||||
'/displays/{dev1_id}/merge/{dev2_id}',
|
|
||||||
'/diy-and-gardenings/{dev1_id}/merge/{dev2_id}',
|
|
||||||
'/documents/devices/',
|
|
||||||
'/documents/actions/',
|
'/documents/actions/',
|
||||||
'/documents/erasures/',
|
'/documents/erasures/',
|
||||||
'/documents/lots/',
|
'/documents/devices/',
|
||||||
'/documents/static/{filename}',
|
'/documents/stamps/',
|
||||||
'/documents/stock/',
|
'/documents/stock/',
|
||||||
'/documents/check/',
|
'/documents/check/',
|
||||||
'/documents/stamps/',
|
'/documents/lots/',
|
||||||
'/drills/{dev1_id}/merge/{dev2_id}',
|
'/versions/',
|
||||||
'/graphic-cards/{dev1_id}/merge/{dev2_id}',
|
'/manufacturers/',
|
||||||
'/hard-drives/{dev1_id}/merge/{dev2_id}',
|
'/licences/',
|
||||||
'/homes/{dev1_id}/merge/{dev2_id}',
|
'/lives/',
|
||||||
'/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}',
|
|
||||||
'/lots/',
|
'/lots/',
|
||||||
'/lots/{id}/children',
|
'/lots/{id}/children',
|
||||||
'/lots/{id}/devices',
|
'/lots/{id}/devices',
|
||||||
'/manufacturers/',
|
'/metrics/',
|
||||||
'/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}',
|
|
||||||
'/tags/',
|
'/tags/',
|
||||||
'/tags/{tag_id}/device/{device_id}',
|
'/tags/{tag_id}/device/{device_id}',
|
||||||
'/television-sets/{dev1_id}/merge/{dev2_id}',
|
|
||||||
'/users/',
|
'/users/',
|
||||||
'/users/login/',
|
'/users/login/'
|
||||||
'/video-scalers/{dev1_id}/merge/{dev2_id}',
|
# '/devices/{dev1_id}/merge/{dev2_id}',
|
||||||
'/videoconferences/{dev1_id}/merge/{dev2_id}',
|
# '/batteries/{dev1_id}/merge/{dev2_id}',
|
||||||
'/videos/{dev1_id}/merge/{dev2_id}',
|
# '/bikes/{dev1_id}/merge/{dev2_id}',
|
||||||
'/wireless-access-points/{dev1_id}/merge/{dev2_id}',
|
# '/cameras/{dev1_id}/merge/{dev2_id}',
|
||||||
'/versions/',
|
# '/cellphones/{dev1_id}/merge/{dev2_id}',
|
||||||
'/allocates/',
|
# '/components/{dev1_id}/merge/{dev2_id}',
|
||||||
'/deallocates/',
|
# '/computer-accessories/{dev1_id}/merge/{dev2_id}',
|
||||||
'/metrics/',
|
# '/computer-monitors/{dev1_id}/merge/{dev2_id}',
|
||||||
'/licences/',
|
# '/computers/{dev1_id}/merge/{dev2_id}',
|
||||||
'/lives/',
|
# '/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['info'] == {'title': 'Devicehub', 'version': '0.2'}
|
||||||
assert docs['components']['securitySchemes']['bearerAuth'] == {
|
assert docs['components']['securitySchemes']['bearerAuth'] == {
|
||||||
|
|
|
@ -14,6 +14,38 @@ from tests.conftest import file as import_snap
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.mvp
|
@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):
|
def test_simple_merge(app: Devicehub, user: UserClient):
|
||||||
""" Check if is correct to do a manual merge """
|
""" Check if is correct to do a manual merge """
|
||||||
snapshot1, _ = user.post(import_snap('real-custom.snapshot.11'), res=m.Snapshot)
|
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:
|
for com in components1_excluded:
|
||||||
assert not com in pc1.components
|
assert not com in pc1.components
|
||||||
|
|
||||||
@pytest.mark.mvp
|
# @pytest.mark.mvp
|
||||||
def test_merge_two_device_with_differents_tags(app: Devicehub, user: UserClient):
|
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 """
|
""" 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)
|
snapshot1, _ = user.post(import_snap('real-custom.snapshot.11'), res=m.Snapshot)
|
||||||
|
|
Reference in New Issue