Skip to content

Commit

Permalink
Add test for mismatched keys
Browse files Browse the repository at this point in the history
  • Loading branch information
pogzyb committed Oct 12, 2023
1 parent 6c37f5a commit 7b3260d
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 15 deletions.
69 changes: 69 additions & 0 deletions tests/samples/com_dict_asyncwhois.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"domain_name": "google.com",
"created": "1997-09-15T07:00:00+00:00",
"updated": "2019-09-09T15:39:04+00:00",
"expires": "2028-09-13T07:00:00+00:00",
"registrar": "MarkMonitor, Inc.",
"registrar_iana_id": "292",
"registrar_url": "http://www.markmonitor.com",
"registrar_abuse_email": "abusecomplaints@markmonitor.com",
"registrar_abuse_phone": "+1.2086851750",
"registrant_name": null,
"registrant_organization": "Google LLC",
"registrant_address": null,
"registrant_city": null,
"registrant_state": "CA",
"registrant_zipcode": null,
"registrant_country": "US",
"registrant_email": "Select Request Email Form at https://domains.markmonitor.com/whois/google.com",
"registrant_phone": null,
"registrant_fax": null,
"dnssec": "unsigned",
"status": [
"clientUpdateProhibited (https://www.icann.org/epp#clientUpdateProhibited)",
"clientTransferProhibited (https://www.icann.org/epp#clientTransferProhibited)",
"clientDeleteProhibited (https://www.icann.org/epp#clientDeleteProhibited)",
"serverUpdateProhibited (https://www.icann.org/epp#serverUpdateProhibited)",
"serverTransferProhibited (https://www.icann.org/epp#serverTransferProhibited)",
"serverDeleteProhibited (https://www.icann.org/epp#serverDeleteProhibited)"
],
"name_servers": [
"ns2.google.com",
"ns1.google.com",
"ns4.google.com",
"ns3.google.com"
],
"admin_name": null,
"admin_id": null,
"admin_organization": "Google LLC",
"admin_city": null,
"admin_address": null,
"admin_state": "CA",
"admin_zipcode": null,
"admin_country": "US",
"admin_phone": null,
"admin_fax": null,
"admin_email": "Select Request Email Form at https://domains.markmonitor.com/whois/google.com",
"billing_name": null,
"billing_id": null,
"billing_organization": null,
"billing_city": null,
"billing_address": null,
"billing_state": null,
"billing_zipcode": null,
"billing_country": null,
"billing_phone": null,
"billing_fax": null,
"billing_email": null,
"tech_name": null,
"tech_id": null,
"tech_organization": "Google LLC",
"tech_city": null,
"tech_address": null,
"tech_state": "CA",
"tech_zipcode": null,
"tech_country": "US",
"tech_phone": null,
"tech_fax": null,
"tech_email": "Select Request Email Form at https://domains.markmonitor.com/whois/google.com"
}
52 changes: 52 additions & 0 deletions tests/samples/com_dict_whodap.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"abuse_email": "abusecomplaints@markmonitor.com",
"abuse_phone": "+1.2086851750",
"admin_name": "REDACTED FOR PRIVACY",
"admin_organization": "REDACTED FOR PRIVACY",
"admin_email": "REDACTED FOR PRIVACY",
"admin_address": "CA, US",
"admin_phone": "REDACTED FOR PRIVACY",
"admin_fax": "REDACTED FOR PRIVACY",
"billing_name": null,
"billing_organization": null,
"billing_email": null,
"billing_address": null,
"billing_phone": null,
"billing_fax": null,
"registrant_name": "REDACTED FOR PRIVACY",
"registrant_organization": null,
"registrant_email": "REDACTED FOR PRIVACY",
"registrant_address": "CA, US",
"registrant_phone": "REDACTED FOR PRIVACY",
"registrant_fax": "REDACTED FOR PRIVACY",
"registrar_name": null,
"registrar_email": null,
"registrar_address": "3540 E Longwing Ln, Meridian, ID, 83646, US",
"registrar_phone": null,
"registrar_fax": null,
"technical_name": "REDACTED FOR PRIVACY",
"technical_organization": "REDACTED FOR PRIVACY",
"technical_email": "REDACTED FOR PRIVACY",
"technical_address": "CA, US",
"technical_phone": "REDACTED FOR PRIVACY",
"technical_fax": "REDACTED FOR PRIVACY",
"created_date": "1997-09-15T07:00:00+00:00",
"updated_date": "2019-09-09T15:39:04+00:00",
"expires_date": "2028-09-13T07:00:00+00:00",
"status": [
"client update prohibited",
"client transfer prohibited",
"client delete prohibited",
"server update prohibited",
"server transfer prohibited",
"server delete prohibited"
],
"nameservers": [
"ns1.google.com",
"ns2.google.com",
"ns3.google.com",
"ns4.google.com"
],
"domain_name": "google.com",
"dnssec": "unsigned"
}
64 changes: 49 additions & 15 deletions tests/test_parser_methods.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,53 @@
import unittest
import datetime
import json
import os

