1 | from geniusweb.events.TournamentStarted import TournamentStarted
|
---|
2 | import unittest
|
---|
3 | from unitpy.GeneralTests import GeneralTests
|
---|
4 | from pyson.ObjectMapper import ObjectMapper
|
---|
5 | from typing import List
|
---|
6 | from geniusweb.events.NegotiationEvent import NegotiationEvent
|
---|
7 | import json
|
---|
8 |
|
---|
9 | class TournamentStartedTest(unittest.TestCase, GeneralTests[TournamentStarted]):
|
---|
10 | pyson = ObjectMapper()
|
---|
11 |
|
---|
12 | SESSIONNR = 1
|
---|
13 | NOW = 101
|
---|
14 | NOW1 = NOW + 1
|
---|
15 | NSESSIONS = 5
|
---|
16 |
|
---|
17 | tournamentStarted = TournamentStarted(NSESSIONS, NOW)
|
---|
18 | tournamentStarteda = TournamentStarted(NSESSIONS, NOW)
|
---|
19 | otherTournamentStarted = TournamentStarted(NSESSIONS + 1, NOW)
|
---|
20 | tournamentStartedLater = TournamentStarted(NSESSIONS, NOW1)
|
---|
21 |
|
---|
22 | tournamentstartedstring = '{"TournamentStarted":{"time":101,"numberOfSessions":5}}'
|
---|
23 |
|
---|
24 | def getGeneralTestData(self) -> List[List[TournamentStarted]]:
|
---|
25 | mylist = []
|
---|
26 | mylist.append([self.tournamentStarted, self.tournamentStarteda])
|
---|
27 | mylist.append([self.otherTournamentStarted])
|
---|
28 | mylist.append([self.tournamentStartedLater])
|
---|
29 | return mylist
|
---|
30 |
|
---|
31 | def getGeneralTestStrings(self) -> List[str]:
|
---|
32 | return ["TournamentStarted\\[.*" + str(self.NOW) + ".*" + str(self.NSESSIONS) + ".*\\]",\
|
---|
33 | "TournamentStarted\\[.*" + str(self.NOW) + ".*" + str(self.NSESSIONS + 1) + ".*\\]",\
|
---|
34 | "TournamentStarted\\[.*" + str(self.NOW1) + ".*" + str(self.NSESSIONS) + ".*\\]"]
|
---|
35 |
|
---|
36 | def testserializeTournamentStarted(self):
|
---|
37 | print(self.tournamentstartedstring)
|
---|
38 | self.assertEqual(json.loads(self.tournamentstartedstring), self.pyson.toJson(self.tournamentStarted))
|
---|
39 |
|
---|
40 | def testdeserializeTournamentStarted(self):
|
---|
41 | evt = self.pyson.parse(json.loads(self.tournamentstartedstring), NegotiationEvent)
|
---|
42 | self.assertEqual(TournamentStarted, type(evt))
|
---|
43 | event = evt
|
---|
44 | # compare fields, as sessionended is a derived/new inner class
|
---|
45 | self.assertEqual(self.NSESSIONS, event.getNumberOfSessions())
|
---|
46 | self.assertEqual(self.NOW, event.getTime())
|
---|
47 |
|
---|
48 | def testNullTime(self):
|
---|
49 | TournamentStarted(self.NSESSIONS, 0)
|
---|
50 |
|
---|
51 | def testNegativeTime(self):
|
---|
52 | self.assertRaises(ValueError, lambda: TournamentStarted(self.NSESSIONS, -1)) |
---|