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

Last change on this file since 100 was 100, checked in by ruud, 19 months ago

python installs also wheel to avoid error messages

File size: 2.4 KB
Line 
1from datetime import datetime
2import json
3from typing import List
4import unittest
5
6from pyson.ObjectMapper import ObjectMapper
7from unitpy.GeneralTests import GeneralTests
8from uri.uri import URI
9
10from geniusweb.actions.PartyId import PartyId
11from geniusweb.actions.Vote import Vote
12from geniusweb.actions.Votes import Votes
13from geniusweb.inform.Inform import Inform
14from geniusweb.inform.OptIn import OptIn
15from geniusweb.issuevalue.Bid import Bid
16from geniusweb.issuevalue.DiscreteValue import DiscreteValue
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.*val.*.*2.*Vote.*partyB.*iss.*val.*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.