Exemple #1
0
    def test_com_expiration(self):
        data = """
        Status: ok
        Updated Date: 2017-03-31T07:36:34Z
        Creation Date: 2013-02-21T19:24:57Z
        Registry Expiry Date: 2018-02-21T19:24:57Z

        >>> Last update of whois database: Sun, 31 Aug 2008 00:18:23 UTC <<<
        """
        w = WhoisEntry.load('urlowl.com', data)
        expires = w.expiration_date.strftime('%Y-%m-%d')
        self.assertEqual(expires, '2018-02-21')
Exemple #2
0
 def test_com_expiration(self):
     data = """
         Status: ok
         Updated Date: 14-apr-2008
         Creation Date: 14-apr-2008
         Expiration Date: 14-apr-2009
         
         >>> Last update of whois database: Sun, 31 Aug 2008 00:18:23 UTC <<<
     """
     w = WhoisEntry.load('urlowl.com', data)
     expires = w.expiration_date.strftime('%Y-%m-%d')
     self.assertEquals(expires, '2009-04-14')
 def test_com_expiration(self):
     data = """
     Status: ok
     Updated Date: 14-apr-2008
     Creation Date: 14-apr-2008
     Expiration Date: 14-apr-2009
     
     >>> Last update of whois database: Sun, 31 Aug 2008 00:18:23 UTC <<<
     """
     w = WhoisEntry.load('urlowl.com', data)
     expires = w.expiration_date.strftime('%Y-%m-%d')
     self.assertEqual(expires, '2009-04-14')
    def test_nl_expiration(self):
        data = """
        domain_name: randomtest.nl
        Status:      in quarantine
        Creation Date: 2008-09-24
        Updated Date: 2020-10-27
        Date out of quarantine: 2020-12-06T20:31:25
        """

        w = WhoisEntry.load('randomtest.nl', data)
        expires = w.expiration_date.strftime('%Y-%m-%d')
        self.assertEqual(expires, '2020-12-06')
Exemple #5
0
def test_com_expiration():
    data = dedent("""\
    Status: ok
    Updated Date: 2017-03-31T07:36:34Z
    Creation Date: 2013-02-21T19:24:57Z
    Registry Expiry Date: 2018-02-21T19:24:57Z

    >>> Last update of whois database: Sun, 31 Aug 2008 00:18:23 UTC <<<
    """)
    w = WhoisEntry.load('urlowl.com', data)
    expires = w['expired_date'].strftime('%Y-%m-%d')
    assert expires == '2018-02-21'
Exemple #6
0
    def test_com_allsamples(self):
        """
        Iterate over all of the sample/whois/*.com files, read the data,
        parse it, and compare to the expected values in sample/expected/.
        Only keys defined in keys_to_test will be tested.
        
        To generate fresh expected value dumps, see NOTE below.
        """
        keys_to_test = [
            'domain_name', 'expiration_date', 'updated_date', 'creation_date',
            'status'
        ]
        fail = 0
        for path in glob('test/samples/whois/*.com'):
            # Parse whois data
            domain = os.path.basename(path)
            whois_fp = open(path)
            data = whois_fp.read()

            w = WhoisEntry.load(domain, data)
            results = {}
            for key in keys_to_test:
                results[key] = w.get(key)

            # Load expected result
            expected_fp = open(os.path.join('test/samples/expected/', domain))
            expected_results = simplejson.load(expected_fp)

            # NOTE: Toggle condition below to write expected results from the parse results
            # This will overwrite the existing expected results. Only do this if you've manually
            # confirmed that the parser is generating correct values at its current state.
            if False:
                expected_fp = open(
                    os.path.join('test/samples/expected/', domain), 'w')
                expected_results = simplejson.dump(results, expected_fp)
                continue

            # Compare each key
            for key in results:
                result = results.get(key)
                expected = expected_results.get(key)
                if expected != result:
                    print "%s \t(%s):\t %s != %s" % (domain, key, result,
                                                     expected)
                    fail += 1

        if fail:
            self.fail("%d sample whois attributes were not parsed properly!" %
                      fail)
 def _parse_and_compare(self, domain_name, data, expected_results):
     results = WhoisEntry.load(domain_name, data)
     fail = 0
     total = 0
     # Compare each key
     for key in expected_results:
         total += 1
         result = results.get(key)
         if isinstance(result, datetime.datetime):
             result = str(result)
         expected = expected_results.get(key)
         if expected != result:
             print("%s \t(%s):\t %s != %s" % (domain_name, key, result, expected))
             fail += 1
     if fail:
         self.fail("%d/%d sample whois attributes were not parsed properly!"
                   % (fail, total))
Exemple #8
0
    def test_com_allsamples(self):
        """
        Iterate over all of the sample/whois/*.com files, read the data,
        parse it, and compare to the expected values in sample/expected/.
        Only keys defined in keys_to_test will be tested.
        
        To generate fresh expected value dumps, see NOTE below.
        """
        keys_to_test = ['domain_name', 'expiration_date', 'updated_date', 'creation_date', 'status']
        fail = 0
        for path in glob('test/samples/whois/*.com'):
            # Parse whois data
            domain = os.path.basename(path)
            whois_fp = open(path)
            data = whois_fp.read()
            
            w = WhoisEntry.load(domain, data)
            results = {}
            for key in keys_to_test:
                results[key] = w.get(key)

            # Load expected result
            expected_fp = open(os.path.join('test/samples/expected/', domain))
            expected_results = simplejson.load(expected_fp)
            
            # NOTE: Toggle condition below to write expected results from the parse results
            # This will overwrite the existing expected results. Only do this if you've manually
            # confirmed that the parser is generating correct values at its current state.
            if False:
                expected_fp = open(os.path.join('test/samples/expected/', domain), 'w')
                expected_results = simplejson.dump(results, expected_fp)
                continue
            
            # Compare each key
            for key in results:
                result = results.get(key)
                expected = expected_results.get(key)
                if expected != result:
                    print "%s \t(%s):\t %s != %s" % (domain, key, result, expected)
                    fail += 1
            
        if fail:
            self.fail("%d sample whois attributes were not parsed properly!" % fail)
Exemple #9
0
def test_all_samples(domain):
    """
    Iterate over all of the sample/whois/* files, read the data,
    parse it, and compare to the expected values in sample/expected/.
    Only keys defined in keys_to_test will be tested.

    To generate fresh expected value dumps, see NOTE below.
    """

    # NOTE: Toggle condition below to write expected results from the
    # parse results This will overwrite the existing expected results.
    # Only do this if you've manually confirmed that the parser is
    # generating correct values at its current state.

    s = (SAMPLES_DIR / "whois" / domain)
    result = json.dumps(WhoisEntry.load(s.name, s.read_text(encoding="utf-8")), default=date2str4json, indent=2)

    if False:
        (SAMPLES_DIR / "expected" / domain).write_text(result)

    expected = (SAMPLES_DIR / "expected" / domain).read_text(encoding="utf-8")

    # Load it again to ignore key order of the persisted json files
    assert json.loads(expected) == json.loads(result)
Exemple #10
0
    def test_com_allsamples(self):
        """
        Iterate over all of the sample/whois/*.com files, read the data,
        parse it, and compare to the expected values in sample/expected/.
        Only keys defined in keys_to_test will be tested.

        To generate fresh expected value dumps, see NOTE below.
        """
        keys_to_test = [
            'domain_name', 'expiration_date', 'updated_date', 'creation_date',
            'status'
        ]
        fail = 0
        total = 0
        whois_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                  'samples', 'whois', '*')
        expect_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                   'samples', 'expected')
        for path in glob(whois_path):
            # Parse whois data
            domain = os.path.basename(path)
            with open(path) as whois_fp:
                data = whois_fp.read()

            w = WhoisEntry.load(domain, data)
            results = {key: w.get(key) for key in keys_to_test}

            # NOTE: Toggle condition below to write expected results from the
            # parse results This will overwrite the existing expected results.
            # Only do this if you've manually confirmed that the parser is
            # generating correct values at its current state.
            if False:

                def date2str4json(obj):
                    if isinstance(obj, datetime.datetime):
                        return str(obj)
                    raise TypeError('{} is not JSON serializable'.format(
                        repr(obj)))

                outfile_name = os.path.join(expect_path, domain)
                with open(outfile_name, 'w') as outfil:
                    expected_results = json.dump(results,
                                                 outfil,
                                                 default=date2str4json)
                continue

            # Load expected result
            with open(os.path.join(expect_path, domain)) as infil:
                expected_results = json.load(infil)

            # Compare each key
            compare_keys = set.union(set(results), set(expected_results))
            if keys_to_test is not None:
                compare_keys = compare_keys.intersection(set(keys_to_test))
            for key in compare_keys:
                total += 1
                if key not in results:
                    print("%s \t(%s):\t Missing in results" % (
                        domain,
                        key,
                    ))
                    fail += 1
                    continue

                result = results.get(key)
                if isinstance(result, list):
                    result = [str(element) for element in result]
                if isinstance(result, datetime.datetime):
                    result = str(result)
                expected = expected_results.get(key)
                if expected != result:
                    print("%s \t(%s):\t %s != %s" %
                          (domain, key, result, expected))
                    fail += 1

        if fail:
            self.fail(
                "%d/%d sample whois attributes were not parsed properly!" %
                (fail, total))
    def test_ca_parse(self):
        data = """
        Domain name:           testdomain.ca
        Domain status:         registered
        Creation date:         2000/11/20
        Expiry date:           2020/03/08
        Updated date:          2016/04/29
        DNSSEC:                Unsigned

        Registrar:
            Name:              Webnames.ca Inc.
            Number:            70

        Registrant:
            Name:              Test Industries

        Administrative contact:
            Name:              Test Person1
            Postal address:    Test Address
                               Test City, TestVille
            Phone:             +1.1235434123x123
            Fax:               +1.123434123
            Email:             [email protected]

        Technical contact:
            Name:              Test Persion2
            Postal address:    Other TestAddress
                               TestTown OCAS Canada
            Phone:             +1.09876545123
            Fax:               +1.12312993873
            Email:             [email protected]

        Name servers:
            ns1.testserver1.net
            ns2.testserver2.net
        """
        results = WhoisEntry.load('testcompany.ca', data)
        expected_results = {
            "updated_date":
            "2016-04-29 00:00:00",
            "registrant_name": [
                "Webnames.ca Inc.", "Test Industries", "Test Person1",
                "Test Persion2"
            ],
            "fax": ["+1.123434123", "+1.12312993873"],
            "dnssec":
            "Unsigned",
            "registrant_number":
            "70",
            "expiration_date":
            "2020-03-08 00:00:00",
            "domain_name":
            "testdomain.ca",
            "creation_date":
            "2000-11-20 00:00:00",
            "phone": ["+1.1235434123x123", "+1.09876545123"],
            "domain_status":
            "registered",
            "emails":
            ["*****@*****.**", "*****@*****.**"]
        }

        fail = 0
        total = 0

        # Compare each key
        for key in expected_results:
            total += 1
            result = results.get(key)
            if isinstance(result, datetime.datetime):
                result = str(result)
            expected = expected_results.get(key)
            if expected != result:
                print("%s \t(%s):\t %s != %s" %
                      (domain, key, result, expected))
                fail += 1
        if fail:
            self.fail(
                "%d/%d sample whois attributes were not parsed properly!" %
                (fail, total))