| changeset 12 | c57439b500cb |
| parent 0 | ea0e45971cea |
| child 70 | 1fe2c20adeba |
| 11:5083c26d8f93 | 12:c57439b500cb |
|---|---|
2 |
2 |
3 import os |
3 import os |
4 import sys |
4 import sys |
5 sys.path.append('../') |
5 sys.path.append('../') |
6 |
6 |
7 import time |
7 import datetime |
8 |
8 |
9 import simplejson |
9 import simplejson |
10 from glob import glob |
10 from glob import glob |
11 |
11 |
12 from pywhois.parser import WhoisEntry, cast_date |
12 from whois.parser import WhoisEntry, cast_date |
13 |
13 |
14 class TestParser(unittest.TestCase): |
14 class TestParser(unittest.TestCase): |
15 def test_com_expiration(self): |
15 def test_com_expiration(self): |
16 data = """ |
16 data = """ |
17 Status: ok |
17 Status: ok |
20 Expiration Date: 14-apr-2009 |
20 Expiration Date: 14-apr-2009 |
21 |
21 |
22 >>> Last update of whois database: Sun, 31 Aug 2008 00:18:23 UTC <<< |
22 >>> Last update of whois database: Sun, 31 Aug 2008 00:18:23 UTC <<< |
23 """ |
23 """ |
24 w = WhoisEntry.load('urlowl.com', data) |
24 w = WhoisEntry.load('urlowl.com', data) |
25 expires = w.get('expiration_date') |
25 expires = w.expiration_date.strftime('%Y-%m-%d') |
26 self.assertEquals(expires, ['14-apr-2009']) |
26 self.assertEquals(expires, '2009-04-14') |
27 |
27 |
28 def test_cast_date(self): |
28 def test_cast_date(self): |
29 dates = ['14-apr-2008', '2008-04-14'] |
29 dates = ['14-apr-2008', '2008-04-14'] |
30 for d in dates: |
30 for d in dates: |
31 r = time.strftime('%Y-%m-%d', cast_date(d)) |
31 r = cast_date(d).strftime('%Y-%m-%d') |
32 self.assertEquals(r, '2008-04-14') |
32 self.assertEquals(r, '2008-04-14') |
33 |
33 |
34 def test_com_allsamples(self): |
34 def test_com_allsamples(self): |
35 """ |
35 """ |
36 Iterate over all of the sample/whois/*.com files, read the data, |
36 Iterate over all of the sample/whois/*.com files, read the data, |
72 print "%s \t(%s):\t %s != %s" % (domain, key, result, expected) |
72 print "%s \t(%s):\t %s != %s" % (domain, key, result, expected) |
73 fail += 1 |
73 fail += 1 |
74 |
74 |
75 if fail: |
75 if fail: |
76 self.fail("%d sample whois attributes were not parsed properly!" % fail) |
76 self.fail("%d sample whois attributes were not parsed properly!" % fail) |
77 |
|
78 |
|
79 if __name__ == '__main__': |
|
80 unittest.main() |