Exemplo n.º 1
0
    def test_export_hard_links(self, makeimpexp):
        impexp = makeimpexp(options=('--hard-links', ))
        mapp1 = impexp.mapp1
        api = mapp1.create_and_use()
        content = b'content'
        mapp1.upload_file_pypi("he-llo-1.0.tar.gz", content, "he_llo", "1.0")
        content = zip_dict({"index.html": "<html/>"})
        mapp1.upload_doc("he-llo.zip", content, "he-llo", "")

        # export the data
        impexp.export()

        # check the number of links of the files in the exported data
        assert impexp.exportdir.join('dataindex.json').stat().nlink == 1
        assert impexp.exportdir.join('user1', 'dev',
                                     'he_llo-1.0.doc.zip').stat().nlink == 2
        assert impexp.exportdir.join('user1', 'dev', 'he-llo', '1.0',
                                     'he-llo-1.0.tar.gz').stat().nlink == 2

        # now import the data
        mapp2 = impexp.new_import()

        # and check that the files have the expected content
        with mapp2.xom.keyfs.transaction():
            stage = mapp2.xom.model.getstage(api.stagename)
            verdata = stage.get_versiondata_perstage("he_llo", "1.0")
            assert verdata["version"] == "1.0"
            links = stage.get_releaselinks("he_llo")
            assert len(links) == 1
            assert links[0].entry.file_get_content() == b'content'
            doczip = stage.get_doczip("he_llo", "1.0")
            archive = Archive(py.io.BytesIO(doczip))
            assert 'index.html' in archive.namelist()
            assert py.builtin._totext(archive.read("index.html"),
                                      'utf-8') == "<html/>"
Exemplo n.º 2
0
    def test_hard_links(self, makeimpexp):
        impexp = makeimpexp(options=('--hard-links',))
        mapp1 = impexp.mapp1
        api = mapp1.create_and_use()
        content = b'content'
        mapp1.upload_file_pypi("he-llo-1.0.tar.gz", content, "he_llo", "1.0")
        content = zip_dict({"index.html": "<html/>"})
        mapp1.upload_doc("he-llo.zip", content, "he-llo", "")

        impexp.export()

        assert impexp.exportdir.join(
          'dataindex.json').stat().nlink == 1
        assert impexp.exportdir.join(
          'user1', 'dev', 'he_llo-1.0.doc.zip').stat().nlink == 2
        assert impexp.exportdir.join(
          'user1', 'dev', 'he_llo', 'he-llo-1.0.tar.gz').stat().nlink == 2

        mapp2 = impexp.new_import()

        with mapp2.xom.keyfs.transaction():
            stage = mapp2.xom.model.getstage(api.stagename)
            verdata = stage.get_versiondata_perstage("he_llo", "1.0")
            assert verdata["version"] == "1.0"
            links = stage.get_releaselinks("he_llo")
            assert len(links) == 1
            assert links[0].entry.file_get_content() == b'content'
            doczip = stage.get_doczip("he_llo", "1.0")
            archive = Archive(py.io.BytesIO(doczip))
            assert 'index.html' in archive.namelist()
            assert py.builtin._totext(
                archive.read("index.html"), 'utf-8') == "<html/>"
Exemplo n.º 3
0
 def test_multiple_docs_on_same_version(self, impexp):
     mapp1 = impexp.mapp1
     api = mapp1.create_and_use()
     mapp1.set_versiondata({"name": "hello", "version": "1.0"})
     with mapp1.xom.keyfs.transaction(write=True):
         # create entries with and without log
         stage = mapp1.xom.model.getstage(mapp1.current_stage)
         link = stage.store_doczip(
             "Hello", "1.0",
             content=zip_dict({
                 "index.html": "<html><body>Hello"}))
         link.add_log('upload', stage.user.name, dst=stage.name)
         time.sleep(1.1)  # force different times in log entry
         link = stage.store_doczip(
             "hello", "1.0",
             content=zip_dict({
                 "index.html": "<html><body>hello"}))
         link.add_log('upload', stage.user.name, dst=stage.name)
     impexp.export()
     mapp2 = impexp.new_import()
     with mapp2.xom.keyfs.transaction(write=False):
         stage = mapp2.xom.model.getstage(api.stagename)
         doczip = stage.get_doczip("hello", "1.0")
         archive = Archive(py.io.BytesIO(doczip))
         assert 'index.html' in archive.namelist()
         assert py.builtin._totext(
             archive.read("index.html"), 'utf-8') == "<html><body>hello"
Exemplo n.º 4
0
    def test_storedoczipfile(self, stage, bases):
        from devpi_common.archive import Archive
        stage.set_versiondata(udict(name="pkg1", version="1.0"))
        content = zip_dict({"index.html": "<html/>",
            "_static": {}, "_templ": {"x.css": ""}})
        stage.store_doczip("pkg1", "1.0", content)
        archive = Archive(BytesIO(stage.get_doczip("pkg1", "1.0")))
        assert 'index.html' in archive.namelist()

        content = zip_dict({"nothing": "hello"})
        stage.store_doczip("pkg1", "1.0", content)
        archive = Archive(BytesIO(stage.get_doczip("pkg1", "1.0")))
        namelist = archive.namelist()
        assert 'nothing' in namelist
        assert 'index.html' not in namelist
        assert '_static' not in namelist
        assert '_templ' not in namelist
