import repository from arizona
[raven.git] / apps / gacks / testGacksReceipt.py
1 import unittest
2 import xmlrpclib
3 from gacksreceipt import *
4
5 class TestGacksReceipt(unittest.TestCase):
6    def setUp(self):
7        pass
8
9    def testCreate(self):
10        h = GacksHandle("cpu", 10, 15, 20, 25)
11        r = GacksReceipt(subject="foo1", handle = h, action="foo")
12        self.assertEqual(r.handle, h)
13        self.assertEqual(r.action, "foo")
14
15    def testSetHandle(self):
16        h = GacksHandle("cpu", 10, 15, 20, 25)
17        r = GacksReceipt(subject="foo1", handle = h)
18        self.assertEqual(r.handle, h)
19
20        h2 = GacksHandle("cpu", 10, 15, 20, 25)
21        r.SetHandle(h2);
22        self.assertEqual(r.handle, h2)
23
24    def testSetAction(self):
25        h = GacksHandle("cpu", 10, 15, 20, 25)
26        r = GacksReceipt(subject="foo1", handle = h, action="foo")
27        self.assertEqual(r.action, "foo")
28
29        r.SetAction("bar");
30        self.assertEqual(r.action, "bar")
31
32    def testEncodeDecode(self):
33        h = GacksHandle("cpu", 10, 15, 20, 25)
34        rec1 = GacksRecord("cpu", 10, 13, 20, 25, ["aaa","bbb"], "slice1")
35        rec2 = GacksRecord("cpu", 13, 15, 20, 25, ["aaa","bbb"], "slice1")
36        r = GacksReceipt(subject="foo1", handle = h, action="foo", reclist=[rec1,rec2])
37
38        r.encode()
39
40        str = r.save_to_string()
41
42        r2 = GacksReceipt(string = str)
43        #r2.decode()
44        #r2.dump()
45
46        h2 = r2.GetHandle()
47        self.assertEqual(h2.id, "cpu")
48        self.assertEqual(h2.unitStart, 10)
49        self.assertEqual(h2.unitStop, 15)
50        self.assertEqual(h2.timeStart, 20)
51        self.assertEqual(h2.timeStop, 25)
52
53        self.assertEqual(r2.GetAction(), "foo")
54
55        reclist = r2.GetRecords()
56        r1=reclist[0]
57        r2=reclist[1]
58        self.assertEqual(r1.id, "cpu")
59        self.assertEqual(r1.unitStart, 10)
60        self.assertEqual(r1.unitStop, 13)
61        self.assertEqual(r1.timeStart, 20)
62        self.assertEqual(r1.timeStop, 25)
63        self.assertEqual(r2.id, "cpu")
64        self.assertEqual(r2.unitStart, 13)
65        self.assertEqual(r2.unitStop, 15)
66        self.assertEqual(r2.timeStart, 20)
67        self.assertEqual(r2.timeStop, 25)
68
69 if __name__ == "__main__":
70     unittest.main()