source: geniuswebcore/test/geniusweb/events/ActionEventTest.py@ 75

Last change on this file since 75 was 73, checked in by Bart Vastenhouw, 3 years ago

Fix for IssueValue hashcode.

File size: 2.0 KB
Line 
1import unittest
2
3from pyson.ObjectMapper import ObjectMapper
4from geniusweb.events.ActionEvent import ActionEvent
5from unitpy.GeneralTests import GeneralTests
6from geniusweb.actions.PartyId import PartyId
7from geniusweb.actions.EndNegotiation import EndNegotiation
8from typing import List
9import json
10from geniusweb.events.NegotiationEvent import NegotiationEvent
11from unittest.mock import Mock
12
13class ActionEventTest(unittest.TestCase, GeneralTests[ActionEvent]):
14 NOW = 101
15 pyson = ObjectMapper()
16 string = "{\"ActionEvent\":{\"action\":{\"EndNegotiation\":{\"actor\":\"party1\"}},\"time\":101}}"
17 pid = PartyId("party1");
18 action = EndNegotiation(pid);
19 evt = ActionEvent(action, NOW);
20 evt1 = ActionEvent(action, NOW);
21 evtb = ActionEvent(action, NOW + 1);
22
23 def getGeneralTestData(self) -> List[List[ActionEvent]]:
24 return [[self.evt, self.evt1], [self.evtb]]
25
26 def getGeneralTestStrings(self):
27 return "ActionEvent\\[.*" + str(self.NOW) + ".*EndNegotiation.*\\]",\
28 "ActionEvent\\[.*" + str(self.NOW + 1) + ".*EndNegotiation.*\\]"
29
30 def testSmoke(self):
31 action1 = Mock(EndNegotiation)
32 evt = ActionEvent(action1, 0)
33
34 def testserialize(self):
35 json1 = self.pyson.toJson(self.evt)
36 print(json1)
37 self.assertEqual(json.loads(self.string), json1)
38
39 def testdeserializeTestReadActionEvent(self):
40 evt1 = self.pyson.parse(json.loads(self.string), ActionEvent)
41 print(evt1)
42 # compare fields, as evt is a derived/new inner class
43 self.assertEqual(EndNegotiation, type(evt1.getAction()))
44 self.assertEqual(101, evt1.getTime())
45
46 def testdeserializeTestReadEvent(self):
47 self.assertEqual(self.evt1, self.pyson.parse(json.loads(self.string), ActionEvent))
48 evt1 = self.pyson.parse(json.loads(self.string), NegotiationEvent)
49 self.assertEqual(ActionEvent, type(evt1))
50 ev1 = evt1
51 self.assertEqual(EndNegotiation, type(ev1.getAction()))
52 self.assertEqual(101, ev1.getTime())
Note: See TracBrowser for help on using the repository browser.