[Flatpak SDK] local build is broken
[WebKit-https.git] / tests / test_sub.py
1 #!/usr/bin/env python
2 import os, glob, unittest
3 from ConfigParser import ConfigParser
4 from StringIO import StringIO
5 import planet
6
7 class SubTest(unittest.TestCase):
8     
9     def setUp(self):
10         planet.logging.basicConfig()
11         self.config = ConfigParser()
12         self.config.add_section('Planet')
13         self.config.set('Planet', 'cache_directory', 'planet/tests/data/cache')
14         self.my_planet = planet.Planet(self.config)
15
16     def tearDown(self):
17         for file in glob.glob('planet/tests/data/cache/*'):
18             os.unlink(file)
19         os.removedirs('planet/tests/data/cache')
20
21     def test_fetch(self):
22         self.config.readfp(StringIO("""[planet/tests/data/before.atom]
23 name = Test Feed
24 """))
25         self.my_planet.run("test", "http://example.com", [], 0)
26         channels, channels_list = self.my_planet.gather_channel_info()
27         self.assertEqual(len(channels_list), 1)
28         self.assertEqual(channels_list[0]['configured_url'],
29             'planet/tests/data/before.atom')
30
31         items_list = self.my_planet.gather_items_info(channels)
32         self.assertEqual(len(items_list), 1)
33         self.assertEqual(items_list[0]['summary'],'Some text.')
34         self.assertEqual(items_list[0]['date_iso'],'2003-12-13T18:30:02+00:00')
35
36     # this test is actually per the Atom spec definition of 'updated'
37     def test_update_with_new_date(self):
38         self.config.readfp(StringIO("""[planet/tests/data/before.atom]
39 name = Test Feed
40 """))
41         self.my_planet.run("test", "http://example.com", [], 0)
42         channels, channels_list = self.my_planet.gather_channel_info()
43
44         channel = channels.keys()[0]
45         channel.url = 'planet/tests/data/after.atom'
46         os.link('planet/tests/data/cache/planet,tests,data,before.atom',
47                 'planet/tests/data/cache/planet,tests,data,after.atom')
48         channel.update()
49
50         items_list = self.my_planet.gather_items_info(channels)
51         self.assertEqual(len(items_list), 1)
52         self.assertEqual(items_list[0]['summary'],'Updated text.')
53         self.assertEqual(items_list[0]['date_iso'],'2006-05-21T18:54:02+00:00')
54
55     def test_update_with_no_date(self):
56         self.config.readfp(StringIO("""[planet/tests/data/before.rss]
57 name = Test Feed
58 """))
59         self.my_planet.run("test", "http://example.com", [], 0)
60
61         channels, channels_list = self.my_planet.gather_channel_info()
62         channel = channels.keys()[0]
63         item=channel._items.values()[0]
64         item.set_as_date('date',(2003, 12, 13, 18, 30, 2, 5, 347, 0))
65
66         channel.url = 'planet/tests/data/after.rss'
67         os.link('planet/tests/data/cache/planet,tests,data,before.rss',
68                 'planet/tests/data/cache/planet,tests,data,after.rss')
69         items_list = self.my_planet.gather_items_info(channels)
70         self.assertEqual(items_list[0]['date_iso'],'2003-12-13T18:30:02+00:00')
71         channel.update()
72
73         items_list = self.my_planet.gather_items_info(channels)
74         self.assertEqual(len(items_list), 1)
75         self.assertEqual(items_list[0]['summary'],'Updated text.')
76         self.assertEqual(items_list[0]['date_iso'],'2003-12-13T18:30:02+00:00')
77
78 if __name__ == '__main__':
79     unittest.main()