| author | Egon Kidmose <kidmose@gmail.com> |
| Thu, 15 Feb 2018 15:00:18 +0100 | |
| branch | feature/test-missing-keys |
| changeset 166 | 6cbe4891d62a |
| parent 157 | f091b6581d21 |
| child 179 | 2fb992c480e4 |
| 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 |
|
152
f614365ab91b
Dealing properly when there are multiple dates
joan <aseques@gmail.com>
parents:
149
diff
changeset
|
28 |
Updated Date: 2017-03-31T07:36:34Z |
|
f614365ab91b
Dealing properly when there are multiple dates
joan <aseques@gmail.com>
parents:
149
diff
changeset
|
29 |
Creation Date: 2013-02-21T19:24:57Z |
|
f614365ab91b
Dealing properly when there are multiple dates
joan <aseques@gmail.com>
parents:
149
diff
changeset
|
30 |
Registry Expiry Date: 2018-02-21T19:24:57Z |
| 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')
|
|
152
f614365ab91b
Dealing properly when there are multiple dates
joan <aseques@gmail.com>
parents:
149
diff
changeset
|
36 |
self.assertEqual(expires, '2018-02-21') |
| 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 |
|
166
6cbe4891d62a
test_parser.py: Fail on missing keys
Egon Kidmose <kidmose@gmail.com>
parents:
157
diff
changeset
|
88 |
for key in set(results).union(set(expected_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 |
|
166
6cbe4891d62a
test_parser.py: Fail on missing keys
Egon Kidmose <kidmose@gmail.com>
parents:
157
diff
changeset
|
90 |
if key not in results: |
|
6cbe4891d62a
test_parser.py: Fail on missing keys
Egon Kidmose <kidmose@gmail.com>
parents:
157
diff
changeset
|
91 |
print("%s \t(%s):\t Missing in results" % (domain, key,))
|
|
6cbe4891d62a
test_parser.py: Fail on missing keys
Egon Kidmose <kidmose@gmail.com>
parents:
157
diff
changeset
|
92 |
fail += 1 |
|
6cbe4891d62a
test_parser.py: Fail on missing keys
Egon Kidmose <kidmose@gmail.com>
parents:
157
diff
changeset
|
93 |
continue |
|
6cbe4891d62a
test_parser.py: Fail on missing keys
Egon Kidmose <kidmose@gmail.com>
parents:
157
diff
changeset
|
94 |
|
| 0 | 95 |
result = results.get(key) |
|
152
f614365ab91b
Dealing properly when there are multiple dates
joan <aseques@gmail.com>
parents:
149
diff
changeset
|
96 |
if isinstance(result, list): |
|
f614365ab91b
Dealing properly when there are multiple dates
joan <aseques@gmail.com>
parents:
149
diff
changeset
|
97 |
result = [str(element) for element in result] |
|
97
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
98 |
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
|
99 |
result = str(result) |
| 0 | 100 |
expected = expected_results.get(key) |
101 |
if expected != result: |
|
| 70 | 102 |
print("%s \t(%s):\t %s != %s" % (domain, key, result, expected))
|
| 0 | 103 |
fail += 1 |
| 135 | 104 |
|
| 0 | 105 |
if fail: |
|
97
44522cd37b07
Fixed tests. Also some UTF bugs (python2/3 hell)
Mario D. Santana <mario@elorangutan.com>
parents:
70
diff
changeset
|
106 |
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
|
107 |
% (fail, total)) |
| 12 | 108 |
|
109 |
||
|
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
|
110 |
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
|
111 |
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
|
112 |
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
|
113 |
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
|
114 |
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
|
115 |
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
|
116 |
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
|
117 |
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
|
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 |
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
|
120 |
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
|
121 |
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
|
122 |
|
|
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 |
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
|
124 |
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
|
125 |
|
|
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 |
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
|
127 |
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
|
128 |
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
|
129 |
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
|
130 |
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
|
131 |
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
|
132 |
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
|
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 |
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
|
135 |
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
|
136 |
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
|
137 |
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
|
138 |
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
|
139 |
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
|
140 |
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
|
141 |
|
|
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 |
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
|
143 |
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
|
144 |
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
|
145 |
""" |
|
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 |
expected_results = {
|
| 135 | 147 |
"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
|
148 |
"registrant_name": [ |
| 135 | 149 |
"Webnames.ca Inc.", |
150 |
"Test Industries", |
|
151 |
"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
|
152 |
"Test Persion2" |
| 135 | 153 |
], |
|
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
|
154 |
"fax": [ |
| 135 | 155 |
"+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
|
156 |
"+1.12312993873" |
| 135 | 157 |
], |
158 |
"dnssec": "Unsigned", |
|
159 |
"registrant_number": "70", |
|
160 |
"expiration_date": "2020-03-08 00:00:00", |
|
161 |
"domain_name": "testdomain.ca", |
|
162 |
"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
|
163 |
"phone": [ |
| 135 | 164 |
"+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
|
165 |
"+1.09876545123" |
| 135 | 166 |
], |
167 |
"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
|
168 |
"emails": [ |
| 135 | 169 |
"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
|
170 |
"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
|
171 |
] |
|
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 |
} |
| 135 | 173 |
self._parse_and_compare('testcompany.ca', data, expected_results)
|
174 |
||
175 |
def test_il_parse(self): |
|
176 |
data = """ |
|
177 |
query: python.org.il |
|
178 |
||
179 |
reg-name: python |
|
180 |
domain: python.org.il |
|
181 |
||
182 |
descr: Arik Baratz |
|
183 |
descr: PO Box 7775 PMB 8452 |
|
184 |
descr: San Francisco, CA |
|
185 |
descr: 94120 |
|
186 |
descr: USA |
|
187 |
phone: +1 650 6441973 |
|
188 |
e-mail: hostmaster AT arik.baratz.org |
|
189 |
admin-c: LD-AB16063-IL |
|
190 |
tech-c: LD-AB16063-IL |
|
191 |
zone-c: LD-AB16063-IL |
|
192 |
nserver: dns1.zoneedit.com |
|
193 |
nserver: dns2.zoneedit.com |
|
194 |
nserver: dns3.zoneedit.com |
|
195 |
validity: 10-05-2018 |
|
196 |
DNSSEC: unsigned |
|
197 |
status: Transfer Locked |
|
198 |
changed: domain-registrar AT isoc.org.il 20050524 (Assigned) |
|
199 |
changed: domain-registrar AT isoc.org.il 20070520 (Transferred) |
|
200 |
changed: domain-registrar AT isoc.org.il 20070520 (Changed) |
|
201 |
changed: domain-registrar AT isoc.org.il 20070520 (Changed) |
|
202 |
changed: domain-registrar AT isoc.org.il 20070807 (Changed) |
|
203 |
changed: domain-registrar AT isoc.org.il 20071025 (Changed) |
|
204 |
changed: domain-registrar AT isoc.org.il 20071025 (Changed) |
|
205 |
changed: domain-registrar AT isoc.org.il 20081221 (Changed) |
|
206 |
changed: domain-registrar AT isoc.org.il 20081221 (Changed) |
|
207 |
changed: domain-registrar AT isoc.org.il 20160301 (Changed) |
|
208 |
changed: domain-registrar AT isoc.org.il 20160301 (Changed) |
|
209 |
||
210 |
person: Arik Baratz |
|
211 |
address: PO Box 7775 PMB 8452 |
|
212 |
address: San Francisco, CA |
|
213 |
address: 94120 |
|
214 |
address: USA |
|
215 |
phone: +1 650 9635533 |
|
216 |
e-mail: hostmaster AT arik.baratz.org |
|
217 |
nic-hdl: LD-AB16063-IL |
|
218 |
changed: Managing Registrar 20070514 |
|
219 |
changed: Managing Registrar 20081002 |
|
220 |
changed: Managing Registrar 20081221 |
|
221 |
changed: Managing Registrar 20081221 |
|
222 |
changed: Managing Registrar 20090502 |
|
223 |
||
224 |
registrar name: LiveDns Ltd |
|
225 |
registrar info: http://domains.livedns.co.il |
|
226 |
""" |
|
227 |
expected_results = {
|
|
228 |
"updated_date": None, |
|
229 |
"registrant_name": "Arik Baratz", |
|
230 |
"fax": None, |
|
231 |
"dnssec": "unsigned", |
|
232 |
"expiration_date": "2018-05-10 00:00:00", |
|
233 |
"domain_name": "python.org.il", |
|
234 |
"creation_date": None, |
|
235 |
"phone": ['+1 650 6441973', '+1 650 9635533'], |
|
236 |
"status": "Transfer Locked", |
|
237 |
"emails": "hostmaster@arik.baratz.org", |
|
238 |
"name_servers": ["dns1.zoneedit.com", "dns2.zoneedit.com", "dns3.zoneedit.com"], |
|
239 |
"registrar": "LiveDns Ltd", |
|
240 |
"referral_url": "http://domains.livedns.co.il" |
|
241 |
} |
|
242 |
self._parse_and_compare('python.org.il', data, expected_results)
|
|
243 |
||
|
156
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
244 |
def test_ie_parse(self): |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
245 |
data = """ |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
246 |
domain: rte.ie |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
247 |
descr: RTE Commercial Enterprises Limited |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
248 |
descr: Body Corporate (Ltd,PLC,Company) |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
249 |
descr: Corporate Name |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
250 |
admin-c: AWB910-IEDR |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
251 |
admin-c: JM474-IEDR |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
252 |
tech-c: JM474-IEDR |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
253 |
registration: 11-February-2000 |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
254 |
renewal: 31-March-2024 |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
255 |
holder-type: Billable |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
256 |
locked: NO |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
257 |
ren-status: Active |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
258 |
in-zone: 1 |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
259 |
nserver: ns1.rte.ie 162.159.0.73 2400:cb00:2049:1::a29f:49 |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
260 |
nserver: ns2.rte.ie 162.159.1.73 2400:cb00:2049:1::a29f:149 |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
261 |
nserver: ns3.rte.ie 162.159.2.27 2400:cb00:2049:1::a29f:21b |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
262 |
nserver: ns4.rte.ie 162.159.3.18 2400:cb00:2049:1::a29f:312 |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
263 |
source: IEDR |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
264 |
|
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
265 |
person: Michael Kennedy |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
266 |
nic-hdl: AWB910-IEDR |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
267 |
source: IEDR |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
268 |
|
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
269 |
person: John Moylan |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
270 |
nic-hdl: JM474-IEDR |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
271 |
source: IEDR |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
272 |
|
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
273 |
person: John Moylan |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
274 |
nic-hdl: JM474-IEDR |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
275 |
source: IEDR""" |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
276 |
|
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
277 |
expected_results = {
|
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
278 |
"domain_name": "rte.ie", |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
279 |
"description": [ |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
280 |
"RTE Commercial Enterprises Limited", |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
281 |
"Body Corporate (Ltd,PLC,Company)", |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
282 |
"Corporate Name" |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
283 |
], |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
284 |
"source": "IEDR", |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
285 |
"creation_date": "2000-02-11 00:00:00", |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
286 |
"expiration_date": "2024-03-31 00:00:00", |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
287 |
"name_servers": [ |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
288 |
"ns1.rte.ie 162.159.0.73 2400:cb00:2049:1::a29f:49", |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
289 |
"ns2.rte.ie 162.159.1.73 2400:cb00:2049:1::a29f:149", |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
290 |
"ns3.rte.ie 162.159.2.27 2400:cb00:2049:1::a29f:21b", |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
291 |
"ns4.rte.ie 162.159.3.18 2400:cb00:2049:1::a29f:312" |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
292 |
], |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
293 |
"status": "Active", |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
294 |
"admin_id": [ |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
295 |
"AWB910-IEDR", |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
296 |
"JM474-IEDR" |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
297 |
], |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
298 |
"tech_id": "JM474-IEDR" |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
299 |
} |
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
300 |
self._parse_and_compare('rte.ie', data, expected_results)
|
|
9437303d43e8
Add handling of .ie domains
Vanush Paturyan <ektich@gmail.com>
parents:
135
diff
changeset
|
301 |
|
| 135 | 302 |
def _parse_and_compare(self, domain_name, data, expected_results): |
303 |
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
|
304 |
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
|
305 |
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
|
306 |
# 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
|
307 |
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
|
308 |
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
|
309 |
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
|
310 |
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
|
311 |
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
|
312 |
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
|
313 |
if expected != result: |
| 135 | 314 |
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
|
315 |
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
|
316 |
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
|
317 |
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
|
318 |
% (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
|
319 |
|
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
320 |
|
|
e8cb8d1367c0
Add more support for .ca domains parse dates, names, and emails correctly
Brian Murphy <brian.p.murphy@gmail.com>
parents:
97
diff
changeset
|
321 |
|
| 12 | 322 |
if __name__ == '__main__': |
323 |
unittest.main() |