source: geniuswebcore/test/geniusweb/inform/OptInTest.py@ 78

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

Fix for IssueValue hashcode.

File size: 2.4 KB
Line 
1from datetime import datetime
2import json
3import unittest
4
5from pyson.ObjectMapper import ObjectMapper
6from uri.uri import URI
7
8from geniusweb.actions.PartyId import PartyId
9from geniusweb.actions.Vote import Vote
10from geniusweb.actions.Votes import Votes
11from geniusweb.inform.Inform import Inform
12from geniusweb.inform.OptIn import OptIn
13from geniusweb.issuevalue.Bid import Bid
14from geniusweb.issuevalue.DiscreteValue import DiscreteValue
15from unitpy.GeneralTests import GeneralTests
16from typing import List
17
18
19class OptInTest(unittest.TestCase, GeneralTests[OptIn]):
20 maxDiff = None
21
22 bid1 = Bid({"iss": DiscreteValue("val1")})
23 bid2 = Bid({"iss": DiscreteValue("val2")})
24 partyA = PartyId("partyA")
25 partyB = PartyId("partyB")
26 voteA1 = Vote(partyA, bid1, 2, 9)
27 voteB1 = Vote(partyB, bid1, 2, 9)
28 voteB2 = Vote(partyB, bid2, 2, 9)
29
30 votesA = Votes(partyA, set([voteA1]))
31 votesB = Votes(partyB,set([voteB1, voteB2]))
32
33 optIn1 = OptIn([votesA, votesB])
34 optIn1a = OptIn([votesA, votesB])
35 optIn2 = OptIn([votesA])
36 jackson = ObjectMapper();
37
38 asJson="{\"OptIn\":{\"votes\":[{\"Votes\":{\"actor\":\"partyA\",\"votes\":[{\"Vote\":{\"actor\":\"partyA\",\"bid\":{\"issuevalues\":{\"iss\":\"val1\"}},\"minPower\":2,\"maxPower\":9}}]}},{\"Votes\":{\"actor\":\"partyB\",\"votes\":[{\"Vote\":{\"actor\":\"partyB\",\"bid\":{\"issuevalues\":{\"iss\":\"val2\"}},\"minPower\":2,\"maxPower\":9}},{\"Vote\":{\"actor\":\"partyB\",\"bid\":{\"issuevalues\":{\"iss\":\"val1\"}},\"minPower\":2,\"maxPower\":9}}]}}]}}"
39
40 def getGeneralTestData(self) -> List[List[OptIn]] :
41 return [[self.optIn1, self.optIn1a], [self.optIn2]]
42
43 def getGeneralTestStrings(self) -> List[str]:
44 return ["OptIn.*Votes.*Vote.*partyA.*iss.*val1.*2.*Votes.*Vote.*partyB.*iss.*val2.*.*2.*Vote.*partyB.*iss.*val1.*2.*",
45 "OptIn.*Votes.*Vote.*partyA.*iss.*val.*2.*"]
46
47 def testSerialize(self):
48 jsonstruct = self.jackson.toJson(self.optIn1)
49 print(jsonstruct)
50 # test does not work, python keeps changing the field order...
51# self.assertEqual(self.bla, jsonstruct)
52
53 def testDeserialize(self):
54 p = self.jackson.parse(json.loads(self.asJson), Inform)
55 print(p);
56 self.assertEqual(self.optIn1, p)
57
58 def testOneVotePerParty(self):
59 self.assertRaises(ValueError, lambda: OptIn([self.votesA, self.votesA]))
60
Note: See TracBrowser for help on using the repository browser.