source: geniuswebcore/test/geniusweb/issuevalue/BidTest.py@ 59

Last change on this file since 59 was 59, checked in by Wouter Pasman, 3 years ago

#44 manual commit of first public release, because this will cause the dist directory to move

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