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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# -*- encoding: utf-8 -*-
try:
import unittest2 as unittest
except ImportError:
import unittest
from isso import utils
from isso.utils import parse
class TestUtils(unittest.TestCase):
def test_anonymize(self):
examples = [
(u'12.34.56.78', u'12.34.56.0'),
(u'1234:5678:90ab:cdef:fedc:ba09:8765:4321', u'1234:5678:90ab:0000:0000:0000:0000:0000'),
(u'::ffff:127.0.0.1', u'127.0.0.0')]
for (addr, anonymized) in examples:
self.assertEqual(utils.anonymize(addr), anonymized)
class TestParse(unittest.TestCase):
def test_thread(self):
self.assertEqual(parse.thread("asdf"), (None, 'Untitled.'))
self.assertEqual(parse.thread("""
<html>
<head>
<title>Foo!</title>
</head>
<body>
<header>
<h1>generic website title.</h1>
<h2>subtile title.</h2>
</header>
<article>
<header>
<h1>Can you find me?</h1>
</header>
<section id="isso-thread">
</section>
</article>
</body>
</html>"""), (None, 'Can you find me?'))
self.assertEqual(parse.thread("""
<html>
<body>
<h1>I'm the real title!1
<section data-title="No way%21" id="isso-thread">
"""), (None, 'No way!'))
self.assertEqual(parse.thread("""
<section id="isso-thread" data-title="Test" data-isso-id="test">
"""), ('test', 'Test'))
self.assertEqual(parse.thread('<section id="isso-thread" data-isso-id="Fuu.">'),
('Fuu.', 'Untitled.'))
|