from asyncwhois.parse import BaseParser
from asyncwhois.parse import BaseParser, convert_whodap_keys


class TestWhoIsParserMethods(unittest.TestCase):
def test_convert_whodap_keys(self):
with open(
os.path.join(
os.path.abspath(os.path.dirname(__file__)),
"samples/com_dict_asyncwhois.json",
)
) as o:
asyncwhois_dict = json.loads(o.read())

with open(
os.path.join(
os.path.abspath(os.path.dirname(__file__)),
"samples/com_dict_whodap.json",
)
) as o:
whodap_dict = json.loads(o.read())

whodap_keys_after = convert_whodap_keys(whodap_dict).keys()
asyncwhois_keys = asyncwhois_dict.keys()
for whodap_key in whodap_keys_after:
assert (
whodap_key in asyncwhois_keys
), f"{whodap_key} not in {asyncwhois_keys}"

for asyncwhois_key in asyncwhois_dict.keys():
assert (
asyncwhois_key in whodap_keys_after
), f"{asyncwhois_key} not in {whodap_keys_after}"

def test_parse_dates(self):
date_strings = [
'11-aug-2020',
'11-August-2020',
'11-09-2020',
'2020-09-20',
'2020.09.20',
'2020/09/20',
'2020. 09. 20.',
'2020.09.20 11:11:11',
'August 11 2020',
'20200920'
"11-aug-2020",
"11-August-2020",
"11-09-2020",
"2020-09-20",
"2020.09.20",
"2020/09/20",
"2020. 09. 20.",
"2020.09.20 11:11:11",
"August 11 2020",
"20200920",
]

for date_string in date_strings:
Expand All @@ -31,11 +61,13 @@ def test_find_match(self):
Name server: ns2.google.com
Status: ok
"""
domain = BaseParser().find_match(r'domain name: *(.+)', test_blob)
domain = BaseParser().find_match(r"domain name: *(.+)", test_blob)
self.assertEqual(domain, "google.com")
name_servers = BaseParser().find_match(r'name server: *(.+)', test_blob, many=True)
name_servers = BaseParser().find_match(
r"name server: *(.+)", test_blob, many=True
)
self.assertEqual(len(name_servers), 2)
status = BaseParser().find_match(r'status: *(.+)', test_blob, many=True)
status = BaseParser().find_match(r"status: *(.+)", test_blob, many=True)
self.assertEqual(len(status), 1)

def test_find_multiline_match(self):
Expand All @@ -50,5 +82,7 @@ def test_find_multiline_match(self):
Registrar: someone
"""
name_servers = BaseParser().find_multiline_match(r'Domain nameservers:\n', test_blob)
name_servers = BaseParser().find_multiline_match(
r"Domain nameservers:\n", test_blob
)
self.assertEqual(len(name_servers), 4)

0 comments on commit 7b3260d

Please sign in to comment.