test/test_parser.py
changeset 102 e8cb8d1367c0
parent 97 44522cd37b07
child 135 808c8bc803f5
equal deleted inserted replaced
101:e804426aad35 102:e8cb8d1367c0
    93         if fail:
    93         if fail:
    94             self.fail("%d/%d sample whois attributes were not parsed properly!"
    94             self.fail("%d/%d sample whois attributes were not parsed properly!"
    95                       % (fail, total))
    95                       % (fail, total))
    96 
    96 
    97 
    97 
       
    98     def test_ca_parse(self):
       
    99         data = """
       
   100         Domain name:           testdomain.ca
       
   101         Domain status:         registered
       
   102         Creation date:         2000/11/20
       
   103         Expiry date:           2020/03/08
       
   104         Updated date:          2016/04/29
       
   105         DNSSEC:                Unsigned
       
   106 
       
   107         Registrar:
       
   108             Name:              Webnames.ca Inc.
       
   109             Number:            70
       
   110 
       
   111         Registrant:
       
   112             Name:              Test Industries
       
   113 
       
   114         Administrative contact:
       
   115             Name:              Test Person1
       
   116             Postal address:    Test Address
       
   117                                Test City, TestVille
       
   118             Phone:             +1.1235434123x123
       
   119             Fax:               +1.123434123
       
   120             Email:             testperson1@testcompany.ca
       
   121 
       
   122         Technical contact:
       
   123             Name:              Test Persion2
       
   124             Postal address:    Other TestAddress
       
   125                                TestTown OCAS Canada
       
   126             Phone:             +1.09876545123
       
   127             Fax:               +1.12312993873
       
   128             Email:             testpersion2@testcompany.ca
       
   129 
       
   130         Name servers:
       
   131             ns1.testserver1.net
       
   132             ns2.testserver2.net
       
   133         """
       
   134         results = WhoisEntry.load('testcompany.ca', data)
       
   135         expected_results = {
       
   136             "updated_date": "2016-04-29 00:00:00", 
       
   137             "registrant_name": [
       
   138                 "Webnames.ca Inc.", 
       
   139                 "Test Industries", 
       
   140                 "Test Person1", 
       
   141                 "Test Persion2"
       
   142             ], 
       
   143             "fax": [
       
   144                 "+1.123434123", 
       
   145                 "+1.12312993873"
       
   146             ], 
       
   147             "dnssec": "Unsigned", 
       
   148             "registrant_number": "70", 
       
   149             "expiration_date": "2020-03-08 00:00:00", 
       
   150             "domain_name": "testdomain.ca", 
       
   151             "creation_date": "2000-11-20 00:00:00", 
       
   152             "phone": [
       
   153                 "+1.1235434123x123", 
       
   154                 "+1.09876545123"
       
   155             ], 
       
   156             "domain_status": "registered", 
       
   157             "emails": [
       
   158                 "testperson1@testcompany.ca", 
       
   159                 "testpersion2@testcompany.ca"
       
   160             ]
       
   161         }
       
   162         
       
   163         fail = 0
       
   164         total = 0
       
   165 
       
   166         # Compare each key
       
   167         for key in expected_results:
       
   168             total += 1
       
   169             result = results.get(key)
       
   170             if isinstance(result, datetime.datetime):
       
   171                 result = str(result)
       
   172             expected = expected_results.get(key)
       
   173             if expected != result:
       
   174                 print("%s \t(%s):\t %s != %s" % (domain, key, result, expected))
       
   175                 fail += 1
       
   176         if fail:
       
   177             self.fail("%d/%d sample whois attributes were not parsed properly!"
       
   178                       % (fail, total))
       
   179 
       
   180 
       
   181 
       
   182         
       
   183 
    98 if __name__ == '__main__':
   184 if __name__ == '__main__':
    99     unittest.main()
   185     unittest.main()