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