def test_an_exception_is_raised_when_we_hit_an_error():
    responses.add(responses.GET, rest_url('bug', 1017315),
                      body="It's all broken", status=500,
                      content_type='application/json', match_querystring=True)
    bugzilla = Bugsy()
    with pytest.raises(BugsyException) as e:
        bugzilla.get(1017315)
    assert str(e.value) == "Message: We received a 500 error with the following: It's all broken"
Exemplo n.º 2
0
def test_an_exception_is_raised_when_we_hit_an_error():
    responses.add(responses.GET,
                  rest_url('bug', 1017315),
                  body="It's all broken",
                  status=500,
                  content_type='application/json',
                  match_querystring=True)
    bugzilla = Bugsy()
    with pytest.raises(BugsyException) as e:
        bugzilla.get(1017315)
    assert str(
        e.value
    ) == "Message: We received a 500 error with the following: It's all broken Code: None"
Exemplo n.º 3
0
def test_bugsyexception_raised_for_http_500_when_commenting_on_a_bug(
        bug_return):
    responses.add(responses.GET,
                  'https://bugzilla.mozilla.org/rest/login',
                  body='{"token": "foobar"}',
                  status=200,
                  content_type='application/json',
                  match_querystring=True)
    responses.add(responses.GET,
                  rest_url('bug', 1017315),
                  body=json.dumps(bug_return),
                  status=200,
                  content_type='application/json',
                  match_querystring=True)
    bugzilla = Bugsy("foo", "bar")
    bug = bugzilla.get(1017315)

    responses.add(responses.POST,
                  'https://bugzilla.mozilla.org/rest/bug/1017315/comment',
                  body='Internal Server Error',
                  status=500,
                  content_type='text/html',
                  match_querystring=True)
    with pytest.raises(BugsyException) as e:
        bug.add_comment("I like sausages")
    assert str(
        e.value
    ) == "Message: We received a 500 error with the following: Internal Server Error Code: None"
Exemplo n.º 4
0
def test_we_can_update_a_bug_from_bugzilla():
    responses.add(
        responses.GET,
        rest_url("bug", 1017315),
        body=json.dumps(example_return),
        status=200,
        content_type="application/json",
        match_querystring=True,
    )
    bugzilla = Bugsy()
    bug = bugzilla.get(1017315)
    import copy

    bug_dict = copy.deepcopy(example_return)
    bug_dict["bugs"][0]["status"] = "REOPENED"
    responses.reset()
    responses.add(
        responses.GET,
        "https://bugzilla.mozilla.org/rest/bug/1017315",
        body=json.dumps(bug_dict),
        status=200,
        content_type="application/json",
    )
    bug.update()
    assert bug.status == "REOPENED"
Exemplo n.º 5
0
def test_we_can_update_a_bug_with_login_token():
    responses.add(
        responses.GET,
        'https://bugzilla.mozilla.org/rest/login?login=foo&password=bar',
        body='{"token": "foobar"}',
        status=200,
        content_type='application/json',
        match_querystring=True)

    responses.add(
        responses.GET,
        'https://bugzilla.mozilla.org/rest/bug/1017315?token=foobar&include_fields=version&include_fields=id&include_fields=summary&include_fields=status&include_fields=op_sys&include_fields=resolution&include_fields=product&include_fields=component&include_fields=platform',
        body=json.dumps(example_return),
        status=200,
        content_type='application/json',
        match_querystring=True)
    bugzilla = Bugsy("foo", "bar")
    bug = bugzilla.get(1017315)
    import copy
    bug_dict = copy.deepcopy(example_return)
    bug_dict['bugs'][0]['status'] = "REOPENED"
    responses.reset()
    responses.add(responses.GET,
                  'https://bugzilla.mozilla.org/rest/bug/1017315?token=foobar',
                  body=json.dumps(bug_dict),
                  status=200,
                  content_type='application/json',
                  match_querystring=True)
    bug.update()
    assert bug.id == 1017315
    assert bug.status == 'REOPENED'
    assert bug.summary == 'Schedule Mn tests on opt Linux builds on cedar'
Exemplo n.º 6
0
def test_comment_retrieval():
    responses.add(responses.GET,
                  'https://bugzilla.mozilla.org/rest/login',
                  body='{"token": "foobar"}',
                  status=200,
                  content_type='application/json',
                  match_querystring=True)
    responses.add(responses.GET,
                  rest_url('bug', 1017315),
                  body=json.dumps(example_return),
                  status=200,
                  content_type='application/json',
                  match_querystring=True)
    responses.add(responses.GET,
                  'https://bugzilla.mozilla.org/rest/bug/1017315/comment',
                  body=json.dumps(comments_return),
                  status=200,
                  content_type='application/json',
                  match_querystring=True)

    bugzilla = Bugsy("foo", "bar")
    bug = bugzilla.get(1017315)
    comments = bug.get_comments()
    assert len(comments) == 2
    c1 = comments[0]
    assert c1.attachment_id is None
    assert c1.author == u'*****@*****.**'
    assert c1.bug_id == 1017315
    assert c1.creation_time == datetime.datetime(2014, 3, 27, 23, 47, 45)
    assert c1.creator == u'*****@*****.**'
    assert c1.id == 8589785
    assert c1.is_private is False
    assert c1.text == u'text 1'
    assert c1.tags == set([u'tag1', u'tag2'])
    assert c1.time == datetime.datetime(2014, 3, 27, 23, 47, 45)
Exemplo n.º 7
0
def test_comment_retrieval():
    responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/login?login=foo&password=bar',
                        body='{"token": "foobar"}', status=200,
                        content_type='application/json', match_querystring=True)
    responses.add(responses.GET, rest_url('bug', 1017315, token='foobar'),
                      body=json.dumps(example_return), status=200,
                      content_type='application/json', match_querystring=True)
    responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/bug/1017315/comment?token=foobar',
                    body=json.dumps(comments_return), status=200,
                    content_type='application/json', match_querystring=True)

    bugzilla = Bugsy("foo", "bar")
    bug = bugzilla.get(1017315)
    comments = bug.get_comments()
    assert len(comments) == 2
    c1 = comments[0]
    assert c1.attachment_id is None
    assert c1.author == u'*****@*****.**'
    assert c1.bug_id == 1017315
    assert c1.creation_time == datetime.datetime(2014, 03, 27, 23, 47, 45)
    assert c1.creator == u'*****@*****.**'
    assert c1.id == 8589785
    assert c1.is_private is False
    assert c1.text == u'text 1'
    assert c1.tags == set([u'tag1', u'tag2'])
    assert c1.time == datetime.datetime(2014, 03, 27, 23, 47, 45)
Exemplo n.º 8
0
def test_we_can_update_a_bug_with_login_token():
    responses.add(responses.GET,
                  'https://bugzilla.mozilla.org/rest/login',
                  body='{"token": "foobar"}',
                  status=200,
                  content_type='application/json',
                  match_querystring=True)

    responses.add(responses.GET,
                  rest_url('bug', 1017315),
                  body=json.dumps(example_return),
                  status=200,
                  content_type='application/json',
                  match_querystring=True)
    bugzilla = Bugsy("foo", "bar")
    bug = bugzilla.get(1017315)
    import copy
    bug_dict = copy.deepcopy(example_return)
    bug_dict['bugs'][0]['status'] = "REOPENED"
    responses.reset()
    responses.add(responses.GET,
                  'https://bugzilla.mozilla.org/rest/bug/1017315',
                  body=json.dumps(bug_dict),
                  status=200,
                  content_type='application/json',
                  match_querystring=True)
    bug.update()
    assert bug.id == 1017315
    assert bug.status == 'REOPENED'
    assert bug.summary == 'Schedule Mn tests on opt Linux builds on cedar'
Exemplo n.º 9
0
def test_add_attachment(attachment_return, bug_return):
    responses.add(responses.GET,
                  'https://bugzilla.mozilla.org/rest/login',
                  body='{"token": "foobar"}',
                  status=200,
                  content_type='application/json',
                  match_querystring=True)
    responses.add(responses.GET,
                  rest_url('bug', 1017315),
                  json=bug_return,
                  status=200,
                  content_type='application/json',
                  match_querystring=True)
    responses.add(responses.POST,
                  'https://bugzilla.mozilla.org/rest/bug/1017315/attachment',
                  json=attachment_return,
                  status=200,
                  content_type='application/json',
                  match_querystring=True)

    bugzilla = Bugsy("foo", "bar")
    bug = bugzilla.get(1017315)
    attachment = Attachment(bugzilla,
                            **attachment_return['bugs']['1017315'][0])
    bug.add_attachment(attachment)

    assert len(responses.calls) == 3
Exemplo n.º 10
0
def test_add_attachment_with_missing_required_fields(attachment_return,
                                                     bug_return):
    responses.add(responses.GET,
                  'https://bugzilla.mozilla.org/rest/login',
                  body='{"token": "foobar"}',
                  status=200,
                  content_type='application/json',
                  match_querystring=True)
    responses.add(responses.GET,
                  rest_url('bug', 1017315),
                  json=bug_return,
                  status=200,
                  content_type='application/json',
                  match_querystring=True)
    responses.add(responses.POST,
                  'https://bugzilla.mozilla.org/rest/bug/1017315/attachment',
                  json=attachment_return,
                  status=200,
                  content_type='application/json',
                  match_querystring=True)

    bugzilla = Bugsy("foo", "bar")
    bug = bugzilla.get(1017315)
    clone = copy.deepcopy(attachment_return['bugs']['1017315'][0])
    del clone['data']
    attachment = Attachment(bugzilla, **clone)

    try:
        bug.add_attachment(attachment)
        assert False, "Should have raised a BugException due to add without data"
    except BugException as e:
        assert str(
            e
        ) == "Message: Cannot add attachment without all required fields Code: None"
Exemplo n.º 11
0
def test_we_can_update_a_bug_with_login_token(bug_return):
    responses.add(responses.GET,
                  'https://bugzilla.mozilla.org/rest/login',
                  body='{"token": "foobar"}',
                  status=200,
                  content_type='application/json',
                  match_querystring=True)

    responses.add(responses.GET,
                  rest_url('bug', 1017315),
                  body=json.dumps(bug_return),
                  status=200,
                  content_type='application/json',
                  match_querystring=True)
    bugzilla = Bugsy()
    bug = bugzilla.get(1017315)
    responses.reset()
    responses.add(responses.GET,
                  'https://bugzilla.mozilla.org/rest/bug/1017315',
                  body=json.dumps(bug_return),
                  status=200,
                  content_type='application/json')
    clone = Bug(bugsy=bugzilla, **bug.to_dict())
    clone.status = 'NEW'
    clone.update()
    assert clone.id == 1017315
    assert clone.status == 'RESOLVED'
Exemplo n.º 12
0
def test_attachment_retrieval(attachment_return, bug_return):
    responses.add(responses.GET,
                  'https://bugzilla.mozilla.org/rest/login',
                  body='{"token": "foobar"}',
                  status=200,
                  content_type='application/json',
                  match_querystring=True)
    responses.add(responses.GET,
                  rest_url('bug', 1017315),
                  json=bug_return,
                  status=200,
                  content_type='application/json',
                  match_querystring=True)
    responses.add(responses.GET,
                  'https://bugzilla.mozilla.org/rest/bug/1017315/attachment',
                  json=attachment_return,
                  status=200,
                  content_type='application/json',
                  match_querystring=True)

    bugzilla = Bugsy("foo", "bar")
    bug = bugzilla.get(1017315)
    attachments = bug.get_attachments()
    assert len(attachments) == 1

    attachment = attachments[0].to_dict()
    for k, v in attachment.items():
        if k in ['creation_time', 'last_change_time']:
            orig = attachment_return['bugs']['1017315'][0][k]
            assert v == datetime.datetime.strptime(orig, '%Y-%m-%dT%H:%M:%SZ')
        else:
            orig = attachment_return['bugs']['1017315'][0][k]
            assert v == orig
Exemplo n.º 13
0
def test_that_we_can_add_a_comment_to_an_existing_bug():
    responses.add(
        responses.GET,
        "https://bugzilla.mozilla.org/rest/login?login=foo&password=bar",
        body='{"token": "foobar"}',
        status=200,
        content_type="application/json",
        match_querystring=True,
    )

    responses.add(
        responses.GET,
        rest_url("bug", 1017315, token="foobar"),
        body=json.dumps(example_return),
        status=200,
        content_type="application/json",
        match_querystring=True,
    )
    bugzilla = Bugsy("foo", "bar")
    bug = bugzilla.get(1017315)

    responses.add(
        responses.POST,
        "https://bugzilla.mozilla.org/rest/bug/1017315/comment?token=foobar",
        body=json.dumps({}),
        status=200,
        content_type="application/json",
        match_querystring=True,
    )

    bug.add_comment("I like sausages")

    assert len(responses.calls) == 3
Exemplo n.º 14
0
def test_that_we_can_add_a_comment_to_an_existing_bug():
    responses.add(responses.GET,
                  'https://bugzilla.mozilla.org/rest/login',
                  body='{"token": "foobar"}',
                  status=200,
                  content_type='application/json',
                  match_querystring=True)

    responses.add(responses.GET,
                  rest_url('bug', 1017315),
                  body=json.dumps(example_return),
                  status=200,
                  content_type='application/json',
                  match_querystring=True)
    bugzilla = Bugsy("foo", "bar")
    bug = bugzilla.get(1017315)

    responses.add(responses.POST,
                  'https://bugzilla.mozilla.org/rest/bug/1017315/comment',
                  body=json.dumps({}),
                  status=200,
                  content_type='application/json',
                  match_querystring=True)

    bug.add_comment("I like sausages")

    assert len(responses.calls) == 3
Exemplo n.º 15
0
def test_we_can_remove_tags_to_bug_comments():
    responses.add(responses.GET,
                  'https://bugzilla.mozilla.org/rest/login',
                  body='{"token": "foobar"}',
                  status=200,
                  content_type='application/json',
                  match_querystring=True)

    responses.add(responses.GET,
                  rest_url('bug', 1017315),
                  body=json.dumps(example_return),
                  status=200,
                  content_type='application/json',
                  match_querystring=True)
    bugzilla = Bugsy("foo", "bar")
    bug = bugzilla.get(1017315)

    responses.add(responses.GET,
                  'https://bugzilla.mozilla.org/rest/bug/1017315/comment',
                  body=json.dumps(comments_return),
                  status=200,
                  content_type='application/json',
                  match_querystring=True)

    comments = bug.get_comments()

    responses.add(responses.PUT,
                  'https://bugzilla.mozilla.org/rest/bug/comment/8589785/tags',
                  body=json.dumps(["spam", "foo"]),
                  status=200,
                  content_type='application/json',
                  match_querystring=True)
    comments[0].remove_tags("foo")

    assert len(responses.calls) == 4
Exemplo n.º 16
0
def test_that_we_can_add_a_comment_to_an_existing_bug():
    responses.add(
        responses.GET,
        'https://bugzilla.mozilla.org/rest/login?login=foo&password=bar',
        body='{"token": "foobar"}',
        status=200,
        content_type='application/json',
        match_querystring=True)

    responses.add(
        responses.GET,
        'https://bugzilla.mozilla.org/rest/bug/1017315?token=foobar&include_fields=version&include_fields=id&include_fields=summary&include_fields=status&include_fields=op_sys&include_fields=resolution&include_fields=product&include_fields=component&include_fields=platform',
        body=json.dumps(example_return),
        status=200,
        content_type='application/json',
        match_querystring=True)
    bugzilla = Bugsy("foo", "bar")
    bug = bugzilla.get(1017315)

    responses.add(
        responses.POST,
        'https://bugzilla.mozilla.org/rest/bug/1017315/comment?token=foobar',
        body=json.dumps({}),
        status=200,
        content_type='application/json',
        match_querystring=True)

    bug.add_comment("I like sausages")

    assert len(responses.calls) == 3
Exemplo n.º 17
0
def test_we_can_add_multiple_emails_to_cc_list():
    bug = None
    bugzilla = None
    with responses.RequestsMock() as rsps:
        rsps.add(responses.GET,
                 'https://bugzilla.mozilla.org/rest/login',
                 body='{"token": "foobar"}',
                 status=200,
                 content_type='application/json',
                 match_querystring=True)
        rsps.add(responses.GET,
                 rest_url('bug', 1017315),
                 body=json.dumps(example_return),
                 status=200,
                 content_type='application/json',
                 match_querystring=True)
        bugzilla = Bugsy("foo", "bar")
        bug = bugzilla.get(1017315)
    import copy
    bug_dict = copy.deepcopy(example_return)
    bug_dict['bugs'][0]['cc_detail'].append({
        u'id': 438921,
        u'email': u'*****@*****.**',
        u'name': u'[email protected] ',
        u'real_name': u'AutomatedTester'
    })
    bug_dict['bugs'][0]['cc_detail'].append({
        u'id': 438922,
        u'email': u'*****@*****.**',
        u'name': u'[email protected] ',
        u'real_name': u'Foobar'
    })

    updated_bug = None
    with responses.RequestsMock() as rsps:
        rsps.add(responses.PUT,
                 'https://bugzilla.mozilla.org/rest/bug/1017315',
                 body=json.dumps(bug_dict),
                 status=200,
                 content_type='application/json',
                 match_querystring=True)

        rsps.add(responses.GET,
                 rest_url('bug', 1017315),
                 body=json.dumps(bug_dict),
                 status=200,
                 content_type='application/json',
                 match_querystring=True)

        bug.cc = ["*****@*****.**", "*****@*****.**"]
        updated_bug = bugzilla.put(bug)

    cced = updated_bug.cc
    assert isinstance(cced, list)
    assert [
        u"*****@*****.**", u"*****@*****.**", u"*****@*****.**",
        u"*****@*****.**", u"*****@*****.**",
        u"*****@*****.**"
    ] == cced
def test_bugsyexception_raised_for_http_502_when_retrieving_bugs():
    responses.add(responses.GET, rest_url('bug', 123456),
                  body='Bad Gateway', status=502,
                  content_type='text/html', match_querystring=True)
    bugzilla = Bugsy()
    with pytest.raises(BugsyException) as e:
        r = bugzilla.get(123456)
    assert str(e.value) == "Message: We received a 502 error with the following: Bad Gateway"
Exemplo n.º 19
0
def test_we_can_get_a_bug():
    responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/bug/1017315',
                      body=json.dumps(example_return), status=200,
                      content_type='application/json', match_querystring=True)
    bugzilla = Bugsy()
    bug = bugzilla.get(1017315)
    assert bug.id == 1017315
    assert bug.status == 'RESOLVED'
    assert bug.summary == 'Schedule Mn tests on opt Linux builds on cedar'
Exemplo n.º 20
0
def test_we_can_get_a_bug():
    responses.add(responses.GET, rest_url('bug', 1017315),
                      body=json.dumps(example_return), status=200,
                      content_type='application/json', match_querystring=True)
    bugzilla = Bugsy()
    bug = bugzilla.get(1017315)
    assert bug.id == 1017315
    assert bug.status == 'RESOLVED'
    assert bug.summary == 'Schedule Mn tests on opt Linux builds on cedar'
Exemplo n.º 21
0
def test_we_can_get_a_bug():
    responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/bug/1017315?include_fields=version&include_fields=id&include_fields=summary&include_fields=status&include_fields=op_sys&include_fields=resolution&include_fields=product&include_fields=component&include_fields=platform',
                      body=json.dumps(example_return), status=200,
                      content_type='application/json', match_querystring=True)
    bugzilla = Bugsy()
    bug = bugzilla.get(1017315)
    assert bug.id == 1017315
    assert bug.status == 'RESOLVED'
    assert bug.summary == 'Schedule Mn tests on opt Linux builds on cedar'
Exemplo n.º 22
0
def test_we_can_remove_an_email_to_cc_list():
    bug = None
    bugzilla = None
    with responses.RequestsMock() as rsps:
        rsps.add(responses.GET,
                 'https://bugzilla.mozilla.org/rest/login',
                 body='{"token": "foobar"}',
                 status=200,
                 content_type='application/json',
                 match_querystring=True)
        rsps.add(responses.GET,
                 rest_url('bug', 1017315),
                 body=json.dumps(example_return),
                 status=200,
                 content_type='application/json',
                 match_querystring=True)

        bugzilla = Bugsy("foo", "bar")
        bug = bugzilla.get(1017315)
    import copy
    bug_dict = copy.deepcopy(example_return)
    bug_dict['bugs'][0]['cc_detail'].remove([
        person for person in bug_dict['bugs'][0]['cc_detail']
        if person['id'] == 397261
    ][0])
    bug_dict['bugs'][0]['cc_detail'].remove([
        person for person in bug_dict['bugs'][0]['cc_detail']
        if person['id'] == 418814
    ][0])

    updated_bug = None
    with responses.RequestsMock() as rsps:
        rsps.add(responses.PUT,
                 'https://bugzilla.mozilla.org/rest/bug/1017315',
                 body=json.dumps(bug_dict),
                 status=200,
                 content_type='application/json',
                 match_querystring=True)

        rsps.add(responses.GET,
                 rest_url('bug', 1017315),
                 body=json.dumps(bug_dict),
                 status=200,
                 content_type='application/json',
                 match_querystring=True)

        bug.cc = ["*****@*****.**", "[email protected]"]
        updated_bug = bugzilla.put(bug)

    cced = updated_bug.cc
    assert isinstance(cced, list)
    assert [u"*****@*****.**", u"*****@*****.**"] == cced
