예제 #1
0
def test_get():
    api = graylogapi.GraylogAPI('http://echo.jsontest.com/one/two', 
        username = '******',
        password = '******')
    res = api._get()
    expected = "{\"one\": \"two\"}\n"
    assert res == expected
예제 #2
0
def test_get():
    api = graylogapi.GraylogAPI('http://echo.jsontest.com/one/two',
                                username='******',
                                password='******')
    res = api._get()
    expected = {'one': 'two'}
    assert res == expected
예제 #3
0
def test_obj_path_build():
    api = graylogapi.GraylogAPI('https://test.com')
    assert api._path == ''
    api = api.foo
    assert api._path == '/foo'
    api = api.bar.baz
    assert api._path == '/foo/bar/baz'
    api = api._('from')
    assert api._path == '/foo/bar/baz/from'
예제 #4
0
def test_obj_creation():
    api = graylogapi.GraylogAPI('https://test.com/foo/bar/',
                                username='******',
                                password='******',
                                api_key='ABCDEFG')
    assert api._path == '/foo/bar/'
    assert api.username == 'Zack'
    assert api.password == 'Zack'
    assert api.api_key == 'ABCDEFG'
예제 #5
0
def test_auth_header():
    api = graylogapi.GraylogAPI('/', username='******', password='******')
    header = api.build_auth_header()
    payload = 'Zack' + ':' + 'Zack'
    header_test = {
        'Authorization': 'Basic ' + base64.b64encode(payload),
        'Accept': 'application/json'
    }
    assert header == header_test
예제 #6
0
def test_obj_creation():
    # test based on username / password API end-point access level
    api = graylogapi.GraylogAPI('https://test.com/foo/bar/',
                                username='******',
                                password='******',
                                api_key=None)
    assert api._path == '/foo/bar/'
    assert api.username == 'Zack'
    assert api.password == 'Zack'
    assert api.api_key is None

    # test based on api-key token access level
    api = graylogapi.GraylogAPI('https://test.com/foo/bar/',
                                username=None,
                                password=None,
                                api_key='ABCDEFG')
    assert api._path == '/foo/bar/'
    assert api.username is None
    assert api.password is None
    assert api.api_key == 'ABCDEFG'
예제 #7
0
def test_auth_header():
    # test based on username / password API end-point access level
    api = graylogapi.GraylogAPI('/', username='******', password='******')
    header = api.build_auth_header()
    payload = 'Zack' + ':' + 'Zack'
    header_test = {
        'Authorization': 'Basic ' + base64.b64encode(payload),
        'Accept': 'application/json'
    }
    assert header == header_test

    # test based on api-key token access level
    api = graylogapi.GraylogAPI('/',
                                username=None,
                                password=None,
                                api_key='ABCDEFG')
    header = api.build_auth_header()
    payload = 'ABCDEFG' + ':' + 'token'
    header_test = {
        'Authorization': 'Basic ' + base64.b64encode(payload),
        'Accept': 'application/json'
    }
    assert header == header_test
예제 #8
0
def test_delete():
    api = graylogapi.GraylogAPI('http://echo.jsontest.com/one/two', 
            username = '******',
            password = '******')
    with pytest.raises(NotImplementedError):
        api._delete()