From be59b9110753c788a430a0e1632fbd563bd07ea3 Mon Sep 17 00:00:00 2001 From: "Christopher K. Hoadley" Date: Sat, 2 Feb 2019 20:32:06 -0600 Subject: [PATCH] Add information about a claimed and an unclaimed username to the site information. This will allow the tests to directly source the information from the JSON data. It will also allow people who add new sites to also add test data (which will automatically get tested). Add a new test method which finds all sites of a given detect algorithm, and which also has test vectors, and runs tests against them. At the current time, the test vectors are optional. But, once when there is finally complete coverage, then they will be required. Anyone who adds a site without also adding test data will trigger a failure. --- data.json | 4 +++- tests/all.py | 12 ++---------- tests/base.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 11 deletions(-) diff --git a/data.json b/data.json index ed7b9fb9..2b33fab6 100644 --- a/data.json +++ b/data.json @@ -221,7 +221,9 @@ "rank": 921, "regexCheck": "^[a-zA-Z][a-zA-Z0-9_-]*$", "url": "https://dribbble.com/{}", - "urlMain": "https://dribbble.com/" + "urlMain": "https://dribbble.com/", + "username_claimed": "blue", + "username_unclaimed": "noonewouldeverusethis7" }, "EVE Online": { "errorType": "response_url", diff --git a/tests/all.py b/tests/all.py index e21e960f..0f26dbde 100644 --- a/tests/all.py +++ b/tests/all.py @@ -205,11 +205,7 @@ class SherlockSiteCoverageTests(SherlockBaseTest): Will trigger an assert if detection mechanism did not work as expected. """ - self.username_check(['noonewouldeverusethis7'], - ["Dribbble" - ], - exist_check=False - ) + self.detect_type_check("message", exist_check=False) return @@ -227,10 +223,6 @@ class SherlockSiteCoverageTests(SherlockBaseTest): Will trigger an assert if detection mechanism did not work as expected. """ - self.username_check(['blue'], - ["Dribbble" - ], - exist_check=True - ) + self.detect_type_check("message", exist_check=True) return diff --git a/tests/base.py b/tests/base.py index 0f992ba8..e17d8c8d 100644 --- a/tests/base.py +++ b/tests/base.py @@ -105,3 +105,50 @@ class SherlockBaseTest(unittest.TestCase): self.assertEqual(result['exists'], exist_result_desired) return + + def detect_type_check(self, detect_type, exist_check=True): + """Username Exist Check. + + Keyword Arguments: + self -- This object. + detect_type -- String corresponding to detection algorithm + which is desired to be tested. + Note that only sites which have documented + usernames which exist and do not exist + will be tested. + exist_check -- Boolean which indicates if this should be + a check for Username existence, + or non-existence. + + Return Value: + N/A. + Runs tests on all sites using the indicated detection algorithm + and which also has test vectors specified. + Will trigger an assert if Username does not have the expected + existence state. + """ + + for site, site_data in self.site_data_all.items(): + if ( + (site_data["errorType"] != detect_type) or + (site_data.get("username_claimed") is None) or + (site_data.get("username_unclaimed") is None) + ): + # This is either not a site we are interested in, or the + # site does not contain the required information to do + # the tests. + pass + else: + # We should run a test on this site. + + # Figure out which type of user + if exist_check: + username_list = [site_data.get("username_claimed")] + else: + username_list = [site_data.get("username_unclaimed")] + self.username_check(username_list, + [site], + exist_check=exist_check + ) + + return