...
 
Commits (2)
......@@ -97,6 +97,7 @@ build:
tags:
- docker
script:
- sed -i "s|__version__ = '[^']*'|__version__ = '$(python ./setversion.py $(git describe --tags --always) | cut -d'+' -f1)'|" openbudget/__init__.py
- make dist
artifacts:
paths:
......@@ -107,9 +108,22 @@ upload:
tags:
- docker
script:
- pip install twine
- twine upload --repository pypi dist/* --username $PYPI_USER --password $PYPI_PASS
dependencies:
- build
only:
- tags
upload_master:
stage: deploy
tags:
- docker
script:
- pip install twine
- twine upload --repository pypi dist/* --username $PYPI_USER --password $PYPI_PASS
dependencies:
- build
only:
refs:
- master
......@@ -24,6 +24,6 @@ import configparser
__author__ = "Yapbreak"
__email__ = 'yapbreak@yapbreak.fr'
__version__ = '0.0.2'
__version__ = '9.9.9'
__config__ = configparser.ConfigParser()
......@@ -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()
......@@ -21,9 +21,10 @@
Package definition of OpenBudget
"""
from setuptools import setup
import openbudget
VERSION = "0.0.2"
VERSION = openbudget.__version__
with open('README.rst') as readme_file:
README = readme_file.read()
......
#!/usr/bin/env python
# coding: utf-8
# Simple budget management planner
# Copyright (C) 2020 Yapbreak
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
Tool module to parse version string and format it to PEP440
"""
import sys
class Version:
"""
Format version number class
"""
@staticmethod
def get_at(list_, index, default):
"""
Get item in a list at index and fallback on default if not available
"""
try:
return list_[index]
except IndexError:
return default
def __init__(self, version):
self.original = version
self.version = version
if version[0] == 'v':
self.version = version[1:]
dot_split = self.version.split('.')
if len(dot_split) == 1:
dot_split = ['0', '0', '2-0-g{}'.format(self.version)]
self.major = self.get_at(dot_split, 0, '0')
self.minor = self.get_at(dot_split, 1, '0')
dash_split = self.get_at(dot_split, 2, '0').split('-')
self.patch = self.get_at(dash_split, 0, '0')
if 'rc' in self.patch:
release_split = self.patch.split('rc')
self.patch = release_split[0]
self.release = release_split[1]
else:
self.release = None
self.dev = self.get_at(dash_split, 1, None)
self.commit = self.get_at(dash_split, 2, None)
def __str__(self):
pep440_version = '{}.{}.{}'.format(
self.major, self.minor, self.patch
)
if self.release is not None:
pep440_version += '.rc{}'.format(self.release)
if self.dev is not None:
pep440_version += '.dev{}'.format(self.dev)
if self.commit is not None:
pep440_version += '+{}'.format(self.commit)
return pep440_version
if __name__ == '__main__':
VERS = Version(sys.argv[1])
print(VERS)
......@@ -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'
}
]