1 | import json
|
---|
2 | from typing import List
|
---|
3 | import unittest
|
---|
4 |
|
---|
5 | from pyson.ObjectMapper import ObjectMapper
|
---|
6 | from unitpy.GeneralTests import GeneralTests
|
---|
7 | from uri.uri import URI
|
---|
8 |
|
---|
9 | from geniusweb.references.Parameters import Parameters
|
---|
10 | from geniusweb.references.PartyRef import PartyRef
|
---|
11 | from geniusweb.references.PartyWithParameters import PartyWithParameters
|
---|
12 |
|
---|
13 |
|
---|
14 | class PartiWithParamsTest (unittest.TestCase, GeneralTests[PartyWithParameters]):
|
---|
15 | serialized = "{\"partyref\":\"ws:party1\",\"parameters\":{\"a\":1}}";
|
---|
16 |
|
---|
17 | party1 = PartyRef( URI("ws:party1"))
|
---|
18 | party2 = PartyRef( URI("ws:party2"))
|
---|
19 | param1 = Parameters()
|
---|
20 | param2 = Parameters().With("a", 1)
|
---|
21 | party1param1 = PartyWithParameters(party1, param1)
|
---|
22 | party1param1a = PartyWithParameters(party1, param1)
|
---|
23 | party1param2 = PartyWithParameters(party1, param2)
|
---|
24 |
|
---|
25 | def getGeneralTestData(self)->List[List[PartyWithParameters]]:
|
---|
26 | return [[ self.party1param1, self.party1param1a, self.party1param1a],
|
---|
27 | [self.party1param2]]
|
---|
28 |
|
---|
29 | def getGeneralTestStrings(self) ->List[str] :
|
---|
30 | return ["PartyRef.ws:party1.","PartyRef.ws:party1.\\{a=1\\}"]
|
---|
31 |
|
---|
32 | def testSerialize(self) :
|
---|
33 | jackson = ObjectMapper()
|
---|
34 |
|
---|
35 | jsonobj = jackson.toJson(self.party1param2)
|
---|
36 | print(jsonobj)
|
---|
37 | self.assertEqual(json.loads(self.serialized), jsonobj)
|
---|
38 |
|
---|
39 | def testDeserialize(self):
|
---|
40 | jackson = ObjectMapper()
|
---|
41 | p = jackson.parse(json.loads(self.serialized), PartyWithParameters)
|
---|
42 | print(p)
|
---|
43 | self.assertEqual(self.party1param2, p)
|
---|