def test_get_commit_date():
    """Test _get_commit_date."""
    gh = GithubUtils()
    dt = gh._get_commit_date("kubernetes", "kubernetes", "v1.19.1")
    assert dt == "2020-09-09T11:17:20Z"

    dt = gh._get_commit_date("kubernetes", "kubernetes", "0d4799964558b1e96587737613d6e79e1679cb82")
    assert dt == "2020-09-17T13:19:13Z"

    dt = gh._get_commit_date("kubernetes", "kubernetes", "95b5b7d61338aa0f4c601e820e1d8f3e45696bbc")
    assert dt == "2020-09-09T11:17:20Z"
 def _set_commit_hash_rules(self, data, gh_link):
     """To set the commit hash rules."""
     hashes_range = data['hashesRange']
     # If there is no range, it means all commits are vulnerable.
     if not hashes_range:
         data['commitRules'] = '*'
         return data
     gh = GithubUtils()
     # This is needed to get the org and name from the gh link.
     gh_splitted = gh_link.split("/")
     length = len(gh_splitted)
     org = gh_splitted[length - 2]
     name = gh_splitted[length - 1]
     regex_vr = "[<>=*]+"
     regex_op = "[0-9a-zA-Z\\_\\.\\-]+"
     rules = ""
     for range in hashes_range:
         # Remove any blank spaces.
         range = range.replace(" ", "")
         operands = re.split(regex_vr, range)
         operators = re.split(regex_op, range)
         if len(operators) == 2 and len(operands) == 2:
             # It means there is only 1 condition.
             date = gh._get_commit_date(
                 org, name, self.__format_golang_version(operands[1]))
             if date:
                 rules = rules + operators[0] + "#" + date + ","
             else:
                 logger.error(
                     "No such data present on Github. Contact Snyk.")
         elif len(operators) == 3 and len(operands) == 3:
             # It means there is a nesting. Ex >x & <y.
             date1 = gh._get_commit_date(
                 org, name, self.__format_golang_version(operands[1]))
             date2 = gh._get_commit_date(
                 org, name, self.__format_golang_version(operands[2]))
             if date1 and date2:
                 rules = rules + operators[0] + "#" + date1 +\
                         "&" + operators[1] + "#" + date2 + ","
             else:
                 logger.error(
                     "No such data present on Github. Contact Snyk.")
         else:
             logger.error("Incorrect hashesRange data. Contact Snyk.")
     # Remove extra , which is get appended.
     if rules:
         rules = rules[:-1]
     data['commitRules'] = rules
     return data