1 | from decimal import Decimal
|
---|
2 | import unittest
|
---|
3 |
|
---|
4 | from pyson.ObjectMapper import ObjectMapper
|
---|
5 |
|
---|
6 | from geniusweb.actions.Accept import Accept
|
---|
7 | from geniusweb.actions.Action import Action
|
---|
8 | from geniusweb.actions.Offer import Offer
|
---|
9 | from geniusweb.actions.PartyId import PartyId
|
---|
10 | from geniusweb.issuevalue.Bid import Bid
|
---|
11 | from geniusweb.issuevalue.DiscreteValue import DiscreteValue
|
---|
12 | from geniusweb.issuevalue.NumberValue import NumberValue
|
---|
13 |
|
---|
14 |
|
---|
15 | class OfferTest (unittest.TestCase) :
|
---|
16 | pyson=ObjectMapper()
|
---|
17 | actor=PartyId("myid")
|
---|
18 | bid=Bid({'fte':NumberValue(Decimal(3)), 'leasecar':DiscreteValue('yes')})
|
---|
19 | bid2=Bid({'fte':NumberValue(Decimal(3)), 'leasecar':DiscreteValue('no')})
|
---|
20 | accept=Accept(actor, bid)
|
---|
21 | accept2=Accept(actor, bid2)
|
---|
22 |
|
---|
23 | def testSerialize(self):
|
---|
24 | print(str(self.pyson.toJson(self.accept)))
|
---|
25 | self.assertEqual({'Accept': {'actor': 'myid', 'bid': {'issuevalues':{'fte': 3, 'leasecar': 'yes'}}}},\
|
---|
26 | self.pyson.toJson(self.accept))
|
---|
27 |
|
---|
28 | def testDeserialize(self):
|
---|
29 | jsonoffer= self.pyson.toJson(self.accept)
|
---|
30 | self.assertEqual(self.accept, self.pyson.parse(jsonoffer, Action))
|
---|
31 |
|
---|
32 | def testRepr(self):
|
---|
33 | self.assertEqual("Accept[myid,Bid{'fte': 3, 'leasecar': yes}]", repr(self.accept))
|
---|
34 |
|
---|
35 | def testEqual(self):
|
---|
36 | self.assertEqual(self.accept, self.accept)
|
---|
37 | self.assertNotEqual(self.accept, self.accept2)
|
---|
38 | self.assertEqual(hash(self.accept), hash(self.accept))
|
---|
39 | self.assertNotEqual(hash(self.accept), hash(self.accept2))
|
---|
40 | |
---|