Skip to content
Snippets Groups Projects
Commit 1e917498 authored by inso's avatar inso
Browse files

New workflow to create accounts and add communities

parent c6090dc7
No related branches found
No related tags found
No related merge requests found
Showing
with 529 additions and 188 deletions
...@@ -18,131 +18,173 @@ ...@@ -18,131 +18,173 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QGroupBox" name="groupBox"> <widget class="QStackedWidget" name="stacked_pages">
<property name="title"> <property name="currentIndex">
<string>Account parameters</string> <number>0</number>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <widget class="QWidget" name="page_init">
<item> <layout class="QVBoxLayout" name="verticalLayout_4">
<layout class="QHBoxLayout" name="horizontalLayout"> <item>
<item> <widget class="QGroupBox" name="groupBox">
<widget class="QLabel" name="label"> <property name="title">
<property name="text"> <string>Account parameters</string>
<string>Account name</string> </property>
</property> <layout class="QVBoxLayout" name="verticalLayout_2">
</widget> <item>
</item> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QLineEdit" name="edit_account_name"/> <widget class="QLabel" name="label">
</item> <property name="text">
</layout> <string>Account name</string>
</item> </property>
<item> </widget>
<layout class="QHBoxLayout" name="horizontalLayout_2"> </item>
<item> <item>
<widget class="QLabel" name="label_2"> <widget class="QLineEdit" name="edit_account_name"/>
<property name="text"> </item>
<string>PGPKey </string> </layout>
</property> </item>
</widget> <item>
</item> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item> <item>
<widget class="QComboBox" name="combo_keys_list"/> <widget class="QLabel" name="label_2">
</item> <property name="text">
</layout> <string>PGPKey </string>
</item> </property>
</layout> </widget>
</item>
<item>
<widget class="QComboBox" name="combo_keys_list"/>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page__communities">
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Communities membership</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QListView" name="list_communities">
<property name="contextMenuPolicy">
<enum>Qt::DefaultContextMenu</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="button_add_community">
<property name="text">
<string>Add a community</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="button_remove_community">
<property name="text">
<string>Remove selected community</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QGroupBox" name="groupBox_2"> <layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="title"> <property name="topMargin">
<string>Communities membership</string> <number>5</number>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_3"> <item>
<item> <widget class="QPushButton" name="button_previous">
<widget class="QListView" name="list_communities"> <property name="enabled">
<property name="contextMenuPolicy"> <bool>false</bool>
<enum>Qt::DefaultContextMenu</enum> </property>
</property> <property name="text">
</widget> <string>Previous</string>
</item> </property>
<item> </widget>
<layout class="QHBoxLayout" name="horizontalLayout_3"> </item>
<item> <item>
<widget class="QPushButton" name="button_add_community"> <spacer name="horizontalSpacer">
<property name="text"> <property name="orientation">
<string>Add a community</string> <enum>Qt::Horizontal</enum>
</property> </property>
</widget> <property name="sizeHint" stdset="0">
</item> <size>
<item> <width>40</width>
<widget class="QPushButton" name="button_remove_community"> <height>20</height>
<property name="text"> </size>
<string>Remove selected community</string> </property>
</property> </spacer>
</widget> </item>
</item> <item>
</layout> <widget class="QPushButton" name="button_next">
</item> <property name="text">
</layout> <string>Next</string>
</widget> </property>
</item> </widget>
<item> </item>
<widget class="QDialogButtonBox" name="button_box"> </layout>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>
<connections> <connections>
<connection> <connection>
<sender>button_box</sender> <sender>button_add_community</sender>
<signal>accepted()</signal> <signal>clicked()</signal>
<receiver>AccountConfigurationDialog</receiver> <receiver>AccountConfigurationDialog</receiver>
<slot>accept()</slot> <slot>open_process_add_community()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>248</x> <x>109</x>
<y>254</y> <y>237</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>157</x> <x>199</x>
<y>274</y> <y>149</y>
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection> <connection>
<sender>button_box</sender> <sender>button_remove_community</sender>
<signal>rejected()</signal> <signal>clicked()</signal>
<receiver>AccountConfigurationDialog</receiver> <receiver>AccountConfigurationDialog</receiver>
<slot>reject()</slot> <slot>action_remove_community()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>316</x> <x>290</x>
<y>260</y> <y>237</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>286</x> <x>199</x>
<y>274</y> <y>149</y>
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection> <connection>
<sender>button_add_community</sender> <sender>list_communities</sender>
<signal>clicked()</signal> <signal>doubleClicked(QModelIndex)</signal>
<receiver>AccountConfigurationDialog</receiver> <receiver>AccountConfigurationDialog</receiver>
<slot>open_process_add_community()</slot> <slot>open_process_edit_community(QModelIndex)</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>109</x> <x>199</x>
<y>237</y> <y>180</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>199</x> <x>199</x>
...@@ -151,14 +193,14 @@ ...@@ -151,14 +193,14 @@
</hints> </hints>
</connection> </connection>
<connection> <connection>
<sender>button_remove_community</sender> <sender>button_next</sender>
<signal>clicked()</signal> <signal>clicked()</signal>
<receiver>AccountConfigurationDialog</receiver> <receiver>AccountConfigurationDialog</receiver>
<slot>action_remove_community()</slot> <slot>next()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>290</x> <x>349</x>
<y>237</y> <y>278</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>199</x> <x>199</x>
...@@ -167,14 +209,14 @@ ...@@ -167,14 +209,14 @@
</hints> </hints>
</connection> </connection>
<connection> <connection>
<sender>list_communities</sender> <sender>button_previous</sender>
<signal>doubleClicked(QModelIndex)</signal> <signal>clicked()</signal>
<receiver>AccountConfigurationDialog</receiver> <receiver>AccountConfigurationDialog</receiver>
<slot>open_process_edit_community(QModelIndex)</slot> <slot>previous()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>199</x> <x>49</x>
<y>180</y> <y>278</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>199</x> <x>199</x>
...@@ -188,5 +230,7 @@ ...@@ -188,5 +230,7 @@
<slot>key_changed(int)</slot> <slot>key_changed(int)</slot>
<slot>action_remove_community()</slot> <slot>action_remove_community()</slot>
<slot>open_process_edit_community(QModelIndex)</slot> <slot>open_process_edit_community(QModelIndex)</slot>
<slot>next()</slot>
<slot>previous()</slot>
</slots> </slots>
</ui> </ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>WalletTabWidget</class>
<widget class="QWidget" name="WalletTabWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>walletTabWidget</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Trusts and hosters</string>
</property>
</widget>
</item>
<item>
<widget class="QTreeView" name="trusts_tree_view"/>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
<slots>
<slot>open_issuance_dialog()</slot>
</slots>
</ui>
import pytest import pytest
import ucoinpy as ucoin import ucoin
import gnupg import gnupg
from mock import Mock from mock import Mock
from cutecoin.models.account import Account from cutecoin.models.account import Account
...@@ -103,7 +103,7 @@ def patch_transactions_sent_get(*arg, **kwargs): ...@@ -103,7 +103,7 @@ def patch_transactions_sent_get(*arg, **kwargs):
} }
}]) }])
def patch_transactions_view_get(*arg, **kwargs): def patch_transactions_view_get(*arg, **kwargs):
return { return {
"signature": "-----BEGIN PGP SIGNATURE----- ... -----END PGP SIGNATURE-----", "signature": "-----BEGIN PGP SIGNATURE----- ... -----END PGP SIGNATURE-----",
...@@ -131,7 +131,7 @@ def patch_transactions_view_get(*arg, **kwargs): ...@@ -131,7 +131,7 @@ def patch_transactions_view_get(*arg, **kwargs):
"comment": "Too much coins ! Making big one." "comment": "Too much coins ! Making big one."
} }
} }
def patch_transactions_issuances_get(*arg, **kwargs): def patch_transactions_issuances_get(*arg, **kwargs):
return iter([{ return iter([{
"hash": "2E69197FAB029D8669EF85E82457A1587CA0ED9C", "hash": "2E69197FAB029D8669EF85E82457A1587CA0ED9C",
...@@ -168,12 +168,12 @@ def mock_gpg(): ...@@ -168,12 +168,12 @@ def mock_gpg():
'fingerprint': '2E69197FAB029D8669EF85E82457A1587CA0ED9C', 'fingerprint': '2E69197FAB029D8669EF85E82457A1587CA0ED9C',
'uids': [u'Mister Test <mister_test@testmail.com>'], 'uids': [u'Mister Test <mister_test@testmail.com>'],
'expires': u'', 'expires': u'',
'length': u'1024', 'length': u'1024',
'algo': u'17', 'algo': u'17',
'date': u'1221156445', 'date': u'1221156445',
'type': u'pub' 'type': u'pub'
}] }]
mock = Mock(spec=gnupg.GPG) mock = Mock(spec=gnupg.GPG)
instance = mock.return_value instance = mock.return_value
instance.list_keys = gpg_list_keys instance.list_keys = gpg_list_keys
...@@ -187,10 +187,6 @@ def mock_community(): ...@@ -187,10 +187,6 @@ def mock_community():
return patch_transactions_recipient_get() return patch_transactions_recipient_get()
elif type(request) is ucoin.hdc.transactions.sender.Last: elif type(request) is ucoin.hdc.transactions.sender.Last:
return patch_transactions_sent_get() return patch_transactions_sent_get()
elif type(request) is ucoin.hdc.transactions.View:
return patch_transactions_view_get()
elif type(request) is ucoin.hdc.transactions.sender.Issuance:
return patch_transactions_issuances_get()
elif type(request) is ucoin.hdc.coins.List: elif type(request) is ucoin.hdc.coins.List:
return { return {
"owner": "2E69197FAB029D8669EF85E82457A1587CA0ED9C", "owner": "2E69197FAB029D8669EF85E82457A1587CA0ED9C",
...@@ -202,7 +198,7 @@ def mock_community(): ...@@ -202,7 +198,7 @@ def mock_community():
"issuer": "2E69197FAB029D8669EF85E82457A1587CA0ED9C", "issuer": "2E69197FAB029D8669EF85E82457A1587CA0ED9C",
"ids": ["10-1-2-F-14"] "ids": ["10-1-2-F-14"]
}] }]
} }
elif type(request) == ucoin.pks.Lookup: elif type(request) == ucoin.pks.Lookup:
return user_keys[ get_args['search'] ] return user_keys[ get_args['search'] ]
else: else:
...@@ -218,13 +214,12 @@ def mock_communities(): ...@@ -218,13 +214,12 @@ def mock_communities():
mock = Mock(spec=Communities, communities_list=[]) mock = Mock(spec=Communities, communities_list=[])
return mock return mock
#TODO: Test account
class Test_Account: class Test_Account:
def test_account_create1(self, mock_communities): def test_account_create1(self, mock_communities):
account = Account.create("25500A07", "TestUser", mock_communities) account = Account.create("25500A07", "TestUser", mock_communities)
assert account is not None assert account is not None
def test_account_create2(self, monkeypatch, mock_communities, mock_community): def test_account_create2(self, monkeypatch, mock_communities, mock_community):
monkeypatch.setattr(gnupg, 'GPG', mock_gpg) monkeypatch.setattr(gnupg, 'GPG', mock_gpg)
mock_communities.communities_list=[mock_community] mock_communities.communities_list=[mock_community]
...@@ -256,12 +251,6 @@ class Test_Account: ...@@ -256,12 +251,6 @@ class Test_Account:
assert len(account.transactions_sent()) == 1 assert len(account.transactions_sent()) == 1
assert sum( trx.value() for trx in account.transactions_sent()) == 200 assert sum( trx.value() for trx in account.transactions_sent()) == 200
def test_account_last_issuances(self, monkeypatch, mock_community, mock_communities):
monkeypatch.setattr(gnupg, 'GPG', mock_gpg)
mock_communities.communities_list=[mock_community]
account = Account.create("25500A07", "TestUser", mock_communities)
assert len(account.last_issuances(mock_community)) == 1
def test_account_issued_last_dividend(self): def test_account_issued_last_dividend(self):
pass pass
......
import pytest import pytest
import ucoinpy as ucoin import ucoin
from cutecoin.models.account.communities import Communities from cutecoin.models.account.communities import Communities
......
import pytest import pytest
import ucoinpy as ucoin import ucoin
from mock import Mock, MagicMock from mock import Mock, MagicMock
from cutecoin.models.wallet import Wallet from cutecoin.models.wallet import Wallet
from cutecoin.models.account.wallets import Wallets from cutecoin.models.account.wallets import Wallets
from cutecoin.models.community import Community, CommunityNetwork from cutecoin.models.community import Community, CommunityNetwork
def mock_community(): def mock_community():
def community_request(request): def community_request(request):
if type(request) is ucoin.hdc.coins.List: if type(request) is ucoin.hdc.coins.List:
...@@ -23,20 +22,19 @@ def mock_community(): ...@@ -23,20 +22,19 @@ def mock_community():
} }
else: else:
assert 0 assert 0
mock_network = Mock(spec=CommunityNetwork, request=community_request) mock_network = Mock(spec=CommunityNetwork, request=community_request)
community = MagicMock(spec=Community, network=mock_network) community = MagicMock(spec=Community, network=mock_network)
return community return community
def mock_wallet(): def mock_wallet():
def wallet_eq(mock1, mock2): def wallet_eq(mock1, mock2):
return mock1.community == mock2.community return mock1.community == mock2.community
mock_wallet = MagicMock(spec=Wallet, __eq__=wallet_eq) mock_wallet = MagicMock(spec=Wallet, __eq__=wallet_eq)
#TODO: Test wallets
class Test_Wallets: class Test_Wallets:
def test_wallets_add_wallet(self): def test_wallets_add_wallet(self):
wallets = Wallets() wallets = Wallets()
...@@ -53,7 +51,7 @@ class Test_Wallets: ...@@ -53,7 +51,7 @@ class Test_Wallets:
wallets = Wallets() wallets = Wallets()
wallets.wallets_list.append(mock_wallet1) wallets.wallets_list.append(mock_wallet1)
wallets.wallets_list.append(mock_wallet2) wallets.wallets_list.append(mock_wallet2)
assert wallets.get_wallet(mock_wallet1) is not None assert wallets.get_wallet(mock_wallet1) is not None
assert wallets.get_wallet(mock_wallet2) is not None assert wallets.get_wallet(mock_wallet2) is not None
assert wallets.get_wallet(mock_wallet3) is None assert wallets.get_wallet(mock_wallet3) is None
...@@ -66,7 +64,7 @@ class Test_Wallets: ...@@ -66,7 +64,7 @@ class Test_Wallets:
wallets = Wallets() wallets = Wallets()
wallets.wallets_list.append(mock_wallet1) wallets.wallets_list.append(mock_wallet1)
wallets.wallets_list.append(mock_wallet2) wallets.wallets_list.append(mock_wallet2)
wallets.remove_all_wallets_of(mock1) wallets.remove_all_wallets_of(mock1)
assert wallets.get_wallet(mock_wallet1) is None assert wallets.get_wallet(mock_wallet1) is None
assert wallets.get_wallet(mock_wallet2) is not None assert wallets.get_wallet(mock_wallet2) is not None
......
import pytest import pytest
from mock import Mock from mock import Mock
import ucoinpy as ucoin import ucoin
from cutecoin.models.community import Community from cutecoin.models.community import Community
from cutecoin.models.community import Node from cutecoin.models.community import Node
from cutecoin.models.account.wallets import Wallets from cutecoin.models.account.wallets import Wallets
...@@ -11,7 +11,7 @@ from cutecoin.models.node import Node ...@@ -11,7 +11,7 @@ from cutecoin.models.node import Node
amendment_hash = "3682F828EFB1A1AFF45ACC6DDBB2BAD100DCD605" amendment_hash = "3682F828EFB1A1AFF45ACC6DDBB2BAD100DCD605"
def patch_amendment_current_get(*args, **kwargs): def patch_amendment_Promoted_get(*args, **kwargs):
return { return {
"version": "1", "version": "1",
"currency": "beta_brousouf", "currency": "beta_brousouf",
...@@ -45,7 +45,7 @@ VotersChanges: ...@@ -45,7 +45,7 @@ VotersChanges:
-C73882B64B7E72237A2F460CE9CAB76D19A8651E -C73882B64B7E72237A2F460CE9CAB76D19A8651E
""" """
} }
def patch_amendments_members_get(*args, **kwargs): def patch_amendments_members_get(*args, **kwargs):
return iter([{ return iter([{
...@@ -87,41 +87,41 @@ def mock_node(): ...@@ -87,41 +87,41 @@ def mock_node():
class Test_Community(): class Test_Community():
def test_community_create(self, monkeypatch, mock_node): def test_community_create(self, monkeypatch, mock_node):
monkeypatch.setattr(ucoin.hdc.amendments.Current, monkeypatch.setattr(ucoin.hdc.amendments.Promoted,
'__get__', patch_amendment_current_get) '__get__', patch_amendment_Promoted_get)
community = Community.create(mock_node) community = Community.create(mock_node)
assert community is not None assert community is not None
def test_community_dividend(self, monkeypatch, mock_node): def test_community_dividend(self, monkeypatch, mock_node):
monkeypatch.setattr(ucoin.hdc.amendments.Current, monkeypatch.setattr(ucoin.hdc.amendments.Promoted,
'__get__', patch_amendment_current_get) '__get__', patch_amendment_Promoted_get)
community = Community.create(mock_node) community = Community.create(mock_node)
assert community.dividend() == 100 assert community.dividend() == 100
def test_community_coin_minimal_power(self, monkeypatch, mock_node): def test_community_coin_minimal_power(self, monkeypatch, mock_node):
monkeypatch.setattr(ucoin.hdc.amendments.Current, monkeypatch.setattr(ucoin.hdc.amendments.Promoted,
'__get__', patch_amendment_current_get) '__get__', patch_amendment_Promoted_get)
community = Community.create(mock_node) community = Community.create(mock_node)
assert community.coin_minimal_power() == 0 assert community.coin_minimal_power() == 0
def test_community_amendment_id(self, monkeypatch, mock_node): def test_community_amendment_id(self, monkeypatch, mock_node):
monkeypatch.setattr(ucoin.hdc.amendments.Current, monkeypatch.setattr(ucoin.hdc.amendments.Promoted,
'__get__', patch_amendment_current_get) '__get__', patch_amendment_Promoted_get)
community = Community.create(mock_node) community = Community.create(mock_node)
assert community.amendment_id() == "2-"+amendment_hash.upper() assert community.amendment_id() == "2-"+amendment_hash.upper()
def test_community_amendment_number(self, monkeypatch, mock_node): def test_community_amendment_number(self, monkeypatch, mock_node):
monkeypatch.setattr(ucoin.hdc.amendments.Current, monkeypatch.setattr(ucoin.hdc.amendments.Promoted,
'__get__', patch_amendment_current_get) '__get__', patch_amendment_Promoted_get)
community = Community.create(mock_node) community = Community.create(mock_node)
assert community.amendment_number() == 2 assert community.amendment_number() == 2
def test_community_person_quality(self, monkeypatch, mock_node): def test_community_person_quality(self, monkeypatch, mock_node):
monkeypatch.setattr(ucoin.hdc.amendments.Current, monkeypatch.setattr(ucoin.hdc.amendments.Promoted,
'__get__', patch_amendment_current_get) '__get__', patch_amendment_Promoted_get)
monkeypatch.setattr(ucoin.hdc.amendments.view.Members, monkeypatch.setattr(ucoin.registry.community.Members,
'__get__', patch_amendments_members_get) '__get__', patch_amendments_members_get)
monkeypatch.setattr(ucoin.hdc.amendments.view.Voters, monkeypatch.setattr(ucoin.registry.community.Voters,
'__get__', patch_amendments_voters_get) '__get__', patch_amendments_voters_get)
community = Community.create(mock_node) community = Community.create(mock_node)
assert community.person_quality("2E69197FAB029D8669EF85E82457A1587CA0ED9C") == "voter" assert community.person_quality("2E69197FAB029D8669EF85E82457A1587CA0ED9C") == "voter"
...@@ -130,11 +130,11 @@ class Test_Community(): ...@@ -130,11 +130,11 @@ class Test_Community():
assert community.person_quality("3F871197FAB029D8669EF85E82457A1587CA0ED9C") == "nothing" assert community.person_quality("3F871197FAB029D8669EF85E82457A1587CA0ED9C") == "nothing"
def test_community_members_fingerprint(self, monkeypatch, mock_node): def test_community_members_fingerprint(self, monkeypatch, mock_node):
monkeypatch.setattr(ucoin.hdc.amendments.Current, monkeypatch.setattr(ucoin.hdc.amendments.Promoted,
'__get__', patch_amendment_current_get) '__get__', patch_amendment_Promoted_get)
monkeypatch.setattr(ucoin.hdc.amendments.view.Members, monkeypatch.setattr(ucoin.registry.community.Members,
'__get__', patch_amendments_members_get) '__get__', patch_amendments_members_get)
monkeypatch.setattr(ucoin.hdc.amendments.view.Voters, monkeypatch.setattr(ucoin.registry.community.Voters,
'__get__', patch_amendments_voters_get) '__get__', patch_amendments_voters_get)
community = Community.create(mock_node) community = Community.create(mock_node)
...@@ -144,11 +144,11 @@ class Test_Community(): ...@@ -144,11 +144,11 @@ class Test_Community():
assert "3F871197FAB029D8669EF85E82457A1587CA0ED9C" not in community.members_fingerprints() assert "3F871197FAB029D8669EF85E82457A1587CA0ED9C" not in community.members_fingerprints()
def test_community_voters_fingerprint(self, monkeypatch, mock_node): def test_community_voters_fingerprint(self, monkeypatch, mock_node):
monkeypatch.setattr(ucoin.hdc.amendments.Current, monkeypatch.setattr(ucoin.registry.community.Members,
'__get__', patch_amendment_current_get) '__get__', patch_amendment_Promoted_get)
monkeypatch.setattr(ucoin.hdc.amendments.view.Members, monkeypatch.setattr(ucoin.registry.community.Members,
'__get__', patch_amendments_members_get) '__get__', patch_amendments_members_get)
monkeypatch.setattr(ucoin.hdc.amendments.view.Voters, monkeypatch.setattr(ucoin.registry.community.Voters,
'__get__', patch_amendments_voters_get) '__get__', patch_amendments_voters_get)
community = Community.create(mock_node) community = Community.create(mock_node)
...@@ -156,10 +156,9 @@ class Test_Community(): ...@@ -156,10 +156,9 @@ class Test_Community():
assert "3F870197FAB029D8669EF85E82457A1587CA0ED9C" in community.voters_fingerprints() assert "3F870197FAB029D8669EF85E82457A1587CA0ED9C" in community.voters_fingerprints()
assert "3F871197FAB029D8669EF85E82457A1587CA0ED9C" not in community.voters_fingerprints() assert "3F871197FAB029D8669EF85E82457A1587CA0ED9C" not in community.voters_fingerprints()
#TODO: Test community json
def test_community_jsonify(self, monkeypatch): def test_community_jsonify(self, monkeypatch):
monkeypatch.setattr(ucoin.hdc.amendments.Current, monkeypatch.setattr(ucoin.hdc.amendments.Promoted,
'__get__', patch_amendment_current_get) '__get__', patch_amendment_Promoted_get)
main_node = Node(trust=True, hoster=True, main_node = Node(trust=True, hoster=True,
server="192.168.100.10", port=3800) server="192.168.100.10", port=3800)
community = Community.create(main_node) community = Community.create(main_node)
...@@ -167,5 +166,5 @@ class Test_Community(): ...@@ -167,5 +166,5 @@ class Test_Community():
json = community.jsonify(wallets) json = community.jsonify(wallets)
account = Mock(spec=Account) account = Mock(spec=Account)
community2 = Community.load(json, account) community2 = Community.load(json, account)
assert community2.network.nodes[0].server == community.network.nodes[0].server assert community2.network.nodes[0].server == community.network.nodes[0].server
import pytest import pytest
import ucoinpy as ucoin import ucoin
from mock import Mock, MagicMock, patch from mock import Mock, MagicMock, patch
from cutecoin.models.wallet import Wallet from cutecoin.models.wallet import Wallet
from cutecoin.models.community import Community, CommunityNetwork from cutecoin.models.community import Community, CommunityNetwork
...@@ -21,10 +21,10 @@ def mock_community(): ...@@ -21,10 +21,10 @@ def mock_community():
} }
else: else:
assert 0 assert 0
def community_eq(mock1, mock2): def community_eq(mock1, mock2):
return mock1.amendment_id() == mock2.amendment_id() return mock1.amendment_id() == mock2.amendment_id()
mock_network = Mock(spec=CommunityNetwork, request=community_request) mock_network = Mock(spec=CommunityNetwork, request=community_request)
community = MagicMock(spec=Community, network=mock_network, __eq__=community_eq) community = MagicMock(spec=Community, network=mock_network, __eq__=community_eq)
...@@ -49,7 +49,7 @@ class Test_Wallet: ...@@ -49,7 +49,7 @@ class Test_Wallet:
def test_wallet_get_text(self): def test_wallet_get_text(self):
pass pass
def test_eq(self): def test_eq(self):
mock1 = mock_community() mock1 = mock_community()
mock1.amendment_id.return_value = "2-AMENDMENTTEST" mock1.amendment_id.return_value = "2-AMENDMENTTEST"
...@@ -59,7 +59,7 @@ class Test_Wallet: ...@@ -59,7 +59,7 @@ class Test_Wallet:
wallet2 = Wallet([], mock2) wallet2 = Wallet([], mock2)
assert wallet1 == wallet2 assert wallet1 == wallet2
def test_not_eq(self): def test_not_eq(self):
mock1 = mock_community() mock1 = mock_community()
mock1.amendment_id.return_value = "2-AMENDMENTTEST" mock1.amendment_id.return_value = "2-AMENDMENTTEST"
...@@ -69,11 +69,11 @@ class Test_Wallet: ...@@ -69,11 +69,11 @@ class Test_Wallet:
wallet2 = Wallet([], mock2) wallet2 = Wallet([], mock2)
assert wallet1 != wallet2 assert wallet1 != wallet2
def test_wallet_jsonify(self, monkeypatch): def test_wallet_jsonify(self, monkeypatch):
wallet = Wallet([], mock_community()) wallet = Wallet([], mock_community())
wallet.refresh_coins("86F7E437FAA5A7FCE15D1DDCB9EAEAEA377667B8") wallet.refresh_coins("86F7E437FAA5A7FCE15D1DDCB9EAEAEA377667B8")
json = wallet.jsonify() json = wallet.jsonify()
wallet2 = Wallet.load(json, mock_community()) wallet2 = Wallet.load(json, mock_community())
same_coins = [coin1 for coin1, coin2 in zip(wallet.coins, wallet2.coins) if coin1 == coin2] same_coins = [coin1 for coin1, coin2 in zip(wallet.coins, wallet2.coins) if coin1 == coin2]
assert len(same_coins) == len(wallet.coins) and len(same_coins) == len(wallet2.coins) assert len(same_coins) == len(wallet.coins) and len(same_coins) == len(wallet2.coins)
\ No newline at end of file \ No newline at end of file
...@@ -8,7 +8,6 @@ from PyQt5.QtWidgets import QApplication, QDialog ...@@ -8,7 +8,6 @@ from PyQt5.QtWidgets import QApplication, QDialog
from cutecoin.gui.mainWindow import MainWindow from cutecoin.gui.mainWindow import MainWindow
from cutecoin.core import Core from cutecoin.core import Core
#TODO: Rename all functions to match python style
if __name__ == '__main__': if __name__ == '__main__':
app = QApplication(sys.argv) app = QApplication(sys.argv)
......
...@@ -24,5 +24,4 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget): ...@@ -24,5 +24,4 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget):
self.setupUi(self) self.setupUi(self)
self.community = community self.community = community
self.account = account self.account = account
#TODO: Rename to list:
self.list_community_members.setModel(MembersListModel(community)) self.list_community_members.setModel(MembersListModel(community))
...@@ -6,7 +6,7 @@ Created on 1 févr. 2014 ...@@ -6,7 +6,7 @@ Created on 1 févr. 2014
from cutecoin.gen_resources.mainwindow_uic import Ui_MainWindow from cutecoin.gen_resources.mainwindow_uic import Ui_MainWindow
from PyQt5.QtWidgets import QMainWindow, QAction, QErrorMessage, QDialogButtonBox from PyQt5.QtWidgets import QMainWindow, QAction, QErrorMessage, QDialogButtonBox
from PyQt5.QtCore import QSignalMapper from PyQt5.QtCore import QSignalMapper
from cutecoin.gui.configureAccountDialog import ConfigureAccountDialog from cutecoin.gui.processConfigureAccount import ProcessConfigureAccount
from cutecoin.gui.transferMoneyDialog import TransferMoneyDialog from cutecoin.gui.transferMoneyDialog import TransferMoneyDialog
from cutecoin.gui.communityTabWidget import CommunityTabWidget from cutecoin.gui.communityTabWidget import CommunityTabWidget
from cutecoin.gui.addContactDialog import AddContactDialog from cutecoin.gui.addContactDialog import AddContactDialog
...@@ -35,10 +35,8 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -35,10 +35,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.refresh() self.refresh()
def open_add_account_dialog(self): def open_add_account_dialog(self):
dialog = ConfigureAccountDialog(self.core, None) dialog = ProcessConfigureAccount(self.core, None)
dialog.button_box.button( dialog.accepted.connect(self.refresh)
QDialogButtonBox.Ok).clicked.connect(
self.refresh)
dialog.exec_() dialog.exec_()
def save(self): def save(self):
...@@ -56,10 +54,8 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -56,10 +54,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
AddContactDialog(self.core.current_account, self).exec_() AddContactDialog(self.core.current_account, self).exec_()
def open_configure_account_dialog(self): def open_configure_account_dialog(self):
dialog = ConfigureAccountDialog(self.core, self.core.current_account) dialog = ProcessConfigureAccount(self.core, self.core.current_account)
dialog.button_box.button( dialog.accepted.connect(self.refresh)
QDialogButtonBox.Ok).clicked.connect(
self.refresh)
dialog.exec_() dialog.exec_()
''' '''
......
...@@ -16,7 +16,60 @@ from PyQt5.QtWidgets import QDialog, QErrorMessage, QInputDialog ...@@ -16,7 +16,60 @@ from PyQt5.QtWidgets import QDialog, QErrorMessage, QInputDialog
import gnupg import gnupg
class ConfigureAccountDialog(QDialog, Ui_AccountConfigurationDialog): class Step():
def __init__(self, config_dialog, previous_step=None, next_step=None):
self.previous_step = previous_step
self.next_step = next_step
self.config_dialog = config_dialog
class StepPageInit(Step):
'''
First step when adding a community
'''
def __init__(self, config_dialog):
super().__init__(config_dialog)
def is_valid(self):
return True
def process_next(self):
pass
def display_page(self):
self.config_dialog.button_previous.setEnabled(False)
class StepPageCommunities(Step):
'''
First step when adding a community
'''
def __init__(self, config_dialog):
super().__init__(config_dialog)
def is_valid(self):
return True
def process_next(self):
'''
We create the community
'''
server = self.config_dialog.lineedit_server.text()
port = self.config_dialog.spinbox_port.value()
default_node = Node(server, port, trust=True, hoster=True)
account = self.config_dialog.account
self.config_dialog.community = account.communities.add_community(
default_node)
#TODO: Get existing Wallet from ucoin node
account.wallets.add_wallet(account.fingerprint,
self.config_dialog.community)
def display_page(self):
self.config_dialog.button_previous.setEnabled(False)
self.config_dialog.button_next.setText("Ok")
class ProcessConfigureAccount(QDialog, Ui_AccountConfigurationDialog):
''' '''
classdocs classdocs
''' '''
...@@ -26,10 +79,14 @@ class ConfigureAccountDialog(QDialog, Ui_AccountConfigurationDialog): ...@@ -26,10 +79,14 @@ class ConfigureAccountDialog(QDialog, Ui_AccountConfigurationDialog):
Constructor Constructor
''' '''
# Set up the user interface from Designer. # Set up the user interface from Designer.
super(ConfigureAccountDialog, self).__init__() super(ProcessConfigureAccount, self).__init__()
self.setupUi(self) self.setupUi(self)
self.account = account self.account = account
self.core = core self.core = core
step_init = StepPageInit(self)
step_communities = StepPageCommunities(self)
step_init.next_step = step_communities
self.step = step_init
if self.account is None: if self.account is None:
self.setWindowTitle("New account") self.setWindowTitle("New account")
else: else:
...@@ -61,6 +118,7 @@ class ConfigureAccountDialog(QDialog, Ui_AccountConfigurationDialog): ...@@ -61,6 +118,7 @@ class ConfigureAccountDialog(QDialog, Ui_AccountConfigurationDialog):
def open_process_add_community(self): def open_process_add_community(self):
dialog = ProcessConfigureCommunity(self.account, None) dialog = ProcessConfigureCommunity(self.account, None)
dialog.accepted.connect(self.action_add_community)
dialog.exec_() dialog.exec_()
def action_add_community(self): def action_add_community(self):
...@@ -90,6 +148,24 @@ class ConfigureAccountDialog(QDialog, Ui_AccountConfigurationDialog): ...@@ -90,6 +148,24 @@ class ConfigureAccountDialog(QDialog, Ui_AccountConfigurationDialog):
available_keys = gpg.list_keys(True) available_keys = gpg.list_keys(True)
self.account.keyid = available_keys[key_index]['keyid'] self.account.keyid = available_keys[key_index]['keyid']
def next(self):
if self.step.next_step is not None:
if self.step.is_valid():
self.step.process_next()
self.step = self.step.next_step
next_index = self.stacked_pages.currentIndex() + 1
self.stacked_pages.setCurrentIndex(next_index)
self.step.display_page()
else:
self.accepted.emit()
def previous(self):
if self.step.previous_step is not None:
self.step = self.step.previous_step
previous_index = self.stacked_pages.currentIndex() - 1
self.stacked_pages.setCurrentIndex(previous_index)
self.step.display_page()
def accept(self): def accept(self):
if self.account not in self.core.accounts: if self.account not in self.core.accounts:
self.account.name = self.edit_account_name.text() self.account.name = self.edit_account_name.text()
......
'''
Created on 8 mars 2014
@author: inso
'''
import ucoin
from cutecoin.gen_resources.communityConfigurationDialog_uic import Ui_CommunityConfigurationDialog
from PyQt5.QtWidgets import QDialog, QMenu, QMessageBox
from cutecoin.models.community.treeModel import CommunityTreeModel
from cutecoin.models.community.trustsTreeModel import CommunityTrustsTreeModel
from cutecoin.models.node import Node
from cutecoin.gui.walletTabWidget import WalletTabWidget
class Step():
def __init__(self, config_dialog, previous_step=None, next_step=None):
self.previous_step = previous_step
self.next_step = next_step
self.config_dialog = config_dialog
class StepPageInit(Step):
'''
First step when adding a community
'''
def __init__(self, config_dialog):
super().__init__(config_dialog)
def is_valid(self):
server = self.config_dialog.lineedit_server.text()
port = self.config_dialog.spinbox_port.value()
try:
ucoin.network.Peering(server, port)
except:
QMessageBox.critical(self, "Server error",
"Cannot get node peering")
return False
return True
def process_next(self):
'''
We create the community
'''
server = self.config_dialog.lineedit_server.text()
port = self.config_dialog.spinbox_port.value()
default_node = Node(server, port, trust=True, hoster=True)
account = self.config_dialog.account
self.config_dialog.community = account.communities.add_community(
default_node)
#TODO: Get existing Wallet from ucoin node
account.wallets.add_wallet(account.fingerprint,
self.config_dialog.community)
def display_page(self):
self.config_dialog.button_previous.setEnabled(False)
class StepPageAddNodes(Step):
'''
The step where the user add nodes
'''
def __init__(self, config_dialog):
super().__init__(config_dialog)
#TODO: Check page validity
def is_valid(self):
return True
def process_next(self):
pass
def display_page(self):
tree_model = CommunityTreeModel(self.config_dialog.community)
self.config_dialog.tree_nodes.setModel(tree_model)
self.config_dialog.button_previous.setEnabled(False)
self.config_dialog.button_next.setText("Next")
class StepPageSetWallets(Step):
'''
The step where the user set his wallets
'''
def __init__(self, config_dialog):
super().__init__(config_dialog)
#TODO: Check page validity
def is_valid(self):
return True
def display_page(self):
self.config_dialog.tabs_wallets.clear()
for wallet in self.config_dialog.account.wallets.wallets_list:
wallet_tab = WalletTabWidget(self.config_dialog.account,
self.config_dialog.community)
self.config_dialog.tabs_wallets.addTab(wallet_tab, wallet.name)
tree_model = CommunityTrustsTreeModel(self.config_dialog.community)
current_tab = self.config_dialog.tabs_wallets.currentWidget()
current_tab.trusts_tree_view.setModel(tree_model)
self.config_dialog.button_previous.setEnabled(True)
self.config_dialog.button_next.setText("Ok")
def process_next(self):
pass
class ProcessConfigureCommunity(QDialog, Ui_CommunityConfigurationDialog):
'''
Dialog to configure or add a community
'''
def __init__(self, account, community, default_node=None):
'''
Constructor
'''
super(ProcessConfigureCommunity, self).__init__()
self.setupUi(self)
self.community = community
self.account = account
self.step = None
step_init = StepPageInit(self)
step_add_nodes = StepPageAddNodes(self)
step_set_wallets = StepPageSetWallets(self)
step_init.next_step = step_add_nodes
step_add_nodes.next_step = step_set_wallets
step_set_wallets.previous_step = step_add_nodes
if self.community is not None:
self.stacked_pages.removeWidget(self.page_init)
self.step = step_add_nodes
self.setWindowTitle("Configure community "
+ self.community.currency)
else:
self.step = step_init
self.setWindowTitle("Add a community")
def next(self):
if self.step.next_step is not None:
if self.step.is_valid():
self.step.process_next()
self.step = self.step.next_step
next_index = self.stacked_pages.currentIndex() + 1
self.stacked_pages.setCurrentIndex(next_index)
self.step.display_page()
else:
self.accepted.emit()
self.close()
def previous(self):
if self.step.previous_step is not None:
self.step = self.step.previous_step
previous_index = self.stacked_pages.currentIndex() - 1
self.stacked_pages.setCurrentIndex(previous_index)
self.step.display_page()
def add_node(self):
'''
Add node slot
'''
server = self.edit_server.text()
port = self.box_port.value()
if self.community is not None:
self.community.nodes.append(Node(server, port, trust=True))
self.tree_nodes.setModel(CommunityTreeModel(self.community))
def showContextMenu(self, point):
menu = QMenu()
action = menu.addAction("Delete", self.removeNode)
if self.community is not None:
if len(self.community.nodes) == 1:
action.setEnabled(False)
menu.exec_(self.tree_nodes.mapToGlobal(point))
'''
Created on 2 févr. 2014
@author: inso
'''
import logging
from PyQt5.QtWidgets import QWidget
from cutecoin.gen_resources.walletTabWidget_uic import Ui_WalletTabWidget
class WalletTabWidget(QWidget, Ui_WalletTabWidget):
'''
classdocs
'''
def __init__(self, account, community):
'''
Constructor
'''
super(WalletTabWidget, self).__init__()
self.setupUi(self)
self.community = community
self.account = account
...@@ -19,13 +19,13 @@ class Wallets(object): ...@@ -19,13 +19,13 @@ class Wallets(object):
''' '''
self.wallets_list = [] self.wallets_list = []
def add_wallet(self, community): def add_wallet(self, fingerprint, community, name="Main Wallet"):
''' '''
Create a new wallet of a specific currency. Create a new wallet of a specific currency.
This wallet must not already be present in the account, This wallet must not already be present in the account,
it means the wallet must have a different name or a different currency. it means the wallet must have a different name or a different currency.
''' '''
wallet = Wallet.create(community) wallet = Wallet.create(fingerprint, community, name)
if wallet not in self.wallets_list: if wallet not in self.wallets_list:
self.wallets_list.append(wallet) self.wallets_list.append(wallet)
return wallet return wallet
......
...@@ -120,7 +120,7 @@ class CommunityTrustsTreeModel(QAbstractItemModel): ...@@ -120,7 +120,7 @@ class CommunityTrustsTreeModel(QAbstractItemModel):
node_item = NodeItem(node, self.root_item) node_item = NodeItem(node, self.root_item)
logging.debug( logging.debug(
"mainNode : " + "mainNode : " +
node.getText() + node.get_text() +
" / " + " / " +
node_item.data(0)) node_item.data(0))
self.root_item.appendChild(node_item) self.root_item.appendChild(node_item)
...@@ -128,7 +128,7 @@ class CommunityTrustsTreeModel(QAbstractItemModel): ...@@ -128,7 +128,7 @@ class CommunityTrustsTreeModel(QAbstractItemModel):
child_node_item = NodeItem(node, node_item) child_node_item = NodeItem(node, node_item)
logging.debug( logging.debug(
"\t node : " + "\t node : " +
node.getText() + node.get_text() +
" / " + " / " +
child_node_item.data(0)) child_node_item.data(0))
node_item.appendChild(child_node_item) node_item.appendChild(child_node_item)
...@@ -19,7 +19,7 @@ class Wallet(object): ...@@ -19,7 +19,7 @@ class Wallet(object):
It's only used to sort coins. It's only used to sort coins.
''' '''
def __init__(self, fingerprint, coins, community, name="Main Wallet"): def __init__(self, fingerprint, coins, community, name):
''' '''
Constructor Constructor
''' '''
...@@ -29,8 +29,8 @@ class Wallet(object): ...@@ -29,8 +29,8 @@ class Wallet(object):
self.name = name self.name = name
@classmethod @classmethod
def create(cls, community): def create(cls, fingerprint, community, name):
return cls([], community) return cls(fingerprint, [], community, name)
@classmethod @classmethod
def load(cls, json_data, community): def load(cls, json_data, community):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment