def test_bugzilla_comment_length_capped(test_project, eleven_jobs_stored):
    """
    Test that the total number of characters in the comment is capped correctly.
    """
    bug_id = 12345678
    job_id = 1
    who = "*****@*****.**"

    # Create an error line with length equal to the max comment length.
    # Once the job metadata has been added, the total comment length
    # will exceed the max length, unless correctly truncated.
    bug_suggestions = [{"search": "a" * settings.BZ_MAX_COMMENT_LENGTH,
                        "search_terms": [],
                        "bugs": []
                        }]

    bug_suggestions_placeholders = [
        job_id, 'Bug suggestions',
        'json', json.dumps(bug_suggestions),
        job_id, 'Bug suggestions',
    ]

    with ArtifactsModel(test_project) as artifacts_model:
        artifacts_model.store_job_artifact([bug_suggestions_placeholders])
    req = BugzillaCommentRequest(test_project, job_id, bug_id, who)
    req.generate_request_body()

    assert len(req.body['comment']) == settings.BZ_MAX_COMMENT_LENGTH
def test_bugzilla_comment_length_capped(test_project, eleven_jobs_stored):
    """
    Test that the total number of characters in the comment is capped correctly.
    """
    bug_id = 12345678
    job_id = 1
    who = "*****@*****.**"

    # Create an error line with length equal to the max comment length.
    # Once the job metadata has been added, the total comment length
    # will exceed the max length, unless correctly truncated.
    bug_suggestions = [{
        "search": "a" * settings.BZ_MAX_COMMENT_LENGTH,
        "search_terms": [],
        "bugs": []
    }]

    bug_suggestions_placeholders = [
        job_id,
        'Bug suggestions',
        'json',
        json.dumps(bug_suggestions),
        job_id,
        'Bug suggestions',
    ]

    with ArtifactsModel(test_project) as artifacts_model:
        artifacts_model.store_job_artifact([bug_suggestions_placeholders])
    req = BugzillaCommentRequest(test_project, job_id, bug_id, who)
    req.generate_request_body()

    assert len(req.body['comment']) == settings.BZ_MAX_COMMENT_LENGTH
def test_bugzilla_comment_request_body(jm, eleven_jobs_processed):
    """
    Test the request body is created correctly
    """
    bug_id = 12345678
    job_id = 1
    who = "*****@*****.**"

    bug_suggestions = []
    bug_suggestions.append({"search": "First error line", "search_terms": [], "bugs": []})
    bug_suggestions.append({"search": "Second error line", "search_terms": [], "bugs": []})

    bug_suggestions_placeholders = [
        job_id, 'Bug suggestions',
        'json', json.dumps(bug_suggestions),
        job_id, 'Bug suggestions',
    ]

    jm.store_job_artifact([bug_suggestions_placeholders])
    req = BugzillaCommentRequest(jm.project, job_id, bug_id, who)
    req.generate_request_body()

    expected = {
        'comment': (u'log: http://local.treeherder.mozilla.org/'
                    u'logviewer.html#?repo=test_treeherder&job_id=1\n'
                    u'repository: test_treeherder\n'
                    u'start_time: 2013-11-13T06:39:13\n'
                    u'who: user[at]mozilla[dot]com\n'
                    u'machine: bld-linux64-ec2-132\n'
                    u'revision: cdfe03e77e66\n\n'
                    u'First error line\n'
                    u'Second error line')
    }
    assert req.body == expected
def submit_bugzilla_comment(project, job_id, bug_id, who):
    """
    Send a post request to Bugzilla's REST API to add a new comment to the associated bug.
    In the future this will be removed in favour of periodic (eg once a week) summary comments
    on intermittent failure bugs, made by OrangeFactor v2 or similar.
    """
    try:
        req = BugzillaCommentRequest(project, job_id, bug_id, who)
        req.generate_request_body()
        req.send_request()
    except Exception as e:
        # Initially retry after 1 minute, then for each subsequent retry
        # lengthen the retry time by another minute.
        submit_bugzilla_comment.retry(exc=e, countdown=(1 + submit_bugzilla_comment.request.retries) * 60)
        # this exception will be raised once the number of retries
        # exceeds max_retries
        raise
Esempio n. 5
0
def submit_bugzilla_comment(project, job_id, bug_id, who):
    """
    Send a post request to Bugzilla's REST API to add a new comment to the associated bug.
    In the future this will be removed in favour of periodic (eg once a week) summary comments
    on intermittent failure bugs, made by OrangeFactor v2 or similar.
    """
    try:
        req = BugzillaCommentRequest(project, job_id, bug_id, who)
        req.generate_request_body()
        req.send_request()
    except Exception as e:
        # Initially retry after 1 minute, then for each subsequent retry
        # lengthen the retry time by another minute.
        submit_bugzilla_comment.retry(
            exc=e,
            countdown=(1 + submit_bugzilla_comment.request.retries) * 60)
        # this exception will be raised once the number of retries
        # exceeds max_retries
        raise