blob: 56ec08f6740de84c6599380226c53688ea1f8232 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
import os
import tempfile
import yaml
import unittest
import gg_scrapper
from gg_scrapper import Group, Topic, Article # noqa
IN_URL = 'https://groups.google.com/forum/#!forum/jbrout'
ORIG_URL = 'http://groups.google.com/d/forum/jbrout'
EXP_URL = 'https://groups.google.com/forum/' + \
'?_escaped_fragment_=forum/jbrout'
class TestGGScrapper(unittest.TestCase):
def test_URL_conversion(self):
obs_URL = gg_scrapper.Group.unenscape_Google_bang_URL(IN_URL)
self.assertEqual(obs_URL, EXP_URL)
def test_do_redirect(self):
obs_URL = gg_scrapper.Group.do_redirect(ORIG_URL)
self.assertEqual(obs_URL, EXP_URL)
class TestMBOX(unittest.TestCase):
def test_create_mbox(self):
'''Create a mbox file from (pickled) Group
'''
group_file_name = 'test/group.yaml'
with open(group_file_name, 'r') as group_f:
group = yaml.load(group_f)
mbx_file = tempfile.NamedTemporaryFile('w', delete=False)
mbx = gg_scrapper.MBOX(mbx_file.name)
mbx.write_group(group)
with open('test/mbox.mbx') as exp_f:
with open(mbx_file.name) as mbx_f:
self.assertEqual(exp_f.read(), mbx_f.read())
os.unlink(mbx_file.name)
if __name__ == '__main__':
unittest.main()
|