Skip to content
Snippets Groups Projects
Commit 77a615f7 authored by inso's avatar inso
Browse files

Add user parameters file

parent e7daa0fa
No related branches found
No related tags found
No related merge requests found
...@@ -4,3 +4,4 @@ from .certification import Certification ...@@ -4,3 +4,4 @@ from .certification import Certification
from .transaction import Transaction from .transaction import Transaction
from .node import Node from .node import Node
from .connection import Connection from .connection import Connection
from .user_parameters import UserParameters
import attr
@attr.s()
class UserParameters:
"""
The user parameters entity
"""
lang = attr.ib(convert=str, default="en_US")
referential = attr.ib(convert=int, default=0)
expert_mode = attr.ib(convert=bool, default=False)
digits_after_comma = attr.ib(convert=int, default=2)
maximized = attr.ib(convert=bool, default=False)
notifications = attr.ib(convert=bool, default=True)
enable_proxy = attr.ib(convert=bool, default=True)
proxy_type = attr.ib(convert=int, default=0)
proxy_address = attr.ib(convert=str, default="")
proxy_port = attr.ib(convert=int, default=8080)
international_system_of_units = attr.ib(convert=int, default=False)
forgetfulness = attr.ib(convert=bool, default=True)
from .user_parameters import UserParametersFile
\ No newline at end of file
import attr
import json
from ..entities import UserParameters
@attr.s(frozen=True)
class UserParametersFile:
"""
The repository for UserParameters
"""
_file = attr.ib()
def save(self, user_parameters):
"""
Commit a user_parameters to the database
:param sakia.data.entities.UserParameters user_parameters: the user_parameters to commit
"""
with open(self._file, 'w') as outfile:
json.dump(attr.asdict(user_parameters), outfile, indent=4)
def load(self):
"""
Update an existing user_parameters in the database
:param sakia.data.entities.UserParameters user_parameters: the user_parameters to update
"""
with open(self._file, 'r') as json_data:
user_parameters = UserParameters(**json.load(json_data))
return user_parameters
\ No newline at end of file
...@@ -93,10 +93,12 @@ CREATE TABLE IF NOT EXISTS nodes( ...@@ -93,10 +93,12 @@ CREATE TABLE IF NOT EXISTS nodes(
PRIMARY KEY (currency, pubkey) PRIMARY KEY (currency, pubkey)
); );
-- Keys TABLE -- Cnnections TABLE
CREATE TABLE IF NOT EXISTS connections( CREATE TABLE IF NOT EXISTS connections(
currency VARCHAR(30), currency VARCHAR(30),
pubkey VARCHAR(50), pubkey VARCHAR(50),
salt VARCHAR(50), salt VARCHAR(50),
PRIMARY KEY (currency, pubkey) PRIMARY KEY (currency, pubkey)
); );
from sakia.data.entities import UserParameters
from sakia.data.files import UserParametersFile
import tempfile
import unittest
import os
class TestUserParametersFile(unittest.TestCase):
def test_init_save_load(self):
file = os.path.join(tempfile.mkdtemp(), "params.json")
user_parameters = UserParameters()
user_parameters_file = UserParametersFile(file)
user_parameters.proxy_address = "test.fr"
user_parameters_file.save(user_parameters)
user_parameters_2 = user_parameters_file.load()
self.assertEqual(user_parameters, user_parameters_2)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment