source: geniuswebcore/test/geniusweb/actions/OfferTest.py@ 73

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

Fix for IssueValue hashcode.

File size: 1.4 KB
Line 
1from decimal import Decimal
2import unittest
3
4from pyson.ObjectMapper import ObjectMapper
5
6from geniusweb.actions.Action import Action
7from geniusweb.actions.Offer import Offer
8from geniusweb.actions.PartyId import PartyId
9from geniusweb.issuevalue.Bid import Bid
10from geniusweb.issuevalue.DiscreteValue import DiscreteValue
11from geniusweb.issuevalue.NumberValue import NumberValue
12
13
14class 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
Note: See TracBrowser for help on using the repository browser.