fix loading records from a dictionary when pointer is not defined
[sfa.git] / tests / testGacksCalendar.py
1 import unittest
2 import xmlrpclib
3 from gackscalendar import *
4
5 class TestGacksCalendar():
6     def setUp(self):
7         self.r1 = GacksRecord("cpu", 0, 10, 100, 200, ["foo", "bar"], "slice1")
8         self.r2 = GacksRecord("cpu", 0, 10, 200, 300, ["foo", "bar"], "slice2")
9         self.r3 = GacksRecord("cpu", 10, 60, 150, 250, ["foo", "bar"], "slice3")
10         self.r4 = GacksRecord("disk", 0, 50, 100, INFINITY, ["foo", "bar"], "slice4")
11
12     def testCreate(self):
13         c = self.CalClass()
14
15     def testInsert(self):
16         c = self.CalClass()
17         c.insert_record(self.r1)
18         c.insert_record(self.r2)
19         c.insert_record(self.r3)
20         c.insert_record(self.r4)
21
22     def testQuery(self):
23         c = self.CalClass()
24         c.insert_record(self.r1)
25         c.insert_record(self.r2)
26         c.insert_record(self.r3)
27         c.insert_record(self.r4)
28
29         records = c.query()
30
31         self.assertEqual(len(records), 4)
32
33     def testRemove(self):
34         c = self.CalClass()
35         c.insert_record(self.r1)
36         c.insert_record(self.r2)
37         c.insert_record(self.r3)
38         c.insert_record(self.r4)
39
40         c.remove_record(self.r2)
41         c.remove_record(self.r4)
42
43         records = c.query()
44         self.assertEqual(len(records), 2)
45
46         self.assert_(c.find_record(self.r1))
47         self.assertEqual(c.find_record(self.r2), None)
48         self.assert_(c.find_record(self.r3))
49         self.assertEqual(c.find_record(self.r4), None)
50
51
52 class TestGacksListCalendar(unittest.TestCase, TestGacksCalendar):
53     def setUp(self):
54         self.CalClass = GacksListCalendar
55         TestGacksCalendar.setUp(self)
56
57 if __name__ == "__main__":
58     unittest.main()