source: geniuswebcore/test/geniusweb/protocol/session/ConnectionWithPartiesTest.py@ 75

Last change on this file since 75 was 73, checked in by Bart Vastenhouw, 3 years ago

Fix for IssueValue hashcode.

File size: 2.8 KB
Line 
1from typing import List
2import unittest
3from unittest.mock import Mock
4
5from unitpy.GeneralTests import GeneralTests
6
7from geniusweb.actions.PartyId import PartyId
8from geniusweb.protocol.partyconnection.ProtocolToPartyConn import ProtocolToPartyConn
9from geniusweb.protocol.partyconnection.ProtocolToPartyConnections import ProtocolToPartyConnections
10
11
12class ConnectionWithPartiesTest (unittest.TestCase, GeneralTests[ProtocolToPartyConnections]):
13 party1 = PartyId("party1")
14 party2 = PartyId("party2")
15 party3 = PartyId("party3")
16
17 con1 = Mock(ProtocolToPartyConn)
18 con2 = Mock(ProtocolToPartyConn)
19 con3 = Mock(ProtocolToPartyConn)
20
21 conns1 = ProtocolToPartyConnections([con1, con2])
22 conns1a = ProtocolToPartyConnections([con1, con2])
23 conns2 = ProtocolToPartyConnections([con1, con3])
24 conns3 = ProtocolToPartyConnections([con2, con1])
25 conns4 = ProtocolToPartyConnections([con2, con1, con3])
26 conns5 = ProtocolToPartyConnections([con2, con1, con3, con1])
27
28 con1.__repr__=Mock(return_value="con1") #type:ignore
29 con2.__repr__=Mock(return_value="con2") #type:ignore
30 con3.__repr__=Mock(return_value="con3") #type:ignore
31
32 con1.getParty=Mock(return_value=party1)
33 con2.getParty=Mock(return_value=party2)
34 con3.getParty=Mock(return_value=party3)
35
36
37 def getGeneralTestData(self)->List[List[ProtocolToPartyConnections]] :
38 return [[self.conns1, self.conns1a],[self.conns2], [self.conns3],
39 [self.conns4]]
40
41 def getGeneralTestStrings(self) -> List[str] :
42 return ["ConnectionWithParties\\[con1, con2\\]",
43 "ConnectionWithParties\\[con1, con3\\]",
44 "ConnectionWithParties\\[con2, con1\\]",
45 "ConnectionWithParties\\[con2, con1, con3\\]"]
46
47 def testGet(self):
48 self.assertEqual(self.con1, self.conns1.getConn(0))
49 self.assertEqual(self.con3, self.conns4.getConn(2))
50
51 def testGetParty(self):
52 self.assertEquals(self.con1, self.conns1.get(self.party1))
53 self.assertEquals(self.con1, self.conns4.get(self.party1))
54 self.assertEquals(self.con2, self.conns1.get(self.party2))
55 self.assertEquals(self.con2, self.conns3.get(self.party2))
56 self.assertEquals(self.con2, self.conns4.get(self.party2))
57
58 def testGetUnknownParty(self) :
59 self.assertEqual(None, self.conns2.get(self.party2))
60
61 def testSize(self):
62 self.assertEqual(2, self.conns1.size())
63 self.assertEquals(2, self.conns2.size())
64 self.assertEquals(2, self.conns3.size())
65 self.assertEquals(3, self.conns4.size())
66
67 def testWithParty(self) :
68 conns = self.conns3.With(self.con3)
69 self.assertEqual(2, self.conns3.size())
70 self.assertEqual(3, conns.size())
71 self.assertEqual(self.conns4, conns)
72
73 def testWithExistingParty(self):
74 self.conns4.With(self.con1);
75 # no throw, default this is ok, it should be the protocol testing this.
76
77 def testAllUnique(self):
78 self.assertTrue(self.conns4.allunique());
79 self.assertFalse(self.conns5.allunique());
80
Note: See TracBrowser for help on using the repository browser.