def test_that_we_can_add_a_comment_to_a_bug_before_it_is_put(): 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, '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("foo", "bar") bug = Bug() bug.summary = "I like cheese" bug.add_comment("I like sausages") bug_dict = bug.to_dict().copy() bug_dict['id'] = 123123 responses.add(responses.POST, 'https://bugzilla.mozilla.org/rest/bug', body=json.dumps(bug_dict), status=200, content_type='application/json', match_querystring=True) bugzilla.put(bug)
def test_that_we_can_add_a_comment_to_a_bug_before_it_is_put(): 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 = Bug() bug.summary = "I like cheese" bug.add_comment("I like sausages") bug_dict = bug.to_dict().copy() bug_dict["id"] = 123123 responses.add( responses.POST, "https://bugzilla.mozilla.org/rest/bug?token=foobar", body=json.dumps(bug_dict), status=200, content_type="application/json", match_querystring=True, ) bugzilla.put(bug)
def test_we_can_put_a_current_bug(): responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/login', body='{"token": "foobar"}', status=200, content_type='application/json', match_querystring=True) bug_dict = example_return.copy() bug_dict['summary'] = 'I love foo but hate bar' responses.add(responses.PUT, 'https://bugzilla.mozilla.org/rest/bug/1017315', body=json.dumps(bug_dict), status=200, content_type='application/json') 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 = Bug(**example_return['bugs'][0]) bug.summary = 'I love foo but hate bar' bug.assigned_to = "*****@*****.**" bugzilla.put(bug) assert bug.summary == 'I love foo but hate bar' assert bug.assigned_to == "*****@*****.**"
def test_we_cant_post_without_a_username_or_password(): bugzilla = Bugsy() try: bugzilla.put("foo") assert 1 == 0, "Should have thrown when calling put" except BugsyException as e: assert str(e) == "Message: Unfortunately you can't put bugs in Bugzilla without credentials"
def test_bug_update_updates_copy_dict(bug_return, comments_return): responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/login', body='{"token": "foobar"}', status=200, content_type='application/json', match_querystring=True) bugzilla = Bugsy("foo", "bar") bug = Bug(bugzilla, **bug_return['bugs'][0]) bug.status = 'NEW' diff = bug.diff() bug_dict = copy.deepcopy(bug_return) bug_dict['bugs'][0]['status'] = 'NEW' responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/bug/1017315', body=json.dumps(bug_dict), status=200, content_type='application/json') responses.add(responses.PUT, 'https://bugzilla.mozilla.org/rest/bug/1017315', body=json.dumps(diff), status=200, content_type='application/json') bugzilla.put(bug) bug.update() assert bug._copy['status'] == 'NEW'
def test_we_cant_post_without_a_username_or_password(): bugzilla = Bugsy() try: bugzilla.put("foo") assert 1 == 0, "Should have thrown when calling put" except BugsyException as e: assert str(e) == "Message: Unfortunately you can't put bugs in Bugzilla without credentials Code: None"
def test_we_cant_post_without_passing_a_bug_object(): 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) bugzilla = Bugsy("foo", "bar") try: bugzilla.put("foo") assert 1 == 0, "Should have thrown an error about type when calling put" except BugsyException as e: assert str(e) == "Message: Please pass in a Bug object when posting to Bugzilla Code: None"
def test_we_cant_post_without_passing_a_bug_object(): 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) bugzilla = Bugsy("foo", "bar") try: bugzilla.put("foo") assert 1 == 0, "Should have thrown an error about type when calling put" except BugsyException as e: assert str(e) == "Message: Please pass in a Bug object when posting to Bugzilla"
def test_we_can_create_a_new_remote_bug(): bug = Bug() bug.summary = "I like foo" 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) bug_dict = bug.to_dict().copy() bug_dict['id'] = 123123 responses.add(responses.POST, 'https://bugzilla.mozilla.org/rest/bug', body=json.dumps(bug_dict), status=200, content_type='application/json') bugzilla = Bugsy("foo", "bar") bugzilla.put(bug) assert bug.id != None
def test_we_handle_errors_from_bugzilla_when_posting(): 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.POST, 'https://bugzilla.mozilla.org/rest/bug', body='{"error":true,"code":50,"message":"You must select/enter a component."}', status=400, content_type='application/json') bugzilla = Bugsy("foo", "bar") bug = Bug() try: bugzilla.put(bug) assert 1 == 0, "Put should have raised an error" except BugsyException as e: assert str(e) == "Message: You must select/enter a component. Code: 50"
def test_we_handle_errors_from_bugzilla_when_posting(): 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.POST, 'https://bugzilla.mozilla.org/rest/bug', body='{"error":true,"code":50,"message":"You must select/enter a component."}', status=200, content_type='application/json') bugzilla = Bugsy("foo", "bar") bug = Bug() try: bugzilla.put(bug) assert 1 == 0, "Put should have raised an error" except BugsyException as e: assert str(e) == "Message: You must select/enter a component."
def test_we_handle_errors_from_bugzilla_when_updating_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.POST, 'https://bugzilla.mozilla.org/rest/bug/1017315', body='{"error":true,"code":50,"message":"You must select/enter a component."}', status=200, content_type='application/json') bugzilla = Bugsy("foo", "bar") bug_dict = example_return.copy() bug_dict['summary'] = 'I love foo but hate bar' bug = Bug(**bug_dict['bugs'][0]) try: bugzilla.put(bug) except BugsyException as e: assert str(e) == "Message: You must select/enter a component."
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)
def test_we_handle_errors_from_bugzilla_when_updating_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.PUT, 'https://bugzilla.mozilla.org/rest/bug/1017315', body='{"error":true,"code":50,"message":"You must select/enter a component."}', status=400, content_type='application/json') bugzilla = Bugsy("foo", "bar") bug_dict = example_return.copy() bug_dict['summary'] = 'I love foo but hate bar' bug = Bug(**bug_dict['bugs'][0]) try: bugzilla.put(bug) except BugsyException as e: assert str(e) == "Message: You must select/enter a component. Code: 50"
def test_we_can_put_a_current_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) bug_dict = example_return.copy() bug_dict['summary'] = 'I love foo but hate bar' responses.add(responses.POST, 'https://bugzilla.mozilla.org/rest/bug/1017315', body=json.dumps(bug_dict), status=200, content_type='application/json') bugzilla = Bugsy("foo", "bar") bug = Bug(**example_return['bugs'][0]) bug.summary = 'I love foo but hate bar' bugzilla.put(bug) assert bug.summary == 'I love foo but hate bar'
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_we_can_put_a_current_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) bug_dict = example_return.copy() bug_dict['summary'] = 'I love foo but hate bar' responses.add(responses.POST, 'https://bugzilla.mozilla.org/rest/bug/1017315', body=json.dumps(bug_dict), status=200, content_type='application/json') bugzilla = Bugsy("foo", "bar") bug = Bug(**example_return['bugs'][0]) bug.summary = 'I love foo but hate bar' bugzilla.put(bug) assert bug.summary == 'I love foo but hate bar'
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
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
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