Exemplo n.º 23
0
def test_we_can_get_a_bug():
    responses.add(
        responses.GET,
        'https://bugzilla.mozilla.org/rest/bug/1017315?include_fields=version&include_fields=id&include_fields=summary&include_fields=status&include_fields=op_sys&include_fields=resolution&include_fields=product&include_fields=component&include_fields=platform',
        body=json.dumps(example_return),
        status=200,
        content_type='application/json',
        match_querystring=True)
    bugzilla = Bugsy()
    bug = bugzilla.get(1017315)
    assert bug.id == 1017315
    assert bug.status == 'RESOLVED'
    assert bug.summary == 'Schedule Mn tests on opt Linux builds on cedar'
Exemplo n.º 24
0
def test_we_can_get_a_bug_with_login_token(bug_return):
  responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/login',
                        body='{"token": "foobar"}', status=200,
                        content_type='application/json', match_querystring=True)
  responses.add(responses.GET, rest_url('bug', 1017315),
                body=json.dumps(bug_return), status=200,
                content_type='application/json', match_querystring=True)
  bugzilla = Bugsy("foo", "bar")
  bug = bugzilla.get(1017315)
  assert bug.id == 1017315
  assert bug.status == 'RESOLVED'
  assert bug.summary == 'Schedule Mn tests on opt Linux builds on cedar'
  assert responses.calls[1].request.headers['X-Bugzilla-Token'] == 'foobar'
Exemplo n.º 25
0
def test_we_can_get_a_bug_with_login_token():
  responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/login',
                        body='{"token": "foobar"}', status=200,
                        content_type='application/json', match_querystring=True)
  responses.add(responses.GET, rest_url('bug', 1017315),
                    body=json.dumps(example_return), status=200,
                    content_type='application/json', match_querystring=True)
  bugzilla = Bugsy("foo", "bar")
  bug = bugzilla.get(1017315)
  assert bug.id == 1017315
  assert bug.status == 'RESOLVED'
  assert bug.summary == 'Schedule Mn tests on opt Linux builds on cedar'
  assert responses.calls[1].request.headers['X-Bugzilla-Token'] == 'foobar'
Exemplo n.º 26
0
def test_bugsyexception_raised_for_http_502_when_retrieving_bugs():
    responses.add(responses.GET,
                  rest_url('bug', 123456),
                  body='Bad Gateway',
                  status=502,
                  content_type='text/html',
                  match_querystring=True)
    bugzilla = Bugsy()
    with pytest.raises(BugsyException) as e:
        r = bugzilla.get(123456)
    assert str(
        e.value
    ) == "Message: We received a 502 error with the following: Bad Gateway Code: None"
Exemplo n.º 27
0
def test_we_can_get_a_bug_with_login_token():
  responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/login?login=foo&password=bar',
                        body='{"token": "foobar"}', status=200,
                        content_type='application/json', match_querystring=True)

  responses.add(responses.GET, rest_url('bug', 1017315, token='foobar'),
                    body=json.dumps(example_return), status=200,
                    content_type='application/json', match_querystring=True)
  bugzilla = Bugsy("foo", "bar")
  bug = bugzilla.get(1017315)
  assert bug.id == 1017315
  assert bug.status == 'RESOLVED'
  assert bug.summary == 'Schedule Mn tests on opt Linux builds on cedar'
Exemplo n.º 28
0
def test_we_can_get_a_bug_with_login_token():
  responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/login?login=foo&password=bar',
                        body='{"token": "foobar"}', status=200,
                        content_type='application/json', match_querystring=True)

  responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/bug/1017315?token=foobar',
                    body=json.dumps(example_return), status=200,
                    content_type='application/json', match_querystring=True)
  bugzilla = Bugsy("foo", "bar")
  bug = bugzilla.get(1017315)
  assert bug.id == 1017315
  assert bug.status == 'RESOLVED'
  assert bug.summary == 'Schedule Mn tests on opt Linux builds on cedar'
Exemplo n.º 29
0
def test_we_can_update_a_bug_from_bugzilla():
    responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/bug/1017315?include_fields=version&include_fields=id&include_fields=summary&include_fields=status&include_fields=op_sys&include_fields=resolution&include_fields=product&include_fields=component&include_fields=platform',
                      body=json.dumps(example_return), status=200,
                      content_type='application/json', match_querystring=True)
    bugzilla = Bugsy()
    bug = bugzilla.get(1017315)
    import copy
    bug_dict = copy.deepcopy(example_return)
    bug_dict['bugs'][0]['status'] = "REOPENED"
    responses.reset()
    responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/bug/1017315',
                      body=json.dumps(bug_dict), status=200,
                      content_type='application/json')
    bug.update()
    assert bug.status == 'REOPENED'
Exemplo n.º 30
0
def test_we_can_update_a_bug_from_bugzilla():
    responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/bug/1017315',
                      body=json.dumps(example_return), status=200,
                      content_type='application/json', match_querystring=True)
    bugzilla = Bugsy()
    bug = bugzilla.get(1017315)
    import copy
    bug_dict = copy.deepcopy(example_return)
    bug_dict['bugs'][0]['status'] = "REOPENED"
    responses.reset()
    responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/bug/1017315',
                      body=json.dumps(bug_dict), status=200,
                      content_type='application/json')
    bug.update()
    assert bug.status == 'REOPENED'
def test_bugsyexception_raised_for_http_500_when_commenting_on_a_bug():
    responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/login?login=foo&password=bar',
                  body='{"token": "foobar"}', status=200,
                  content_type='application/json', match_querystring=True)
    responses.add(responses.GET, rest_url('bug', 1017315, token='foobar'),
                  body=json.dumps(example_return), status=200,
                  content_type='application/json', match_querystring=True)
    bugzilla = Bugsy("foo", "bar")
    bug = bugzilla.get(1017315)

    responses.add(responses.POST, 'https://bugzilla.mozilla.org/rest/bug/1017315/comment?token=foobar',
                      body='Internal Server Error', status=500,
                      content_type='text/html', match_querystring=True)
    with pytest.raises(BugsyException) as e:
        bug.add_comment("I like sausages")
    assert str(e.value) == "Message: We received a 500 error with the following: Internal Server Error"
