Commit da6d74cd authored by Adrien Oliva's avatar Adrien Oliva

feat(usecase): Implement account Delete usecase

parent ec4fd8cf
Pipeline #819 passed with stages
in 4 minutes
......@@ -219,3 +219,42 @@ class Create(base.UseCaseBase):
self._repo.register_account(new_account)
return base.ResponseSuccess()
class DeleteRequest(base.ValidRequest):
"""
Request use as input in Delete use cases
"""
def __init__(self, ident):
self.ident = ident
@classmethod
def from_dict(cls, adict):
"""
:adict Keys:
* *ident* (``str``) --
_mandatory_, String that identify account.
"""
errors = base.InvalidRequest()
if 'ident' not in adict:
errors.add_error('ident', 'Required argument')
if errors.has_errors():
return errors
return cls(**adict)
class Delete(base.UseCaseBase):
"""
Usecase to allow account deletion
"""
@base.safe_exec
def execute(self, request):
if not request:
return base.ResponseFailure.build_from_invalid_request(request)
self._log.debug('Delete account from request %s', request)
self._repo.delete_account(request.ident)
return base.ResponseSuccess()
......@@ -279,3 +279,43 @@ def test_account_create_invalid_request_no_from_dict(uccreate):
assert not bool(response)
account_mock.from_dict.assert_not_called()
repo.register_account.assert_not_called()
@pytest.fixture
def ucdelete(repo):
"""
Build a UseCase Delete tight to repo
"""
ucdelete = ucaccount.Delete(repo)
yield repo, ucdelete
def test_account_delete_valid_request(ucdelete):
"""
Use case to delete account
"""
repo, uc_delete = ucdelete
request = mock.MagicMock()
request.__bool__.return_value = True
response = uc_delete.execute(request)
assert bool(response)
repo.delete_account.assert_called_with(request.ident)
def test_account_delete_invalid_request(ucdelete):
"""
Use case to delete account
"""
repo, uc_delete = ucdelete
request = mock.MagicMock()
request.__bool__.return_value = False
response = uc_delete.execute(request)
assert not bool(response)
repo.delete_account.assert_not_called()
......@@ -307,3 +307,38 @@ def test_create_request_invalid_currency_and_balance():
'parameter': 'initialbalance',
'message': 'Must be a float'
}]
def test_delete_request_ident():
"""
Create a delete request
"""
req = ucaccount.DeleteRequest('foobar')
assert bool(req)
assert req.ident == 'foobar'
def test_delete_request_factory_valid():
"""
Create a delete request from factory with valid input
"""
req = ucaccount.DeleteRequest.from_dict({'ident': 'baz'})
assert bool(req)
assert req.ident == 'baz'
def test_delete_request_factory_invalid():
"""
Create a delete request from factory with invalid input
"""
req = ucaccount.DeleteRequest.from_dict({})
assert not bool(req)
assert isinstance(req, base.InvalidRequest)
assert req.errors == [
{
'parameter': 'ident',
'message': 'Required argument'
}
]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment