Example #1
0
def test_github_good(serving_app):
    @serving_app.route('/meta')
    def meta():
        return jsonify({'hooks': ['192.30.252.0/22']})

    network = _load_github_hooks(github_url=serving_app.url)
    assert network == ['192.30.252.0/22']
Example #2
0
def test_bad_status(serving_app):
    @serving_app.route('/meta')
    def meta():
        return jsonify({'hooks': ['192.30.252.0/22']}), 403

    with pytest.raises(ServiceUnavailable) as exc:
        network = _load_github_hooks(github_url=serving_app.url)
    assert exc.value.description == 'Error reaching GitHub'
Example #3
0
def test_bad_structure(serving_app):
    @serving_app.route('/meta')
    def meta():
        return jsonify({})

    with pytest.raises(ServiceUnavailable) as exc:
        network = _load_github_hooks(github_url=serving_app.url)
    assert exc.value.description == 'Error reaching GitHub'
Example #4
0
def test_bad_headers(serving_app):
    @serving_app.route('/meta')
    def meta():
        headers = {
            'X-RateLimit-Remaining': 0,
        }
        return jsonify({'hooks': ['192.30.252.0/22']}), 403, headers

    with pytest.raises(ServiceUnavailable) as exc:
        network = _load_github_hooks(github_url=serving_app.url)
    assert exc.value.description == 'Error reaching GitHub'
Example #5
0
def test_rate_limited(serving_app):
    @serving_app.route('/meta')
    def meta():
        headers = {
            'X-RateLimit-Remaining': 0,
            'X-RateLimit-Reset': 1445929478,
        }
        return jsonify({'hooks': ['192.30.252.0/22']}), 403, headers

    with pytest.raises(ServiceUnavailable) as exc:
        network = _load_github_hooks(github_url=serving_app.url)
    assert (exc.value.description == 'Rate limited from GitHub until '
            'Tue, 27 Oct 2015 07:04:38 GMT')
Example #6
0
def test_bad_connection():
    with pytest.raises(ServiceUnavailable) as exc:
        network = _load_github_hooks(github_url='http://0.0.0.0:1234')
    assert (exc.value.description == 'Error reaching GitHub')