Пример #1
0
def test_post():
    ghr = BasicAuthRequester('user', 'pass')
    with mock.patch('requests.post') as g:
        g.return_value.status_code = 200
        payload = {"a": 2}
        ghr.post('url', payload)
        g.assert_called_with('url', data=json.dumps(payload), auth=mock.ANY)
Пример #2
0
def test_github_post():
    repo = 'imhotepbot/sacrificial-integration-tests'
    pr = 1
    test_str = 'integration test error name'
    req = BasicAuthRequester(ghu, ghp)
    r = PRReporter(req, repo, pr)
    r.report_line('da6a127a285ae08d9bfcccb1cb62aef908485769', 'foo.py', 2, 3, test_str)
    comments = req.get('https://api.github.com/repos/%s/pulls/%s/comments' %
                       (repo, pr)).json()
    posted = [x for x in comments if test_str in x['body']]

    try:
        assert len(posted) == 1
    finally:
        for comment in comments:
            req.delete('https://api.github.com/repos/%s/pulls/comments/%s' % (
                repo, comment['id']))
Пример #3
0
def test_github_post():
    repo = 'imhotepbot/sacrificial-integration-tests'
    pr = 1
    test_str = 'integration test error name'
    req = BasicAuthRequester(ghu, ghp)
    r = PRReporter(req, pr)
    r.report_line(repo, 'da6a127a285ae08d9bfcccb1cb62aef908485769', 'foo.py', 2, 3, test_str)
    comments = req.get('https://api.github.com/repos/%s/pulls/%s/comments' %
                       (repo, pr)).json()
    posted = [x for x in comments if test_str in x['body']]

    try:
        assert len(posted) == 1
    finally:
        for comment in comments:
            req.delete('https://api.github.com/repos/%s/pulls/comments/%s' % (
                repo, comment['id']))
Пример #4
0
def test_dont_post_duplicate_comments():
    repo = 'imhotepbot/sacrificial-integration-tests'
    pr = 1
    test_str = 'integration test error name'
    req = BasicAuthRequester(ghu, ghp)
    r = PRReporter(req, pr)
    args = [repo, 'da6a127a285ae08d9bfcccb1cb62aef908485769', 'foo.py', 2, 3, test_str]

    r.report_line(*args)
    r.report_line(*args)  # should dedupe.

    comment_url = 'https://api.github.com/repos/%s/pulls/%s/comments' % (
        repo, pr)
    comments = req.get(comment_url).json()
    posted = [x for x in comments if test_str in x['body']]

    try:
        assert len(posted) == 1
    finally:
        for comment in comments:
            req.delete('%s/%s' % (comment_url, comment['id']))
Пример #5
0
def test_dont_post_duplicate_comments():
    repo = 'imhotepbot/sacrificial-integration-tests'
    pr = 1
    test_str = 'integration test error name'
    req = BasicAuthRequester(ghu, ghp)
    r = PRReporter(req, repo, pr)
    args = [
        'da6a127a285ae08d9bfcccb1cb62aef908485769', 'foo.py', 2, 3, test_str
    ]

    r.report_line(*args)
    r.report_line(*args)  # should dedupe.

    comment_url = 'https://api.github.com/repos/%s/pulls/%s/comments' % (repo,
                                                                         pr)
    comments = req.get(comment_url).json()
    posted = [x for x in comments if test_str in x['body']]

    try:
        assert len(posted) == 1
    finally:
        for comment in comments:
            req.delete('%s/%s' % (comment_url, comment['id']))
Пример #6
0
def test_auth():
    ghr = BasicAuthRequester('user', 'pass')
    auth = ghr.get_auth()
    assert auth.username == 'user'
    assert auth.password == 'pass'
Пример #7
0
def test_post():
    ghr = BasicAuthRequester('user', 'pass')
    with mock.patch('requests.post') as g:
        g.return_value.status_code = 200
        ghr.post('url', {"a": 2})
        g.assert_called_with_args('url', data='{"a":2}', auth=mock.ANY)
Пример #8
0
def test_delete():
    ghr = BasicAuthRequester('user', 'pass')
    with mock.patch('requests.delete') as g:
        ghr.delete('url')
        g.assert_called_with_args('url', auth=mock.ANY)
Пример #9
0
def test_get():
    ghr = BasicAuthRequester('user', 'pass')
    with mock.patch('requests.get') as g:
        g.return_value.status_code = 200
        ghr.get('url')
        g.assert_called_with_args('url', auth=mock.ANY)