Пример #1
0
def test_main_push_pypi(monkeypatch, tmpdir, spec):
    from devpi.push import main
    l = []

    def mypost(method, url, data, headers, auth=None, cert=None, verify=None):
        l.append((method, url, data))

        class r:
            status_code = 201
            reason = "created"
            content = json.dumps(
                dict(type="actionlog",
                     status=201,
                     result=[("200", "register", "pkg", "1.0"),
                             ("200", "upload", "pkg-1.3.tar.gz")]))
            headers = {"content-type": "application/json"}
            _json = json.loads(content)

        r.url = url
        return r

    class args:
        clientdir = tmpdir.join("client")
        debug = False
        index = None

    hub = Hub(args)
    monkeypatch.setattr(hub.http, "request", mypost)
    hub.current.reconfigure(dict(index="/some/index"))
    p = tmpdir.join("pypirc")
    p.write(
        textwrap.dedent("""
        [distutils]
        index-servers = whatever

        [whatever]
        repository: http://anotherserver
        username: test
        password: testp
    """))

    class args:
        pypirc = str(p)
        target = "pypi:whatever"
        pkgspec = spec
        index = None

    main(hub, args)
    assert len(l) == 1
    method, url, data = l[0]
    assert url == hub.current.index
    req = json.loads(data)
    assert req["name"] == "pkg"
    assert req["version"] == "1.0"
    assert req["posturl"] == "http://anotherserver"
    assert req["username"] == "test"
    assert req["password"] == "testp"
Пример #2
0
def test_fail_push(monkeypatch, tmpdir):
    from devpi.push import main
    l = []

    def mypost(method, url, data, headers, auth=None, cert=None, verify=None):
        l.append((method, url, data))

        class r:
            status_code = 500
            reason = "Internal Server Error"
            content = json.dumps(
                dict(type="actionlog",
                     status=201,
                     result=[("500", "Internal Server Error",
                              "Internal Server Error")]))
            headers = {"content-type": "application/json"}
            _json = json.loads(content)

            class request:
                method = ''

        r.url = url
        r.request.method = method

        return r

    class args:
        clientdir = tmpdir.join("client")
        debug = False
        index = None

    hub = Hub(args)
    monkeypatch.setattr(hub.http, "request", mypost)
    hub.current.reconfigure(dict(index="/some/index"))
    p = tmpdir.join("pypirc")
    p.write(
        textwrap.dedent("""
        [distutils]
        index-servers = whatever

        [whatever]
        repository: http://anotherserver
        username: test
        password: testp
    """))

    class args:
        pypirc = str(p)
        target = "pypi:whatever"
        pkgspec = "pkg==1.0"
        index = None

    try:
        main(hub, args)
    except SystemExit as e:
        assert e.code == 1
Пример #3
0
def test_main_push_pypi(monkeypatch, tmpdir):
    from devpi.push import main
    l = []
    def mypost(method, url, data, headers, auth=None):
        l.append((method, url, data))
        class r:
            status_code = 201
            reason = "created"
            content = json.dumps(dict(type="actionlog", status=201,
                result=[("200", "register", "pkg", "1.0"),
                        ("200", "upload", "pkg-1.3.tar.gz")]
            ))
            headers = {"content-type": "application/json"}
            _json = json.loads(content)
        r.url = url
        return r

    class args:
        clientdir = tmpdir.join("client")
        debug = False
    hub = Hub(args)
    monkeypatch.setattr(hub.http, "request", mypost)
    hub.current.reconfigure(dict(index="/some/index"))
    p = tmpdir.join("pypirc")
    p.write(py.std.textwrap.dedent("""
        [distutils]
        index-servers = whatever

        [whatever]
        repository: http://anotherserver
        username: test
        password: testp
    """))
    class args:
        pypirc = str(p)
        target = "pypi:whatever"
        nameversion = "pkg-1.0"

    main(hub, args)
    assert len(l) == 1
    method, url, data = l[0]
    assert url == hub.current.index
    req = py.std.json.loads(data)
    assert req["name"] == "pkg"
    assert req["version"] == "1.0"
    assert req["posturl"] == "http://anotherserver"
    assert req["username"] == "test"
    assert req["password"] == "testp"
Пример #4
0
def test_main(monkeypatch, tmpdir):
    from devpi.push import main
    l = []
    def mypost(url, data):
        l.append((url, data))
        class r:
            status_code = 201
        return r
    monkeypatch.setattr(py.std.requests, "post", mypost)

    class args:
        clientdir = tmpdir.join("client")

    hub = Hub(args)
    hub.config.reconfigure(dict(pushrelease="/push"))
    p = tmpdir.join("pypirc")
    p.write(py.std.textwrap.dedent("""
        [distutils]
        index-servers = whatever

        [whatever]
        repository: http://anotherserver
        username: test
        password: testp
    """))
    class args:
        pypirc = str(p)
        posturl = "whatever"
        nameversion = "pkg-1.0"
    main(hub, args)
    assert len(l) == 1
    url, data = l[0]
    assert url == "/push"
    req = py.std.json.loads(data)
    assert req["name"] == "pkg"
    assert req["version"] == "1.0"
    assert req["posturl"] == "http://anotherserver"
    assert req["username"] == "test"
    assert req["password"] == "testp"