| author | joan <aseques@gmail.com> |
| Fri, 08 Dec 2017 23:52:04 +0100 | |
| changeset 149 | 3aff6a7772b3 |
| parent 135 | 808c8bc803f5 |
| child 152 | f614365ab91b |
| 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 |
|
| 135 | 16 |
try: |
17 |
import json |
|
18 |
except: |
|
19 |
import simplejson as json |
|
| 0 | 20 |
from glob import glob |
21 |
||
| 12 | 22 |
from whois.parser import WhoisEntry, cast_date |
| 0 | 23 |
|
24 |
class TestParser(unittest.TestCase): |
|
25 |
def test_com_expiration(self): |
|
26 |
data = """ |
|
|
97
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
27 |
Status: ok |
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
28 |
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
|
29 |
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
|
30 |
Expiration Date: 14-apr-2009 |
| 135 | 31 |
|
|
97
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
32 |
>>> Last update of whois database: Sun, 31 Aug 2008 00:18:23 UTC <<< |
| 0 | 33 |
""" |
34 |
w = WhoisEntry.load('urlowl.com', data)
|
|
| 12 | 35 |
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
|
36 |
self.assertEqual(expires, '2009-04-14') |
| 0 | 37 |
|
38 |
def test_cast_date(self): |
|
39 |
dates = ['14-apr-2008', '2008-04-14'] |
|
40 |
for d in dates: |
|
| 12 | 41 |
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
|
42 |
self.assertEqual(r, '2008-04-14') |
| 0 | 43 |
|
44 |
def test_com_allsamples(self): |
|
45 |
""" |
|
46 |
Iterate over all of the sample/whois/*.com files, read the data, |
|
47 |
parse it, and compare to the expected values in sample/expected/. |
|
48 |
Only keys defined in keys_to_test will be tested. |
|
| 135 | 49 |
|
| 0 | 50 |
To generate fresh expected value dumps, see NOTE below. |
51 |
""" |
|
|
97
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
52 |
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
|
53 |
'creation_date', 'status'] |
| 0 | 54 |
fail = 0 |
|
97
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
55 |
total = 0 |
|
149
3aff6a7772b3
Improve path detection for the test directories in windows
joan <aseques@gmail.com>
parents:
135
diff
changeset
|
56 |
whois_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),'samples','whois','*') |
|
3aff6a7772b3
Improve path detection for the test directories in windows
joan <aseques@gmail.com>
parents:
135
diff
changeset
|
57 |
expect_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'samples','expected') |
|
3aff6a7772b3
Improve path detection for the test directories in windows
joan <aseques@gmail.com>
parents:
135
diff
changeset
|
58 |
for path in glob(whois_path): |
| 0 | 59 |
# Parse whois data |
60 |
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
|
61 |
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
|
62 |
data = whois_fp.read() |
| 135 | 63 |
|
| 0 | 64 |
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
|
65 |
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
|
66 |
|
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
67 |
# 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
|
68 |
# 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
|
69 |
# 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
|
70 |
# 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
|
71 |
if False: |
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
72 |
def date2str4json(obj): |
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
73 |
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
|
74 |
return str(obj) |
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
75 |
raise TypeError( |
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
76 |
'{} is not JSON serializable'.format(repr(obj)))
|
|
149
3aff6a7772b3
Improve path detection for the test directories in windows
joan <aseques@gmail.com>
parents:
135
diff
changeset
|
77 |
outfile_name = os.path.join(expect_path, domain) |
|
97
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
78 |
with open(outfile_name, 'w') as outfil: |
| 135 | 79 |
expected_results = json.dump(results, outfil, |
|
97
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
80 |
default=date2str4json) |
|
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
81 |
continue |
| 0 | 82 |
|
83 |
# Load expected result |
|
|
149
3aff6a7772b3
Improve path detection for the test directories in windows
joan <aseques@gmail.com>
parents:
135
diff
changeset
|
84 |
with open(os.path.join(expect_path, domain)) as infil: |
| 135 | 85 |
expected_results = json.load(infil) |
86 |
||
| 0 | 87 |
# Compare each key |
88 |
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
|
89 |
total += 1 |
| 0 | 90 |
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
|
91 |
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
|
92 |
result = str(result) |
| 0 | 93 |
expected = expected_results.get(key) |
94 |
if expected != result: |
|
| 70 | 95 |
print("%s \t(%s):\t %s != %s" % (domain, key, result, expected))
|
| 0 | 96 |
fail += 1 |
| 135 | 97 |
|
| 0 | 98 |
if fail: |
|
97
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
99 |
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
|
100 |
% (fail, total)) |
| 12 | 101 |
|
102 |
||
|
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
|
103 |
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
|
104 |
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
|
105 |
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
|
106 |
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
|
107 |
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
|
108 |
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
|
109 |
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
|
110 |
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
|
111 |
|
|
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 |
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
|
113 |
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
|
114 |
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
|
115 |
|
|
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 |
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
|
117 |
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
|
118 |
|
|
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 |
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
|
120 |
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
|
121 |
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
|
122 |
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
|
123 |
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
|
124 |
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
|
125 |
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
|
126 |
|
|
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 |
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
|
128 |
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
|
129 |
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
|
130 |
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
|
131 |
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
|
132 |
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
|
133 |
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
|
134 |
|
|
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 |
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
|
136 |
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
|
137 |
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
|
138 |
""" |
|
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 |
expected_results = {
|
| 135 | 140 |
"updated_date": "2016-04-29 00:00:00", |
|
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
|
141 |
"registrant_name": [ |
| 135 | 142 |
"Webnames.ca Inc.", |
143 |
"Test Industries", |
|
144 |
"Test Person1", |
|
|
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
|
145 |
"Test Persion2" |
| 135 | 146 |
], |
|
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
|
147 |
"fax": [ |
| 135 | 148 |
"+1.123434123", |
|
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
|
149 |
"+1.12312993873" |
| 135 | 150 |
], |
151 |
"dnssec": "Unsigned", |
|
152 |
"registrant_number": "70", |
|
153 |
"expiration_date": "2020-03-08 00:00:00", |
|
154 |
"domain_name": "testdomain.ca", |
|
155 |
"creation_date": "2000-11-20 00:00:00", |
|
|
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
|
156 |
"phone": [ |
| 135 | 157 |
"+1.1235434123x123", |
|
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
|
158 |
"+1.09876545123" |
| 135 | 159 |
], |
160 |
"domain_status": "registered", |
|
|
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
|
161 |
"emails": [ |
| 135 | 162 |
"testperson1@testcompany.ca", |
|
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
|
163 |
"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
|
164 |
] |
|
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 |
} |
| 135 | 166 |
self._parse_and_compare('testcompany.ca', data, expected_results)
|
167 |
||
168 |
def test_il_parse(self): |
|
169 |
data = """ |
|
170 |
query: python.org.il |
|
171 |
||
172 |
reg-name: python |
|
173 |
domain: python.org.il |
|
174 |
||
175 |
descr: Arik Baratz |
|
176 |
descr: PO Box 7775 PMB 8452 |
|
177 |
descr: San Francisco, CA |
|
178 |
descr: 94120 |
|
179 |
descr: USA |
|
180 |
phone: +1 650 6441973 |
|
181 |
e-mail: hostmaster AT arik.baratz.org |
|
182 |
admin-c: LD-AB16063-IL |
|
183 |
tech-c: LD-AB16063-IL |
|
184 |
zone-c: LD-AB16063-IL |
|
185 |
nserver: dns1.zoneedit.com |
|
186 |
nserver: dns2.zoneedit.com |
|
187 |
nserver: dns3.zoneedit.com |
|
188 |
validity: 10-05-2018 |
|
189 |
DNSSEC: unsigned |
|
190 |
status: Transfer Locked |
|
191 |
changed: domain-registrar AT isoc.org.il 20050524 (Assigned) |
|
192 |
changed: domain-registrar AT isoc.org.il 20070520 (Transferred) |
|
193 |
changed: domain-registrar AT isoc.org.il 20070520 (Changed) |
|
194 |
changed: domain-registrar AT isoc.org.il 20070520 (Changed) |
|
195 |
changed: domain-registrar AT isoc.org.il 20070807 (Changed) |
|
196 |
changed: domain-registrar AT isoc.org.il 20071025 (Changed) |
|
197 |
changed: domain-registrar AT isoc.org.il 20071025 (Changed) |
|
198 |
changed: domain-registrar AT isoc.org.il 20081221 (Changed) |
|
199 |
changed: domain-registrar AT isoc.org.il 20081221 (Changed) |
|
200 |
changed: domain-registrar AT isoc.org.il 20160301 (Changed) |
|
201 |
changed: domain-registrar AT isoc.org.il 20160301 (Changed) |
|
202 |
||
203 |
person: Arik Baratz |
|
204 |
address: PO Box 7775 PMB 8452 |
|
205 |
address: San Francisco, CA |
|
206 |
address: 94120 |
|
207 |
address: USA |
|
208 |
phone: +1 650 9635533 |
|
209 |
e-mail: hostmaster AT arik.baratz.org |
|
210 |
nic-hdl: LD-AB16063-IL |
|
211 |
changed: Managing Registrar 20070514 |
|
212 |
changed: Managing Registrar 20081002 |
|
213 |
changed: Managing Registrar 20081221 |
|
214 |
changed: Managing Registrar 20081221 |
|
215 |
changed: Managing Registrar 20090502 |
|
216 |
||
217 |
registrar name: LiveDns Ltd |
|
218 |
registrar info: http://domains.livedns.co.il |
|
219 |
""" |
|
220 |
expected_results = {
|
|
221 |
"updated_date": None, |
|
222 |
"registrant_name": "Arik Baratz", |
|
223 |
"fax": None, |
|
224 |
"dnssec": "unsigned", |
|
225 |
"expiration_date": "2018-05-10 00:00:00", |
|
226 |
"domain_name": "python.org.il", |
|
227 |
"creation_date": None, |
|
228 |
"phone": ['+1 650 6441973', '+1 650 9635533'], |
|
229 |
"status": "Transfer Locked", |
|
230 |
"emails": "hostmaster@arik.baratz.org", |
|
231 |
"name_servers": ["dns1.zoneedit.com", "dns2.zoneedit.com", "dns3.zoneedit.com"], |
|
232 |
"registrar": "LiveDns Ltd", |
|
233 |
"referral_url": "http://domains.livedns.co.il" |
|
234 |
} |
|
235 |
self._parse_and_compare('python.org.il', data, expected_results)
|
|
236 |
||
237 |
def _parse_and_compare(self, domain_name, data, expected_results): |
|
238 |
results = WhoisEntry.load(domain_name, data) |
|
|
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
|
239 |
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
|
240 |
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
|
241 |
# 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
|
242 |
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
|
243 |
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
|
244 |
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
|
245 |
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
|
246 |
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
|
247 |
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
|
248 |
if expected != result: |
| 135 | 249 |
print("%s \t(%s):\t %s != %s" % (domain_name, key, result, expected))
|
|
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
|
250 |
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
|
251 |
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
|
252 |
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
|
253 |
% (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
|
254 |
|
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
255 |
|
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
256 |
|
| 12 | 257 |
if __name__ == '__main__': |
258 |
unittest.main() |