Ejemplo n.º 1
0
def test_unauthorized_get(mock_get):
    mock_response = MagicMock()
    mock_response.status_code = 401

    mock_get.return_value = mock_response

    url = 'http://example.com/foo'

    session = OSFSession()

    with pytest.raises(UnauthorizedException):
        session.get(url)

    mock_get.assert_called_once_with(url)
Ejemplo n.º 2
0
def test_get(mock_get):
    mock_response = MagicMock()
    mock_response.status_code = 200

    mock_get.return_value = mock_response

    url = 'http://example.com/foo'

    session = OSFSession()

    response = session.get(url)

    assert response == mock_response
    mock_get.assert_called_once_with(url)
Ejemplo n.º 3
0
def test_basic_auth():
    session = OSFSession()
    session.basic_auth('*****@*****.**', 'secret_password')
    assert session.auth == ('*****@*****.**', 'secret_password')
    assert 'Authorization' not in session.headers
Ejemplo n.º 4
0
def test_basic_build_url():
    session = OSFSession()
    url = session.build_url("some", "path")
    assert url.startswith(session.base_url)
    assert url.endswith("/some/path/")
Ejemplo n.º 5
0
def test_token_auth():
    session = OSFSession()
    session.token_auth('asdfg')
    assert 'Authorization' in session.headers
Ejemplo n.º 6
0
def test_address():
    address = "https://api.test.osf.io/v2/"
    session = OSFSession(address=address)
    assert session.base_url == address
    assert session.base_url != "https://api.osf.io/v2/"
Ejemplo n.º 7
0
def test_token_auth():
    session = OSFSession()
    session.token_auth('0123456789abcd')
    assert session.auth is None
    assert session.headers['Authorization'] == 'Bearer 0123456789abcd'