adding revoke and fixing ConfigRevike
This commit is contained in:
parent
34fbf0dca6
commit
951d067dd6
|
@ -249,6 +249,7 @@ class MakeAvailable(ActionDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = schemas.MakeAvailable
|
SCHEMA = schemas.MakeAvailable
|
||||||
|
|
||||||
|
|
||||||
class ConfirmDef(ActionDef):
|
class ConfirmDef(ActionDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = schemas.Confirm
|
SCHEMA = schemas.Confirm
|
||||||
|
@ -259,6 +260,11 @@ class ConfirmRevokeDef(ActionDef):
|
||||||
SCHEMA = schemas.ConfirmRevoke
|
SCHEMA = schemas.ConfirmRevoke
|
||||||
|
|
||||||
|
|
||||||
|
class RevokeDef(ActionDef):
|
||||||
|
VIEW = None
|
||||||
|
SCHEMA = schemas.Revoke
|
||||||
|
|
||||||
|
|
||||||
class TradeDef(ActionDef):
|
class TradeDef(ActionDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = schemas.Trade
|
SCHEMA = schemas.Trade
|
||||||
|
|
|
@ -1459,6 +1459,11 @@ class Confirm(JoinedTableMixin, ActionWithMultipleDevices):
|
||||||
origin = 'From'
|
origin = 'From'
|
||||||
return '<{0.t} {0.id} accepted by {1}>'.format(self, origin)
|
return '<{0.t} {0.id} accepted by {1}>'.format(self, origin)
|
||||||
|
|
||||||
|
|
||||||
|
class Revoke(Confirm):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ConfirmRevoke(Confirm):
|
class ConfirmRevoke(Confirm):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -474,6 +474,27 @@ class Confirm(ActionWithMultipleDevices):
|
||||||
raise ValidationError(txt)
|
raise ValidationError(txt)
|
||||||
|
|
||||||
|
|
||||||
|
class Revoke(ActionWithMultipleDevices):
|
||||||
|
__doc__ = m.Revoke.__doc__
|
||||||
|
action = NestedOn('Action', only_query='id')
|
||||||
|
|
||||||
|
@validates_schema
|
||||||
|
def validate_revoke(self, data: dict):
|
||||||
|
acceptances = copy.copy(data['action'].acceptances)
|
||||||
|
acceptances.reverse()
|
||||||
|
# import pdb; pdb.set_trace()
|
||||||
|
for ac in acceptances:
|
||||||
|
if ac.user == g.user and not ac.t == 'ConfirmRevoke':
|
||||||
|
return data
|
||||||
|
|
||||||
|
if ac.user == g.user and ac.t == 'ConfirmRevoke':
|
||||||
|
txt = "you are revoke this action before"
|
||||||
|
raise ValidationError(txt)
|
||||||
|
|
||||||
|
txt = "you can't revoke this action because you did not confirm ir before"
|
||||||
|
raise ValidationError(txt)
|
||||||
|
|
||||||
|
|
||||||
class ConfirmRevoke(ActionWithMultipleDevices):
|
class ConfirmRevoke(ActionWithMultipleDevices):
|
||||||
__doc__ = m.ConfirmRevoke.__doc__
|
__doc__ = m.ConfirmRevoke.__doc__
|
||||||
action = NestedOn('Action', only_query='id')
|
action = NestedOn('Action', only_query='id')
|
||||||
|
|
|
@ -1068,6 +1068,7 @@ def test_endpoint_confirm(user: UserClient, user2: UserClient):
|
||||||
user2.post(res=models.Action, data=request_confirm, status=422)
|
user2.post(res=models.Action, data=request_confirm, status=422)
|
||||||
assert len(trade.acceptances) == 2
|
assert len(trade.acceptances) == 2
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.mvp
|
@pytest.mark.mvp
|
||||||
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
||||||
def test_confirm_revoke(user: UserClient, user2: UserClient):
|
def test_confirm_revoke(user: UserClient, user2: UserClient):
|
||||||
|
@ -1094,16 +1095,23 @@ def test_confirm_revoke(user: UserClient, user2: UserClient):
|
||||||
'devices': []
|
'devices': []
|
||||||
}
|
}
|
||||||
|
|
||||||
user2.post(res=models.Action, data=request_confirm)
|
|
||||||
|
|
||||||
request_revoke = {
|
request_revoke = {
|
||||||
'type': 'ConfirmRevoke',
|
'type': 'Revoke',
|
||||||
'action': trade.id,
|
'action': trade.id,
|
||||||
'devices': [],
|
'devices': [],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Normal confirmation
|
||||||
|
user2.post(res=models.Action, data=request_confirm)
|
||||||
|
|
||||||
|
# Normal revoke
|
||||||
user2.post(res=models.Action, data=request_revoke)
|
user2.post(res=models.Action, data=request_revoke)
|
||||||
|
|
||||||
|
# Error for try duplicate revoke
|
||||||
user2.post(res=models.Action, data=request_revoke, status=422)
|
user2.post(res=models.Action, data=request_revoke, status=422)
|
||||||
assert len(trade.acceptances) == 3
|
assert len(trade.acceptances) == 3
|
||||||
|
|
||||||
|
# You can to do one confirmation next of one revoke
|
||||||
user2.post(res=models.Action, data=request_confirm)
|
user2.post(res=models.Action, data=request_confirm)
|
||||||
assert len(trade.acceptances) == 4
|
assert len(trade.acceptances) == 4
|
||||||
|
|
Reference in New Issue