Exemplo n.º 32
0
def test_that_we_can_add_a_comment_to_a_bug():
    responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/login?login=foo&password=bar',
                          body='{"token": "foobar"}', status=200,
                          content_type='application/json', match_querystring=True)

    responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/bug/1017315?token=foobar',
                      body=json.dumps(example_return), status=200,
                      content_type='application/json', match_querystring=True)
    bugzilla = Bugsy("foo", "bar")
    bug = bugzilla.get(1017315)
    bug.add_comment("I like sausages")

    responses.add(responses.POST, 'https://bugzilla.mozilla.org/rest/bug/1017315?token=foobar',
                      body=json.dumps(example_return), status=200,
                      content_type='application/json', match_querystring=True)
    bugzilla.put(bug)
Exemplo n.º 33
0
def test_we_can_add_multiple_keywords_to_list():
    bug = None
    bugzilla = None
    with responses.RequestsMock() as rsps:
        rsps.add(responses.GET,
                 'https://bugzilla.mozilla.org/rest/login',
                 body='{"token": "foobar"}',
                 status=200,
                 content_type='application/json',
                 match_querystring=True)
        rsps.add(responses.GET,
                 rest_url('bug', 1017315),
                 body=json.dumps(example_return),
                 status=200,
                 content_type='application/json',
                 match_querystring=True)
        bugzilla = Bugsy("foo", "bar")
        bug = bugzilla.get(1017315)
    import copy
    bug_dict = copy.deepcopy(example_return)
    bug_dict['bugs'][0]['keywords'].append("intermittent")
    bug_dict['bugs'][0]['keywords'].append("ateam-marionette-server")

    updated_bug = None
    with responses.RequestsMock() as rsps:
        rsps.add(responses.PUT,
                 'https://bugzilla.mozilla.org/rest/bug/1017315',
                 body=json.dumps(bug_dict),
                 status=200,
                 content_type='application/json',
                 match_querystring=True)

        rsps.add(responses.GET,
                 rest_url('bug', 1017315),
                 body=json.dumps(bug_dict),
                 status=200,
                 content_type='application/json',
                 match_querystring=True)

        bug.keywords = ["intermittent", "ateam-marionette-server"]
        updated_bug = bugzilla.put(bug)

    keywords = updated_bug.keywords
    assert isinstance(keywords, list)
    assert ["regression", "intermittent",
            "ateam-marionette-server"] == keywords
Exemplo n.º 34
0
def test_we_can_add_and_remove_blocks():
    bug = None
    bugzilla = None
    with responses.RequestsMock() as rsps:
        rsps.add(responses.GET,
                 'https://bugzilla.mozilla.org/rest/login',
                 body='{"token": "foobar"}',
                 status=200,
                 content_type='application/json',
                 match_querystring=True)
        rsps.add(responses.GET,
                 rest_url('bug', 1017315),
                 body=json.dumps(example_return),
                 status=200,
                 content_type='application/json',
                 match_querystring=True)

        bugzilla = Bugsy("foo", "bar")
        bug = bugzilla.get(1017315)
    import copy
    bug_dict = copy.deepcopy(example_return)
    bug_dict['bugs'][0]['blocks'].remove(654321)
    bug_dict['bugs'][0]['blocks'].append(145123)

    updated_bug = None
    with responses.RequestsMock() as rsps:
        rsps.add(responses.PUT,
                 'https://bugzilla.mozilla.org/rest/bug/1017315',
                 body=json.dumps(bug_dict),
                 status=200,
                 content_type='application/json',
                 match_querystring=True)

        rsps.add(responses.GET,
                 rest_url('bug', 1017315),
                 body=json.dumps(bug_dict),
                 status=200,
                 content_type='application/json',
                 match_querystring=True)

        bug.blocks = ["654321-", "145123"]
        updated_bug = bugzilla.put(bug)

    deps = updated_bug.blocks
    assert isinstance(deps, list)
    assert [145123] == deps
Exemplo n.º 35
0
def test_that_we_can_add_a_comment_to_an_existing_bug():
    responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/login?login=foo&password=bar',
                          body='{"token": "foobar"}', status=200,
                          content_type='application/json', match_querystring=True)

    responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/bug/1017315?token=foobar&include_fields=version&include_fields=id&include_fields=summary&include_fields=status&include_fields=op_sys&include_fields=resolution&include_fields=product&include_fields=component&include_fields=platform',
                      body=json.dumps(example_return), status=200,
                      content_type='application/json', match_querystring=True)
    bugzilla = Bugsy("foo", "bar")
    bug = bugzilla.get(1017315)

    responses.add(responses.POST, 'https://bugzilla.mozilla.org/rest/bug/1017315/comment?token=foobar',
                      body=json.dumps({}), status=200,
                      content_type='application/json', match_querystring=True)

    bug.add_comment("I like sausages")

    assert len(responses.calls) == 3
Exemplo n.º 36
0
def test_we_can_handle_errors_when_retrieving_bugs():
    error_response = {
    "code" : 101,
    "documentation" : "http://www.bugzilla.org/docs/tip/en/html/api/",
    "error" : True,
    "message" : "Bug 111111111111 does not exist."
    }
    responses.add(responses.GET, rest_url('bug', 111111111),
                      body=json.dumps(error_response), status=404,
                      content_type='application/json', match_querystring=True)
    bugzilla = Bugsy()
    try:
        bug = bugzilla.get(111111111)
        assert False, "A BugsyException should have been thrown"
    except BugsyException as e:
        assert str(e) == "Message: Bug 111111111111 does not exist. Code: 101"
    except Exception as e:
        assert False, "Wrong type of exception was thrown"
Exemplo n.º 37
0
def test_we_can_handle_errors_when_retrieving_bugs():
    error_response = {
    "code" : 101,
    "documentation" : "http://www.bugzilla.org/docs/tip/en/html/api/",
    "error" : True,
    "message" : "Bug 111111111111 does not exist."
    }
    responses.add(responses.GET, rest_url('bug', 111111111),
                      body=json.dumps(error_response), status=404,
                      content_type='application/json', match_querystring=True)
    bugzilla = Bugsy()
    try:
        bug = bugzilla.get(111111111)
        assert False, "A BugsyException should have been thrown"
    except BugsyException as e:
        assert str(e) == "Message: Bug 111111111111 does not exist."
    except Exception as e:
        assert False, "Wrong type of exception was thrown"
