示例#1
0
def test_api_url(mock_session):
    session1 = quay_session.QuaySession()
    result1 = session1._api_url("some/endpoint")
    assert result1 == "https://quay.io/v2/some/endpoint"

    session2 = quay_session.QuaySession("http://registry.com")
    result2 = session2._api_url("other/endpoint")
    assert result2 == "http://registry.com/v2/other/endpoint"
示例#2
0
def test_set_token(mock_session):
    mocked_session = mock.MagicMock()
    mocked_session.headers = {}
    mock_session.return_value = mocked_session

    session = quay_session.QuaySession()
    session.set_auth_token("some-token")

    assert session.session.headers["Authorization"] == "Bearer some-token"
示例#3
0
def test_put(mock_session):
    mocked_session = mock.MagicMock()
    mocked_session.headers = {}
    mock_session.return_value = mocked_session
    session = quay_session.QuaySession()

    kwargs = {"data": "new data"}
    session.put("put/data/3", **kwargs)
    kwargs["timeout"] = 10
    mocked_session.put.assert_called_with("https://quay.io/v2/put/data/3",
                                          **kwargs)
示例#4
0
def test_post(mock_session):
    mocked_session = mock.MagicMock()
    mocked_session.headers = {}
    mock_session.return_value = mocked_session
    session = quay_session.QuaySession()

    kwargs = {"headers": {"Accept": "application/json"}, "data": "some data"}
    session.post("post/data/2", **kwargs)
    kwargs["timeout"] = 10
    mocked_session.post.assert_called_with("https://quay.io/v2/post/data/2",
                                           **kwargs)
示例#5
0
def test_delete(mock_session):
    mocked_session = mock.MagicMock()
    mocked_session.headers = {}
    mock_session.return_value = mocked_session
    session = quay_session.QuaySession()

    kwargs = {"data": "old data"}
    session.delete("delete/data/4", **kwargs)
    kwargs["timeout"] = 10
    mocked_session.delete.assert_called_with(
        "https://quay.io/v2/delete/data/4", **kwargs)
示例#6
0
def test_init_docker_api(mock_session):
    mocked_session = mock.MagicMock()
    mocked_session.headers = {}
    mock_session.return_value = mocked_session

    session = quay_session.QuaySession(api="docker")

    assert session.hostname == "quay.io"
    assert session.session.verify is False
    assert session.session.headers["Host"] == "quay.io"
    assert session.api == "docker"
    assert session._api_url(
        "some-endpoint") == "https://quay.io/v2/some-endpoint"
示例#7
0
def test_init_unsupported_api():
    with pytest.raises(ValueError, match="Unknown API type.*"):
        quay_session.QuaySession(api="unsupported")