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/>"
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"
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/>"
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/>"
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/>"