Exemplo n.º 38
0
def test_we_raise_an_exception_if_commenting_on_a_bug_that_returns_an_error():
    responses.add(
        responses.GET,
        "https://bugzilla.mozilla.org/rest/login?login=foo&password=bar",
        body='{"token": "foobar"}',
        status=200,
        content_type="application/json",
        match_querystring=True,
    )

    responses.add(
        responses.GET,
        rest_url("bug", 1017315, token="foobar"),
        body=json.dumps(example_return),
        status=200,
        content_type="application/json",
        match_querystring=True,
    )
    bugzilla = Bugsy("foo", "bar")
    bug = bugzilla.get(1017315)

    # will now return the following error. This could happen if the bug was open
    # when we did a `get()` but is now hidden
    error_response = {
        "code": 101,
        "message": "Bug 1017315 does not exist.",
        "documentation": "http://www.bugzilla.org/docs/tip/en/html/api/",
        "error": True,
    }
    responses.add(
        responses.POST,
        "https://bugzilla.mozilla.org/rest/bug/1017315/comment?token=foobar",
        body=json.dumps(error_response),
        status=404,
        content_type="application/json",
        match_querystring=True,
    )
    try:
        bug.add_comment("I like sausages")
        assert False, "Should have raised an BugException for the bug not existing"
    except BugsyException as e:
        assert str(e) == "Message: Bug 1017315 does not exist. Code: 101"

    assert len(responses.calls) == 3
Exemplo n.º 39
0
def test_we_can_remove_tags_to_bug_comments():
    responses.add(
        responses.GET,
        "https://bugzilla.mozilla.org/rest/login?login=foo&password=bar",
        body='{"token": "foobar"}',
        status=200,
        content_type="application/json",
        match_querystring=True,
    )

    responses.add(
        responses.GET,
        rest_url("bug", 1017315, token="foobar"),
        body=json.dumps(example_return),
        status=200,
        content_type="application/json",
        match_querystring=True,
    )
    bugzilla = Bugsy("foo", "bar")
    bug = bugzilla.get(1017315)

    responses.add(
        responses.GET,
        "https://bugzilla.mozilla.org/rest/bug/1017315/comment?token=foobar",
        body=json.dumps(comments_return),
        status=200,
        content_type="application/json",
        match_querystring=True,
    )

    comments = bug.get_comments()

    responses.add(
        responses.PUT,
        "https://bugzilla.mozilla.org/rest/bug/comment/8589785/tags?token=foobar",
        body=json.dumps(["spam", "foo"]),
        status=200,
        content_type="application/json",
        match_querystring=True,
    )
    comments[0].remove_tags("foo")

    assert len(responses.calls) == 4
Exemplo n.º 40
0
def test_we_can_update_a_bug_from_bugzilla():
    responses.add(responses.GET,
                  rest_url('bug', 1017315),
                  body=json.dumps(example_return),
                  status=200,
                  content_type='application/json',
                  match_querystring=True)
    bugzilla = Bugsy()
    bug = bugzilla.get(1017315)
    import copy
    bug_dict = copy.deepcopy(example_return)
    bug_dict['bugs'][0]['status'] = "REOPENED"
    responses.reset()
    responses.add(responses.GET,
                  'https://bugzilla.mozilla.org/rest/bug/1017315',
                  body=json.dumps(bug_dict),
                  status=200,
                  content_type='application/json')
    bug.update()
    assert bug.status == 'REOPENED'
Exemplo n.º 41
0
def test_we_raise_an_exception_when_getting_comments_and_bugzilla_errors():
    responses.add(
        responses.GET,
        "https://bugzilla.mozilla.org/rest/login?login=foo&password=bar",
        body='{"token": "foobar"}',
        status=200,
        content_type="application/json",
        match_querystring=True,
    )

    responses.add(
        responses.GET,
        rest_url("bug", 1017315, token="foobar"),
        body=json.dumps(example_return),
        status=200,
        content_type="application/json",
        match_querystring=True,
    )
    bugzilla = Bugsy("foo", "bar")
    bug = bugzilla.get(1017315)

    error_response = {
        "code": 67399,
        "message": "The requested method 'Bug.comments' was not found.",
        "documentation": u"http://www.bugzilla.org/docs/tip/en/html/api/",
        "error": True,
    }

    responses.add(
        responses.GET,
        "https://bugzilla.mozilla.org/rest/bug/1017315/comment?token=foobar",
        body=json.dumps(error_response),
        status=400,
        content_type="application/json",
        match_querystring=True,
    )
    try:
        comments = bug.get_comments()
        assert False, "Should have raised an BugException for the bug not existing"
    except BugsyException as e:
        assert str(e) == "Message: The requested method 'Bug.comments' was not found. Code: 67399"
Exemplo n.º 42
0
def test_we_can_update_a_bug_from_bugzilla():
    responses.add(
        responses.GET,
        'https://bugzilla.mozilla.org/rest/bug/1017315?include_fields=version&include_fields=id&include_fields=summary&include_fields=status&include_fields=op_sys&include_fields=resolution&include_fields=product&include_fields=component&include_fields=platform',
        body=json.dumps(example_return),
        status=200,
        content_type='application/json',
        match_querystring=True)
    bugzilla = Bugsy()
    bug = bugzilla.get(1017315)
    import copy
    bug_dict = copy.deepcopy(example_return)
    bug_dict['bugs'][0]['status'] = "REOPENED"
    responses.reset()
    responses.add(responses.GET,
                  'https://bugzilla.mozilla.org/rest/bug/1017315',
                  body=json.dumps(bug_dict),
                  status=200,
                  content_type='application/json')
    bug.update()
    assert bug.status == 'REOPENED'
Exemplo n.º 43
0
def test_we_can_update_a_bug_with_login_token():
  responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/login?login=foo&password=bar',
                        body='{"token": "foobar"}', status=200,
                        content_type='application/json', match_querystring=True)

  responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/bug/1017315?token=foobar',
                    body=json.dumps(example_return), status=200,
                    content_type='application/json', match_querystring=True)
  bugzilla = Bugsy("foo", "bar")
  bug = bugzilla.get(1017315)
  import copy
  bug_dict = copy.deepcopy(example_return)
  bug_dict['bugs'][0]['status'] = "REOPENED"
  responses.reset()
  responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/bug/1017315?token=foobar',
                    body=json.dumps(bug_dict), status=200,
                    content_type='application/json', match_querystring=True)
  bug.update()
  assert bug.id == 1017315
  assert bug.status == 'REOPENED'
  assert bug.summary == 'Schedule Mn tests on opt Linux builds on cedar'
Exemplo n.º 44
0
def test_bugsyexception_raised_for_http_500_when_adding_tags_to_bug_comments():
    responses.add(
        responses.GET,
        'https://bugzilla.mozilla.org/rest/login?login=foo&password=bar',
        body='{"token": "foobar"}',
        status=200,
        content_type='application/json',
        match_querystring=True)

    responses.add(responses.GET,
                  rest_url('bug', 1017315, token='foobar'),
                  body=json.dumps(example_return),
                  status=200,
                  content_type='application/json',
                  match_querystring=True)
    bugzilla = Bugsy("foo", "bar")
    bug = bugzilla.get(1017315)

    responses.add(
        responses.GET,
        'https://bugzilla.mozilla.org/rest/bug/1017315/comment?token=foobar',
        body=json.dumps(comments_return),
        status=200,
        content_type='application/json',
        match_querystring=True)

    comments = bug.get_comments()

    responses.add(
        responses.PUT,
        'https://bugzilla.mozilla.org/rest/bug/comment/8589785/tags?token=foobar',
        body='Internal Server Error',
        status=500,
        content_type='text/html',
        match_querystring=True)
    with pytest.raises(BugsyException) as e:
        comments[0].add_tags("foo")
    assert str(
        e.value
    ) == "Message: We received a 500 error with the following: Internal Server Error Code: None"
