1 | import unittest
|
---|
2 |
|
---|
3 | from pyson.ObjectMapper import ObjectMapper
|
---|
4 |
|
---|
5 | from geniusweb.actions.PartyId import PartyId
|
---|
6 |
|
---|
7 |
|
---|
8 | #FIXME support and test serialization
|
---|
9 | class PartyIdTest (unittest.TestCase) :
|
---|
10 |
|
---|
11 | pyson=ObjectMapper()
|
---|
12 | party=PartyId("a")
|
---|
13 | party1=PartyId("a")
|
---|
14 | party2=PartyId("b")
|
---|
15 |
|
---|
16 |
|
---|
17 | def testRestrictions(self):
|
---|
18 | self.assertRaises(ValueError, lambda : PartyId(""))
|
---|
19 |
|
---|
20 | def testRestrictions2(self):
|
---|
21 | self.assertRaises(ValueError, lambda:PartyId("@2"))
|
---|
22 |
|
---|
23 | def testRestrictions3(self) :
|
---|
24 | self.assertRaises(ValueError, lambda:PartyId("_12"))
|
---|
25 |
|
---|
26 |
|
---|
27 | def testRestrictions4(self):
|
---|
28 | self.assertRaises(ValueError, lambda :PartyId("12A"))
|
---|
29 |
|
---|
30 | def testRestrictions5(self):
|
---|
31 | self.assertRaises(ValueError,lambda :PartyId(" fds "))
|
---|
32 |
|
---|
33 | def testRestrictions6(self):
|
---|
34 | PartyId("A_1_23_ok")
|
---|
35 |
|
---|
36 | def testRestrictions7(self):
|
---|
37 | PartyId("a_1_23_ok")
|
---|
38 |
|
---|
39 | def testGetName(self):
|
---|
40 | self.assertEqual("a", self.party1.getName());
|
---|
41 |
|
---|
42 |
|
---|
43 | def testSerialize(self):
|
---|
44 | print(str(self.pyson.toJson(self.party1)))
|
---|
45 | self.assertEqual("a",self.pyson.toJson(self.party))
|
---|
46 |
|
---|
47 | def testDeserialize(self):
|
---|
48 | self.assertEqual(self.party, self.pyson.parse("a", PartyId))
|
---|
49 |
|
---|
50 |
|
---|
51 | def testRepr(self):
|
---|
52 | self.assertEqual("a", repr(self.party))
|
---|
53 |
|
---|
54 | def testEqual(self):
|
---|
55 | self.assertEqual(self.party, self.party1)
|
---|
56 | self.assertNotEqual(self.party1, self.party2)
|
---|
57 | self.assertEqual(hash(self.party), hash(self.party1))
|
---|
58 | self.assertNotEqual(hash(self.party), hash(self.party2))
|
---|
59 | |
---|