def test_package_with_version_specs(self, monkeypatch, specs, link): indexurl = "http://my/simple/" current = Current() current.reconfigure(dict(simpleindex=indexurl)) ri = RemoteIndex(current) def mockget(url): assert url.startswith(indexurl) assert url.endswith("pkg/") return url, """ <a href="http://my/pkg-0.3.tar.gz"/> <a href="http://my/pkg-0.2.8.tar.gz"/> <a href="http://my/pkg-0.2.7.tar.gz"/> <a href="http://my/pkg-0.2.6.tar.gz"/> <a href="http://my/pkg-0.2.5.tar.gz"/> <a href="http://my/pkg-0.2.5a1.tar.gz"/> <a href="http://my/pkg-0.2.4.1.tar.gz"/> <a href="http://my/pkg-0.2.4.tar.gz"/> <a href="http://my/pkg-0.2.3.tar.gz"/> <a href="http://my/pkg-0.2.2.tar.gz"/> <a href="http://my/pkg-0.2.1.tar.gz"/> <a href="http://my/pkg-0.2.0.tar.gz"/> """ monkeypatch.setattr(ri, "getcontent", mockget) lnk = ri.getbestlink(specs) assert URL(lnk.url).url_nofrag == link
def test_rooturl_on_outside_url(self, loghub): current = Current() d = { "index": "http://l/subpath/some/index", "login": "******", } current.reconfigure(data=d) assert current.rooturl == "http://l/subpath/"
def test_receive_error(self, monkeypatch, tmpdir): indexurl = "http://my/simple/" current = Current(tmpdir.join("client")) current.reconfigure(dict(simpleindex=indexurl)) ri = RemoteIndex(current) def mockget(url): raise ri.ReceiveError(404) monkeypatch.setattr(ri, "getcontent", mockget) link = ri.getbestlink("pkg") assert link is None
def test_switch_to_temporary(self, makehub, mock_http_api): hub = makehub(['use']) mock_http_api.set("http://foo/+api", 200, result=dict(pypisubmit="/post", simpleindex="/index/", index="root/some", bases="root/dev", login="******", authstatus=["noauth", ""])) current = Current() d = { "index": "http://l/some/index", "login": "******", } current.reconfigure(data=d) current.set_auth("user", "password") assert current.get_auth() == ("user", "password") temp = current.switch_to_temporary(hub, "http://foo") temp.set_auth("user1", "password1") assert temp.get_auth() == ("user1", "password1") # original is unaffected assert current.get_auth() == ("user", "password") assert temp._currentdict is not current._currentdict assert temp._currentdict['auth'] is not current._currentdict['auth']
def test_basic(self, monkeypatch, gen, tmpdir): md5 = gen.md5() indexurl = "http://my/simple/" current = Current(tmpdir.join("client")) current.reconfigure(dict(simpleindex=indexurl)) ri = RemoteIndex(current) def mockget(url): assert url.startswith(indexurl) return url, """ <a href="../../pkg-1.2.tar.gz#md5=%s"/> <a href="http://something/pkg-1.2dev1.zip"/> <a href="http://something/pkg-1.2dev2.zip"/> """ % md5 monkeypatch.setattr(ri, "getcontent", mockget) link = ri.getbestlink("pkg") assert URL(link.url).url_nofrag == "http://my/pkg-1.2.tar.gz"
def test_basic(self, monkeypatch, gen, tmpdir): md5 = gen.md5() indexurl = "http://my/simple/" current = Current(tmpdir.join("client")) current.reconfigure(dict(simpleindex=indexurl)) ri = RemoteIndex(current) def mockget(url): assert url.startswith(indexurl) return """ <a href="../../pkg-1.2.tar.gz#md5=%s"/> <a href="http://something/pkg-1.2dev1.zip"/> <a href="http://something/pkg-1.2dev2.zip"/> """ % md5 monkeypatch.setattr(ri, "getcontent", mockget) link = ri.getbestlink("pkg") assert URL(link.url).url_nofrag == "http://my/pkg-1.2.tar.gz"
def test_auth_multisite(self): current = Current() login1 = "http://site.com/+login" login2 = "http://site2.com/+login" current.login = login1 current.set_auth("hello", "pass1") current.login = login2 current.set_auth("hello", "pass2") assert current.get_auth(login1) == ("hello", "pass1") assert current.get_auth(login2) == ("hello", "pass2") current.login = login1 current.del_auth() assert not current.get_auth(login1) assert current.get_auth(login2) == ("hello", "pass2") current.login = login2 current.del_auth() assert not current.get_auth(login2)
def test_normalize_url(self): current = Current() current.reconfigure(dict(simpleindex="http://my.serv/index1")) url = current._normalize_url("index2") assert url == "http://my.serv/index2"
def test_auth_handling(self, loghub): current = Current() d = { "index": "http://l/some/index", "login": "******", } current.reconfigure(data=d) assert current.rooturl current.set_auth("user", "password") assert current.get_auth() == ("user", "password") # ok response d["authstatus"] = ["ok", "user"] current._configure_from_server_api(d, URL(current.rooturl)) assert current.get_auth() == ("user", "password") # invalidation response d["authstatus"] = ["nouser", "user"] current._configure_from_server_api(d, URL(current.rooturl)) assert not current.get_auth()
def test_invalid_url(self, loghub): current = Current() with pytest.raises(SystemExit): current.configure_fromurl(loghub, "http://heise.de:1802:31/qwe")
def current(self): self.clientdir.ensure(dir=1) path = self.clientdir.join("current.json") return Current(path)