| author | Brian Murphy <brian.p.murphy@gmail.com> |
| Mon, 27 Jun 2016 17:00:26 +0000 | |
| changeset 102 | e8cb8d1367c0 |
| parent 97 | 44522cd37b07 |
| child 135 | 808c8bc803f5 |
| permissions | -rw-r--r-- |
| 70 | 1 |
from __future__ import print_function |
2 |
from __future__ import unicode_literals |
|
3 |
from __future__ import division |
|
4 |
from __future__ import absolute_import |
|
5 |
from future import standard_library |
|
6 |
standard_library.install_aliases() |
|
7 |
from builtins import * |
|
| 0 | 8 |
import unittest |
9 |
||
10 |
import os |
|
11 |
import sys |
|
12 |
sys.path.append('../')
|
|
13 |
||
| 12 | 14 |
import datetime |
| 0 | 15 |
|
16 |
import simplejson |
|
17 |
from glob import glob |
|
18 |
||
| 12 | 19 |
from whois.parser import WhoisEntry, cast_date |
| 0 | 20 |
|
21 |
class TestParser(unittest.TestCase): |
|
22 |
def test_com_expiration(self): |
|
23 |
data = """ |
|
|
97
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
24 |
Status: ok |
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
25 |
Updated Date: 14-apr-2008 |
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
26 |
Creation Date: 14-apr-2008 |
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
27 |
Expiration Date: 14-apr-2009 |
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
28 |
|
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
29 |
>>> Last update of whois database: Sun, 31 Aug 2008 00:18:23 UTC <<< |
| 0 | 30 |
""" |
31 |
w = WhoisEntry.load('urlowl.com', data)
|
|
| 12 | 32 |
expires = w.expiration_date.strftime('%Y-%m-%d')
|
|
97
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
33 |
self.assertEqual(expires, '2009-04-14') |
| 0 | 34 |
|
35 |
def test_cast_date(self): |
|
36 |
dates = ['14-apr-2008', '2008-04-14'] |
|
37 |
for d in dates: |
|
| 12 | 38 |
r = cast_date(d).strftime('%Y-%m-%d')
|
|
97
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
39 |
self.assertEqual(r, '2008-04-14') |
| 0 | 40 |
|
41 |
def test_com_allsamples(self): |
|
42 |
""" |
|
43 |
Iterate over all of the sample/whois/*.com files, read the data, |
|
44 |
parse it, and compare to the expected values in sample/expected/. |
|
45 |
Only keys defined in keys_to_test will be tested. |
|
46 |
||
47 |
To generate fresh expected value dumps, see NOTE below. |
|
48 |
""" |
|
|
97
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
49 |
keys_to_test = ['domain_name', 'expiration_date', 'updated_date', |
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
50 |
'creation_date', 'status'] |
| 0 | 51 |
fail = 0 |
|
97
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
52 |
total = 0 |
| 0 | 53 |
for path in glob('test/samples/whois/*.com'):
|
54 |
# Parse whois data |
|
55 |
domain = os.path.basename(path) |
|
|
97
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
56 |
with open(path) as whois_fp: |
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
57 |
data = whois_fp.read() |
| 0 | 58 |
|
59 |
w = WhoisEntry.load(domain, data) |
|
|
97
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
60 |
results = {key: w.get(key) for key in keys_to_test}
|
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
61 |
|
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
62 |
# NOTE: Toggle condition below to write expected results from the |
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
63 |
# parse results This will overwrite the existing expected results. |
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
64 |
# Only do this if you've manually confirmed that the parser is |
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
65 |
# generating correct values at its current state. |
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
66 |
if False: |
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
67 |
def date2str4json(obj): |
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
68 |
if isinstance(obj, datetime.datetime): |
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
69 |
return str(obj) |
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
70 |
raise TypeError( |
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
71 |
'{} is not JSON serializable'.format(repr(obj)))
|
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
72 |
outfile_name = os.path.join('test/samples/expected/', domain)
|
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
73 |
with open(outfile_name, 'w') as outfil: |
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
74 |
expected_results = simplejson.dump(results, outfil, |
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
75 |
default=date2str4json) |
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
76 |
continue |
| 0 | 77 |
|
78 |
# Load expected result |
|
|
97
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
79 |
with open(os.path.join('test/samples/expected/', domain)) as infil:
|
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
80 |
expected_results = simplejson.load(infil) |
| 0 | 81 |
|
82 |
# Compare each key |
|
83 |
for key in results: |
|
|
97
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
84 |
total += 1 |
| 0 | 85 |
result = results.get(key) |
|
97
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
86 |
if isinstance(result, datetime.datetime): |
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
87 |
result = str(result) |
| 0 | 88 |
expected = expected_results.get(key) |
89 |
if expected != result: |
|
| 70 | 90 |
print("%s \t(%s):\t %s != %s" % (domain, key, result, expected))
|
| 0 | 91 |
fail += 1 |
92 |
||
93 |
if fail: |
|
|
97
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
94 |
self.fail("%d/%d sample whois attributes were not parsed properly!"
|
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
95 |
% (fail, total)) |
| 12 | 96 |
|
97 |
||
|
102
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
98 |
def test_ca_parse(self): |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
99 |
data = """ |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
100 |
Domain name: testdomain.ca |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
101 |
Domain status: registered |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
102 |
Creation date: 2000/11/20 |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
103 |
Expiry date: 2020/03/08 |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
104 |
Updated date: 2016/04/29 |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
105 |
DNSSEC: Unsigned |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
106 |
|
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
107 |
Registrar: |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
108 |
Name: Webnames.ca Inc. |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
109 |
Number: 70 |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
110 |
|
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
111 |
Registrant: |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
112 |
Name: Test Industries |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
113 |
|
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
114 |
Administrative contact: |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
115 |
Name: Test Person1 |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
116 |
Postal address: Test Address |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
117 |
Test City, TestVille |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
118 |
Phone: +1.1235434123x123 |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
119 |
Fax: +1.123434123 |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
120 |
Email: testperson1@testcompany.ca |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
121 |
|
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
122 |
Technical contact: |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
123 |
Name: Test Persion2 |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
124 |
Postal address: Other TestAddress |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
125 |
TestTown OCAS Canada |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
126 |
Phone: +1.09876545123 |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
127 |
Fax: +1.12312993873 |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
128 |
Email: testpersion2@testcompany.ca |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
129 |
|
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
130 |
Name servers: |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
131 |
ns1.testserver1.net |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
132 |
ns2.testserver2.net |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
133 |
""" |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
134 |
results = WhoisEntry.load('testcompany.ca', data)
|
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
135 |
expected_results = {
|
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
136 |
"updated_date": "2016-04-29 00:00:00", |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
137 |
"registrant_name": [ |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
138 |
"Webnames.ca Inc.", |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
139 |
"Test Industries", |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
140 |
"Test Person1", |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
141 |
"Test Persion2" |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
142 |
], |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
143 |
"fax": [ |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
144 |
"+1.123434123", |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
145 |
"+1.12312993873" |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
146 |
], |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
147 |
"dnssec": "Unsigned", |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
148 |
"registrant_number": "70", |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
149 |
"expiration_date": "2020-03-08 00:00:00", |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
150 |
"domain_name": "testdomain.ca", |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
151 |
"creation_date": "2000-11-20 00:00:00", |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
152 |
"phone": [ |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
153 |
"+1.1235434123x123", |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
154 |
"+1.09876545123" |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
155 |
], |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
156 |
"domain_status": "registered", |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
157 |
"emails": [ |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
158 |
"testperson1@testcompany.ca", |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
159 |
"testpersion2@testcompany.ca" |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
160 |
] |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
161 |
} |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
162 |
|
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
163 |
fail = 0 |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
164 |
total = 0 |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
165 |
|
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
166 |
# Compare each key |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
167 |
for key in expected_results: |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
168 |
total += 1 |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
169 |
result = results.get(key) |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
170 |
if isinstance(result, datetime.datetime): |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
171 |
result = str(result) |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
172 |
expected = expected_results.get(key) |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
173 |
if expected != result: |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
174 |
print("%s \t(%s):\t %s != %s" % (domain, key, result, expected))
|
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
175 |
fail += 1 |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
176 |
if fail: |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
177 |
self.fail("%d/%d sample whois attributes were not parsed properly!"
|
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
178 |
% (fail, total)) |
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
179 |
|
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
180 |
|
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
181 |
|
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
182 |
|
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
183 |
|
| 12 | 184 |
if __name__ == '__main__': |
185 |
unittest.main() |