def test_get_project_local_template_render(self): self.app.projects.add_metadata({"name": "foo", "version": "1.0", "_filename": "foo-1.0.tar.gz"}) self.app.projects.add_metadata({"name": "foo", "version": "1.1", "_filename": "foo-1.1.tar.gz"}) self.app.projects.add_metadata({"name": "foo", "version": "1.0.dev1", "_filename": "foo-1.0.dev1.tar.gz"}) result = self.client.get("/simple/foo") eq_(result.status_code, codes.ok) iter_ = iter_version_links(result.data, "foo") eq_(iter_.next(), ("foo-1.1.tar.gz", "/local/foo-1.1.tar.gz")) eq_(iter_.next(), ("foo-1.0.tar.gz", "/local/foo-1.0.tar.gz")) eq_(iter_.next(), ("foo-1.0.dev1.tar.gz", "/local/foo-1.0.dev1.tar.gz")) with assert_raises(StopIteration): iter_.next()
def test_get_project_remote_template_render(self): with self._mocked_get("http://pypi.python.org/simple/foo", codes.ok) as mock_get: mock_get.return_value.text = dedent("""\ <html> <body> <a href="../../packages/foo/foo-1.0c1.tar.gz">foo-1.0c1.tar.gz</a> </body> </html>""") result = self.client.get("/simple/foo") eq_(result.status_code, codes.ok) iter_ = iter_version_links(result.data, "foo") eq_(iter_.next(), ("foo-1.0c1.tar.gz", "/remote/packages/foo/foo-1.0c1.tar.gz?base=http%3A%2F%2Fpypi.python.org")) with assert_raises(StopIteration): iter_.next()
def test_iter_version_links(): """ Versions links are correctly parsed. """ HTML = dedent("""\ <html> <body> <a/> <a href="../../packages/foo-1.0.tar.gz"/>foo-1.0.tar.gz</a> <a href="../../packages/bar-1.0.tar.gz"/>bar-1.0.tar.gz</a> <a href="http://foo.com/foo" rel="download"/>foo download link</a> <a href="http://foo.com/files/foo-0.1.0.zip" rel="download">0.1.0 download_url</a><br/> </body> </html>""") iter_ = iter_version_links(HTML, "foo") eq_(next(iter_), ("foo-1.0.tar.gz", "../../packages/foo-1.0.tar.gz")) eq_(next(iter_), "http://foo.com/foo") eq_(next(iter_), ("foo-0.1.0.zip", "http://foo.com/files/foo-0.1.0.zip")) with assert_raises(StopIteration): next(iter_)