Exemplo n.º 45
0
def test_we_raise_an_exception_if_commenting_on_a_bug_that_returns_an_error():
    responses.add(
        responses.GET,
        'https://bugzilla.mozilla.org/rest/login?login=foo&password=bar',
        body='{"token": "foobar"}',
        status=200,
        content_type='application/json',
        match_querystring=True)

    responses.add(responses.GET,
                  rest_url('bug', 1017315, token='foobar'),
                  body=json.dumps(example_return),
                  status=200,
                  content_type='application/json',
                  match_querystring=True)
    bugzilla = Bugsy("foo", "bar")
    bug = bugzilla.get(1017315)

    # will now return the following error. This could happen if the bug was open
    # when we did a `get()` but is now hidden
    error_response = {
        'code': 101,
        'message': 'Bug 1017315 does not exist.',
        'documentation': 'http://www.bugzilla.org/docs/tip/en/html/api/',
        'error': True
    }
    responses.add(
        responses.POST,
        'https://bugzilla.mozilla.org/rest/bug/1017315/comment?token=foobar',
        body=json.dumps(error_response),
        status=404,
        content_type='application/json',
        match_querystring=True)
    try:
        bug.add_comment("I like sausages")
        assert False, "Should have raised an BugException for the bug not existing"
    except BugsyException as e:
        assert str(e) == "Message: Bug 1017315 does not exist. Code: 101"

    assert len(responses.calls) == 3
Exemplo n.º 46
0
def test_we_raise_an_exception_when_getting_comments_and_bugzilla_errors():
    responses.add(
        responses.GET,
        'https://bugzilla.mozilla.org/rest/login?login=foo&password=bar',
        body='{"token": "foobar"}',
        status=200,
        content_type='application/json',
        match_querystring=True)

    responses.add(responses.GET,
                  rest_url('bug', 1017315, token='foobar'),
                  body=json.dumps(example_return),
                  status=200,
                  content_type='application/json',
                  match_querystring=True)
    bugzilla = Bugsy("foo", "bar")
    bug = bugzilla.get(1017315)

    error_response = {
        'code': 67399,
        'message': "The requested method 'Bug.comments' was not found.",
        'documentation': u'http://www.bugzilla.org/docs/tip/en/html/api/',
        'error': True
    }

    responses.add(
        responses.GET,
        'https://bugzilla.mozilla.org/rest/bug/1017315/comment?token=foobar',
        body=json.dumps(error_response),
        status=400,
        content_type='application/json',
        match_querystring=True)
    try:
        comments = bug.get_comments()
        assert False, "Should have raised an BugException for the bug not existing"
    except BugsyException as e:
        assert str(
            e
        ) == "Message: The requested method 'Bug.comments' was not found. Code: 67399"
Exemplo n.º 47
0
def test_comment_retrieval():
    responses.add(
        responses.GET,
        'https://bugzilla.mozilla.org/rest/login?login=foo&password=bar',
        body='{"token": "foobar"}',
        status=200,
        content_type='application/json',
        match_querystring=True)
    responses.add(
        responses.GET,
        'https://bugzilla.mozilla.org/rest/bug/1017315?token=foobar&include_fields=version&include_fields=id&include_fields=summary&include_fields=status&include_fields=op_sys&include_fields=resolution&include_fields=product&include_fields=component&include_fields=platform',
        body=json.dumps(example_return),
        status=200,
        content_type='application/json',
        match_querystring=True)
    responses.add(
        responses.GET,
        'https://bugzilla.mozilla.org/rest/bug/1017315/comment?token=foobar',
        body=json.dumps(comments_return),
        status=200,
        content_type='application/json',
        match_querystring=True)

    bugzilla = Bugsy("foo", "bar")
    bug = bugzilla.get(1017315)
    comments = bug.get_comments()
    assert len(comments) == 2
    c1 = comments[0]
    assert c1.attachment_id is None
    assert c1.author == u'*****@*****.**'
    assert c1.bug_id == 1017315
    assert c1.creation_time == datetime.datetime(2014, 03, 27, 23, 47, 45)
    assert c1.creator == u'*****@*****.**'
    assert c1.id == 8589785
    assert c1.is_private is False
    assert c1.text == u'text 1'
    assert c1.tags == set([u'tag1', u'tag2'])
    assert c1.time == datetime.datetime(2014, 03, 27, 23, 47, 45)
Exemplo n.º 48
0
def wrappedpushbookmark(orig, pushop):
    result = orig(pushop)

    # pushop.ret was renamed to pushop.cgresult in Mercurial 3.2. We can drop
    # this branch once we drop <3.2 support.
    if hasattr(pushop, 'cgresult'):
        origresult = pushop.cgresult
    else:
        origresult = pushop.ret

    # Don't do anything if error from push.
    if not origresult:
        return result

    remoteurl = pushop.remote.url()
    tree = repository.resolve_uri_to_tree(remoteurl)
    # We don't support release trees (yet) because they have special flags
    # that need to get updated.
    if tree and tree in repository.RELEASE_TREES:
        return result

    ui = pushop.ui
    if tree and tree in ui.configlist('bzpost', 'excludetrees', default=[]):
        return result

    if tree:
        baseuri = repository.resolve_trees_to_uris([tree])[0][1].encode('utf-8')
        assert baseuri
    else:
        # This isn't a known Firefox tree. Fall back to resolving URLs by
        # hostname.

        # Only attend Mozilla's server.
        if not updateunknown(remoteurl, repository.BASE_WRITE_URI, ui):
            return result

        baseuri = remoteurl.replace(repository.BASE_WRITE_URI, repository.BASE_READ_URI).rstrip('/')

    bugsmap = {}
    lastbug = None
    lastnode = None

    for node in pushop.outgoing.missing:
        ctx = pushop.repo[node]

        # Don't do merge commits.
        if len(ctx.parents()) > 1:
            continue

        # Our bug parser is buggy for Gaia bump commit messages.
        if '<*****@*****.**>' in ctx.user():
            continue

        # Pushing to Try (and possibly other repos) could push unrelated
        # changesets that have been pushed to an official tree but aren't yet
        # on this specific remote. We use the phase information as a proxy
        # for "already pushed" and prune public changesets from consideration.
        if tree == 'try' and ctx.phase() == phases.public:
            continue

        bugs = parse_bugs(ctx.description())

        if not bugs:
            continue

        bugsmap.setdefault(bugs[0], []).append(ctx.hex()[0:12])
        lastbug = bugs[0]
        lastnode = ctx.hex()[0:12]

    if not bugsmap:
        return result

    bzauth = getbugzillaauth(ui)
    if not bzauth:
        return result

    bzurl = ui.config('bugzilla', 'url', 'https://bugzilla.mozilla.org/rest')

    bugsy = Bugsy(username=bzauth.username, password=bzauth.password,
                  userid=bzauth.userid, cookie=bzauth.cookie,
                  api_key=bzauth.apikey, bugzilla_url=bzurl)

    def public_url_for_bug(bug):
        '''Turn 123 into "https://bugzilla.mozilla.org/show_bug.cgi?id=123".'''
        public_baseurl = bzurl.replace('rest', '').rstrip('/')
        return '%s/show_bug.cgi?id=%s' % (public_baseurl, bug)

    # If this is a try push, we paste the Treeherder link for the tip commit, because
    # the per-commit URLs don't have much value.
    # TODO roll this into normal pushing so we get a Treeherder link in bugs as well.
    if tree == 'try' and lastbug:
        treeherderurl = repository.treeherder_url(tree, lastnode)

        bug = bugsy.get(lastbug)
        comments = bug.get_comments()
        for comment in comments:
            if treeherderurl in comment.text:
                return result

        ui.write(_('recording Treeherder push at %s\n') % public_url_for_bug(lastbug))
        bug.add_comment(treeherderurl)
        return result

    for bugnumber, nodes in bugsmap.items():
        bug = bugsy.get(bugnumber)

        comments = bug.get_comments()
        missing_nodes = []

        # When testing whether this changeset URL is referenced in a
        # comment, we only need to test for the node fragment. The
        # important side-effect is that each unique node for a changeset
        # is recorded in the bug.
        for node in nodes:
            if not any(node in comment.text for comment in comments):
                missing_nodes.append(node)

        if not missing_nodes:
            ui.write(_('bug %s already knows about pushed changesets\n') %
                     bugnumber)
            continue

        lines = []

        for node in missing_nodes:
            ctx = pushop.repo[node]
            lines.append('%s/rev/%s' % (baseuri, ctx.hex()))
            # description is using local encodings. Depending on the
            # configured encoding, replacement characters could be involved. We
            # use encoding.fromlocal() to get the raw bytes, which should be
            # valid UTF-8.
            lines.append(encoding.fromlocal(ctx.description()).splitlines()[0])
            lines.append('')

        comment = '\n'.join(lines)

        ui.write(_('recording push at %s\n') % public_url_for_bug(bugnumber))
        bug.add_comment(comment)

    return result
