[88] | 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.protocol.session.TeamInfo import TeamInfo
|
---|
| 10 | from geniusweb.references.Parameters import Parameters
|
---|
| 11 | from geniusweb.references.PartyRef import PartyRef
|
---|
| 12 | from geniusweb.references.PartyWithParameters import PartyWithParameters
|
---|
| 13 | from geniusweb.references.PartyWithProfile import PartyWithProfile
|
---|
| 14 | from geniusweb.references.ProfileRef import ProfileRef
|
---|
| 15 |
|
---|
| 16 |
|
---|
| 17 | class TeamInfoTest (unittest.TestCase, GeneralTests[TeamInfo]):
|
---|
| 18 |
|
---|
| 19 | team1 = TeamInfo([])
|
---|
| 20 | team1a = TeamInfo([])
|
---|
| 21 | parameters = Parameters()
|
---|
| 22 | asString1 = "{\"TeamInfo\":{\"parties\":[{\"party\":{\"partyref\":\"party1\",\"parameters\":{}},\"profile\":\"profile1\"}]}}";
|
---|
| 23 |
|
---|
| 24 | partyref = PartyRef(URI("party1"))
|
---|
| 25 | profileref = ProfileRef(URI("profile1"))
|
---|
| 26 | team2 = TeamInfo( [PartyWithProfile(PartyWithParameters(partyref, parameters),profileref)])
|
---|
| 27 | team2a = TeamInfo( [ PartyWithProfile(PartyWithParameters(partyref, parameters),
|
---|
| 28 | profileref)]);
|
---|
| 29 |
|
---|
| 30 | def getGeneralTestData(self)->List[List[TeamInfo]] :
|
---|
| 31 | return [[self.team1, self.team1a], [self.team2, self.team2a]]
|
---|
| 32 |
|
---|
| 33 | def getGeneralTestStrings(self) -> List[str]:
|
---|
| 34 | return ["TeamInfo.\\[\\].",
|
---|
| 35 | "TeamInfo.\\[PartyWithProfile.*party1.*profile1.*\\].*"]
|
---|
| 36 |
|
---|
| 37 | def testSerialize(self) :
|
---|
| 38 |
|
---|
| 39 | jackson = ObjectMapper()
|
---|
| 40 | print(jackson.toJson(self.team2))
|
---|
| 41 | self.assertEqual(json.loads(self.asString1), jackson.toJson(self.team2))
|
---|
| 42 |
|
---|
| 43 | def testDeserialize(self) :
|
---|
| 44 | jackson = ObjectMapper()
|
---|
| 45 | read = jackson.parse(json.loads(self.asString1), TeamInfo)
|
---|
| 46 | self.assertEqual(self.team2, read)
|
---|