Exemplo n.º 5
0
    def test_storedoczipfile(self, stage, bases):
        from devpi_common.archive import Archive
        stage.set_versiondata(udict(name="pkg1", version="1.0"))
        content = zip_dict({"index.html": "<html/>",
            "_static": {}, "_templ": {"x.css": ""}})
        stage.store_doczip("pkg1", "1.0", content)
        archive = Archive(BytesIO(stage.get_doczip("pkg1", "1.0")))
        assert 'index.html' in archive.namelist()

        content = zip_dict({"nothing": "hello"})
        stage.store_doczip("pkg1", "1.0", content)
        archive = Archive(BytesIO(stage.get_doczip("pkg1", "1.0")))
        namelist = archive.namelist()
        assert 'nothing' in namelist
        assert 'index.html' not in namelist
        assert '_static' not in namelist
        assert '_templ' not in namelist
Exemplo n.º 6
0
def test_upload_docs_no_version(mapp, testapp, proj):
    api = mapp.create_and_use()
    content = zip_dict({"index.html": "<html/>"})
    mapp.set_versiondata(dict(name="Pkg1", version="1.0"))
    mapp.upload_doc("pkg1.zip", content, "Pkg1", "")
    vv = get_view_version_links(testapp, api.index, "Pkg1", "1.0", proj=proj)
    link = vv.get_link("doczip")
    assert link.href.endswith("/Pkg1-1.0.doc.zip")
    r = testapp.get(link.href)
    archive = Archive(py.io.BytesIO(r.body))
    assert 'index.html' in archive.namelist()
Exemplo n.º 7
0
def test_upload_docs(mapp, testapp, proj):
    api = mapp.create_and_use()
    content = zip_dict({"index.html": "<html/>"})
    mapp.upload_doc("pkg1.zip", content, "pkg1", "2.6", code=400)
    mapp.set_versiondata({"name": "pkg1", "version": "2.6"})
    mapp.upload_doc("pkg1.zip", content, "pkg1", "2.6", code=200)
    vv = get_view_version_links(testapp, api.index, "pkg1", "2.6", proj=proj)
    link = vv.get_link(rel="doczip")
    assert link.href.endswith("/pkg1-2.6.doc.zip")
    r = testapp.get(link.href)
    archive = Archive(py.io.BytesIO(r.body))
    assert 'index.html' in archive.namelist()
Exemplo n.º 8
0
 def test_docs_are_preserved(self, impexp):
     mapp1 = impexp.mapp1
     api = mapp1.create_and_use()
     mapp1.set_versiondata({"name": "hello", "version": "1.0"})
     content = zip_dict({"index.html": "<html/>"})
     mapp1.upload_doc("hello.zip", content, "hello", "")
     impexp.export()
     mapp2 = impexp.new_import()
     with mapp2.xom.keyfs.transaction(write=False):
         stage = mapp2.xom.model.getstage(api.stagename)
         doczip = stage.get_doczip("hello", "1.0")
         archive = Archive(py.io.BytesIO(doczip))
         assert 'index.html' in archive.namelist()
         assert py.builtin._totext(archive.read("index.html"),
                                   'utf-8') == "<html/>"
Exemplo n.º 9
0
 def test_docs_are_preserved(self, impexp):
     mapp1 = impexp.mapp1
     api = mapp1.create_and_use()
     mapp1.set_versiondata({"name": "hello", "version": "1.0"})
     content = zip_dict({"index.html": "<html/>"})
     mapp1.upload_doc("hello.zip", content, "hello", "")
     impexp.export()
     mapp2 = impexp.new_import()
     with mapp2.xom.keyfs.transaction(write=False):
         stage = mapp2.xom.model.getstage(api.stagename)
         doczip = stage.get_doczip("hello", "1.0")
         archive = Archive(py.io.BytesIO(doczip))
         assert 'index.html' in archive.namelist()
         assert py.builtin._totext(
             archive.read("index.html"), 'utf-8') == "<html/>"
Exemplo n.º 10
0
def test_upload_and_push_internal(mapp, testapp, monkeypatch, proj):
    mapp.create_user("user1", "1")
    mapp.create_and_login_user("user2")
    mapp.create_index("prod", indexconfig=dict(acl_upload=["user1", "user2"]))
    mapp.create_index("dev", indexconfig=dict(acl_upload=["user2"]))

    mapp.login("user1", "1")
    mapp.create_index("dev")
    mapp.use("user1/dev")
    mapp.upload_file_pypi("pkg1-2.6.tgz", b"123", "pkg1", "2.6")
    content = zip_dict({"index.html": "<html/>"})
    mapp.upload_doc("pkg1.zip", content, "pkg1", "")

    # check that push is authorized and executed towards user2/prod index
    req = dict(name="pkg1", version="2.6", targetindex="user2/prod")
    r = testapp.push("/user1/dev", json.dumps(req))
    assert r.status_code == 200
    vv = get_view_version_links(testapp, "/user2/prod", "pkg1", "2.6",
                                proj=proj)
    link = vv.get_link(rel="releasefile")
    assert link.href.endswith("/pkg1-2.6.tgz")
    # we check here that the upload of docs without version was
    # automatically tied to the newest release metadata
    link = vv.get_link(rel="doczip")
    assert link.href.endswith("/pkg1-2.6.doc.zip")
    r = testapp.get(link.href)
    archive = Archive(py.io.BytesIO(r.body))
    assert 'index.html' in archive.namelist()

    # reconfigure inheritance and see if get shadowing information
    mapp.modify_index("user1/dev", indexconfig=dict(bases=("/user2/prod",)))
    vv = get_view_version_links(testapp, "/user1/dev", "pkg1", "2.6", proj=proj)
    link = vv.get_link(rel="releasefile")
    assert link.href.endswith("/pkg1-2.6.tgz")
    shadows = vv.shadowed()
    assert len(shadows) == 1, vv.versiondata
    vv = shadows[0]
    link = vv.get_link(rel="releasefile")
    assert link.href.endswith("/pkg1-2.6.tgz")