def test_delete_automated_issue_comments(self):
        comments = [
            { 'id': 1, 'user': { 'login': '******' } },
            { 'id': 2, 'user': { 'login': '******' } },
            { 'id': 3, 'user': { 'login': '******' } },
        ]
        r = github_api.delete_automated_issue_comments('drifty', 'ionic', 1, comments=comments, is_debug=True, automated_login='******')
        self.assertEquals(r.get('deleted_automated_issue_comments'), 1)

        comments = [
            { 'id': 1, 'user': { 'login': '******' } },
            { 'id': 2, 'user': { 'login': '******' } },
            { 'id': 3, 'user': { 'login': '******' } },
        ]
        r = github_api.delete_automated_issue_comments('drifty', 'ionic', 1, comments=comments, is_debug=True, automated_login='******')
        self.assertEquals(r.get('deleted_automated_issue_comments'), 2)

        comments = [
            { 'user': { 'login': '******' } },
            { 'id': 2 },
            { 'id': 3, 'user': { 'login': '******' } },
        ]
        r = github_api.delete_automated_issue_comments('drifty', 'ionic', 1, comments=comments, is_debug=True, automated_login='******')
        self.assertEquals(r.get('deleted_automated_issue_comments'), 0)

        comments = []
        r = github_api.delete_automated_issue_comments('drifty', 'ionic', 1, comments=comments, is_debug=True, automated_login='******')
        self.assertEquals(r.get('deleted_automated_issue_comments'), 0)
def remove_flag_if_submitted_through_github(repo_username, repo_id, issue, issue_comments=None, is_debug=cvar["DEBUG"]):
    """
    Removes the notice flag (automated comments and label) if the issue has been
    resubmitted through the custom form on the Ionic site.
    @param issueNum: the issue number that should be refreshed (string)
    @return: whether or not the flag was removed (bool)
    """

    if not issue:
        return False

    number = issue.get("number")
    if not number:
        return False

    if not has_content_from_custom_submit_form(issue):
        return False

    if not has_needs_resubmit_content_id(repo_username, repo_id, issue, issue_comments=issue_comments):
        return False

    if not is_debug:
        github_api.delete_automated_issue_comments(repo_username, repo_id, number)

    return True
def remove_flag_if_not_updated(repo_username, repo_id, issue, issue_comments=None, needs_resubmit_content_id=cvar['NEEDS_RESUBMIT_CONTENT_ID'], remove_form_resubmit_comment_after=cvar['REMOVE_FORM_RESUBMIT_COMMENT_AFTER'], now=datetime.now(), is_debug=cvar['DEBUG']):
    if not issue:
        return False

    number = issue.get('number')
    if not number:
        return False

    if has_content_from_custom_submit_form(issue):
        return False

    comment = get_needs_resubmit_comment(repo_username, repo_id, issue, issue_comments=issue_comments, needs_resubmit_content_id=needs_resubmit_content_id)
    if comment is None:
        return False

    created_at = util.get_date(comment.get('created_at'))
    if created_at is None:
        return False

    remove_date = created_at + timedelta(days=remove_form_resubmit_comment_after)
    if remove_date > now:
        return False

    if not is_debug:
        github_api.delete_automated_issue_comments(repo_username, repo_id, number)

    return True