1 | from datetime import datetime
|
---|
2 | import unittest
|
---|
3 |
|
---|
4 | from pyson.ObjectMapper import ObjectMapper
|
---|
5 | from uri import URI #type:ignore
|
---|
6 |
|
---|
7 | from geniusweb.actions.PartyId import PartyId
|
---|
8 | from geniusweb.inform.Inform import Inform
|
---|
9 | from geniusweb.inform.Settings import Settings
|
---|
10 | from geniusweb.progress.ProgressTime import ProgressTime
|
---|
11 | from geniusweb.references.Parameters import Parameters
|
---|
12 | from geniusweb.references.ProfileRef import ProfileRef
|
---|
13 | from geniusweb.references.ProtocolRef import ProtocolRef
|
---|
14 |
|
---|
15 |
|
---|
16 | class SettingsTest(unittest.TestCase):
|
---|
17 | id1 = PartyId("party1")
|
---|
18 | id2 = PartyId("party2")
|
---|
19 | profileref1 = ProfileRef(URI("profile:1"))
|
---|
20 | profileref2 = ProfileRef(URI("profile:2"))
|
---|
21 | protocolref1 = ProtocolRef(URI("protocol:1"))
|
---|
22 | protocolref2 = ProtocolRef(URI("protocol:2"))
|
---|
23 | progress1=ProgressTime(1000, datetime.fromtimestamp(12345678))
|
---|
24 | progress2=ProgressTime(2000, datetime.fromtimestamp(12345678))
|
---|
25 | parameters1=Parameters()
|
---|
26 | parameters2=Parameters({'a':1})
|
---|
27 |
|
---|
28 | settings = Settings(id1, profileref1, protocolref1, progress1, parameters1 )
|
---|
29 | settings1 = Settings(id1, profileref1, protocolref1, progress1, parameters1 )
|
---|
30 | settings2 = Settings(id2, profileref1, protocolref1, progress1, parameters1 )
|
---|
31 | settings3 = Settings(id1, profileref2, protocolref1, progress1, parameters1 )
|
---|
32 | settings4 = Settings(id1, profileref1, protocolref2, progress1, parameters1 )
|
---|
33 | settings5 = Settings(id1, profileref1, protocolref1, progress2, parameters1 )
|
---|
34 |
|
---|
35 | settings1json={'Settings': {'id': 'party1', 'profile': 'profile:1', 'protocol': 'protocol:1', 'progress': {'ProgressTime': {'duration': 1000, 'start': 12345678000}}, 'parameters': {}}}
|
---|
36 |
|
---|
37 |
|
---|
38 | def testSerialize(self):
|
---|
39 | pyson=ObjectMapper()
|
---|
40 | print(str(pyson.toJson(self.settings1)))
|
---|
41 | self.assertEqual(self.settings1json, pyson.toJson(self.settings1))
|
---|
42 |
|
---|
43 | def testDeserialize(self):
|
---|
44 | pyson=ObjectMapper()
|
---|
45 | self.assertEqual(self.settings1, pyson.parse(self.settings1json, Inform))
|
---|
46 |
|
---|
47 | def testRepr(self):
|
---|
48 | self.assertEqual("Settings[party1,ProfileRef[profile:1],ProtocolRef[protocol:1],ProgressTime[12345678.0 , 1000ms],{}]", repr(self.settings))
|
---|
49 |
|
---|
50 | def testEqual(self):
|
---|
51 | self.assertEqual(self.settings, self.settings1)
|
---|
52 | self.assertNotEqual(self.settings, self.settings2)
|
---|
53 | self.assertNotEqual(self.settings, self.settings3)
|
---|
54 | self.assertNotEqual(self.settings, self.settings4)
|
---|
55 | self.assertNotEqual(self.settings, self.settings5)
|
---|
56 | self.assertEqual(hash(self.settings), hash(self.settings1))
|
---|
57 | self.assertNotEqual(hash(self.settings), hash(self.settings2))
|
---|
58 | self.assertNotEqual(hash(self.settings), hash(self.settings3))
|
---|
59 | self.assertNotEqual(hash(self.settings), hash(self.settings4))
|
---|
60 | self.assertNotEqual(hash(self.settings), hash(self.settings5))
|
---|
61 |
|
---|
62 | |
---|