Exemplo n.º 49
0
def wrappedpushbookmark(orig, pushop):
    result = orig(pushop)

    # pushop.ret was renamed to pushop.cgresult in Mercurial 3.2. We can drop
    # this branch once we drop <3.2 support.
    if hasattr(pushop, 'cgresult'):
        origresult = pushop.cgresult
    else:
        origresult = pushop.ret

    # Don't do anything if error from push.
    if not origresult:
        return result

    remoteurl = pushop.remote.url()
    tree = repository.resolve_uri_to_tree(remoteurl)
    # We don't support release trees (yet) because they have special flags
    # that need to get updated.
    if tree and tree in repository.RELEASE_TREES:
        return result

    ui = pushop.ui
    if tree and tree in ui.configlist('bzpost', 'excludetrees', default=[]):
        return result

    if tree:
        baseuri = repository.resolve_trees_to_uris([tree
                                                    ])[0][1].encode('utf-8')
        assert baseuri
    else:
        # This isn't a known Firefox tree. Fall back to resolving URLs by
        # hostname.

        # Only attend Mozilla's server.
        if not updateunknown(remoteurl, repository.BASE_WRITE_URI, ui):
            return result

        baseuri = remoteurl.replace(repository.BASE_WRITE_URI,
                                    repository.BASE_READ_URI).rstrip('/')

    bugsmap = {}
    lastbug = None
    lastnode = None

    for node in pushop.outgoing.missing:
        ctx = pushop.repo[node]

        # Don't do merge commits.
        if len(ctx.parents()) > 1:
            continue

        # Our bug parser is buggy for Gaia bump commit messages.
        if '<*****@*****.**>' in ctx.user():
            continue

        # Pushing to Try (and possibly other repos) could push unrelated
        # changesets that have been pushed to an official tree but aren't yet
        # on this specific remote. We use the phase information as a proxy
        # for "already pushed" and prune public changesets from consideration.
        if tree == 'try' and ctx.phase() == phases.public:
            continue

        bugs = parse_bugs(ctx.description())

        if not bugs:
            continue

        bugsmap.setdefault(bugs[0], []).append(ctx.hex())
        lastbug = bugs[0]
        lastnode = ctx.hex()

    if not bugsmap:
        return result

    bzauth = getbugzillaauth(ui)
    if not bzauth:
        return result

    bzurl = ui.config('bugzilla', 'url', 'https://bugzilla.mozilla.org/rest')

    bugsy = Bugsy(username=bzauth.username,
                  password=bzauth.password,
                  userid=bzauth.userid,
                  cookie=bzauth.cookie,
                  api_key=bzauth.apikey,
                  bugzilla_url=bzurl)

    def public_url_for_bug(bug):
        '''Turn 123 into "https://bugzilla.mozilla.org/show_bug.cgi?id=123".'''
        public_baseurl = bzurl.replace('rest', '').rstrip('/')
        return '%s/show_bug.cgi?id=%s' % (public_baseurl, bug)

    # If this is a try push, we paste the Treeherder link for the tip commit, because
    # the per-commit URLs don't have much value.
    # TODO roll this into normal pushing so we get a Treeherder link in bugs as well.
    if tree == 'try' and lastbug:
        treeherderurl = repository.treeherder_url(tree, lastnode)

        bug = bugsy.get(lastbug)
        comments = bug.get_comments()
        for comment in comments:
            if treeherderurl in comment.text:
                return result

        ui.write(
            _('recording Treeherder push at %s\n') %
            public_url_for_bug(lastbug))
        bug.add_comment(treeherderurl)
        return result

    for bugnumber, nodes in bugsmap.items():
        bug = bugsy.get(bugnumber)

        comments = bug.get_comments()
        missing_nodes = []

        # When testing whether this changeset URL is referenced in a
        # comment, we only need to test for the node fragment. The
        # important side-effect is that each unique node for a changeset
        # is recorded in the bug.
        for node in nodes:
            if not any(node in comment.text for comment in comments):
                missing_nodes.append(node)

        if not missing_nodes:
            ui.write(
                _('bug %s already knows about pushed changesets\n') %
                bugnumber)
            continue

        lines = []

        for node in missing_nodes:
            ctx = pushop.repo[node]
            lines.append('%s/rev/%s' % (baseuri, ctx.hex()))
            # description is using local encodings. Depending on the
            # configured encoding, replacement characters could be involved. We
            # use encoding.fromlocal() to get the raw bytes, which should be
            # valid UTF-8.
            lines.append(encoding.fromlocal(ctx.description()).splitlines()[0])
            lines.append('')

        comment = '\n'.join(lines)

        ui.write(_('recording push at %s\n') % public_url_for_bug(bugnumber))
        bug.add_comment(comment)

    return result