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