Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 49 additions & 32 deletions pulp_file/tests/functional/api/test_filesystem_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,47 +174,64 @@ def test_fsexport_by_version(
}


def _filesystem_domain(pulpcore_bindings, gen_object_with_cleanup):
body = {
"name": str(uuid.uuid4()),
"storage_class": "pulpcore.app.models.storage.FileSystem",
"storage_settings": {"MEDIA_ROOT": "/var/lib/pulp/media/"},
}
return gen_object_with_cleanup(pulpcore_bindings.DomainsApi, body)


@pytest.mark.skipif(not settings.DOMAIN_ENABLED, reason="Domains not enabled.")
@pytest.mark.parallel
def test_fsexport_cross_domain(
fs_exporter_factory,
fs_export_factory,
gen_object_with_cleanup,
pulpcore_bindings,
pub_and_repo,
file_bindings,
file_repository_factory,
file_publication_factory,
tmp_path,
monitor_task,
):
# Publication and versions live in source_domain; exporter lives in other_domain.
source_domain = _filesystem_domain(pulpcore_bindings, gen_object_with_cleanup)
other_domain = _filesystem_domain(pulpcore_bindings, gen_object_with_cleanup)

src = tmp_path / "file.dat"
src.write_text("x")
content_href = file_bindings.ContentFilesApi.upload(
relative_path="0.dat", file=str(src), pulp_domain=source_domain.name
).pulp_href
repository = file_repository_factory(pulp_domain=source_domain.name)
monitor_task(
file_bindings.RepositoriesFileApi.modify(
repository.pulp_href, {"add_content_units": [content_href]}
).task
)
repository = file_bindings.RepositoriesFileApi.read(repository.pulp_href)
publication = file_publication_factory(
repository=repository.pulp_href, pulp_domain=source_domain.name
)
latest = repository.latest_version_href
zeroth = latest.rsplit("/", 2)[0] + "/0/"
exporter = fs_exporter_factory(pulp_domain=other_domain.name)

entities = [{}, {}]
for e in entities:
body = {
"name": str(uuid.uuid4()),
"storage_class": "pulpcore.app.models.storage.FileSystem",
"storage_settings": {"MEDIA_ROOT": "/var/lib/pulp/media/"},
}
e["domain"] = gen_object_with_cleanup(pulpcore_bindings.DomainsApi, body)
e["publication"], e["repository"] = pub_and_repo(pulp_domain=e["domain"].name)
e["exporter"] = fs_exporter_factory(pulp_domain=e["domain"].name)
body = {"publication": e["publication"].pulp_href}
e["export"] = fs_export_factory(e["exporter"], body=body)

latest = entities[0]["repository"].latest_version_href
zeroth = latest.replace("/2/", "/0/")

with pytest.raises(BadRequestException) as e:
body = {"publication": entities[0]["publication"].pulp_href}
fs_export_factory(entities[1]["exporter"], body=body)
with pytest.raises(BadRequestException):
fs_export_factory(exporter, body={"publication": publication.pulp_href})

with pytest.raises(BadRequestException) as e:
body = {"repository_version": latest}
fs_export_factory(entities[1]["exporter"], body=body)
with pytest.raises(BadRequestException):
fs_export_factory(exporter, body={"repository_version": latest})

with pytest.raises(BadRequestException) as e:
body = {"repository_version": latest, "start_repository_version": zeroth}
fs_export_factory(entities[1]["exporter"], body=body)
with pytest.raises(BadRequestException):
fs_export_factory(
exporter, body={"repository_version": latest, "start_repository_version": zeroth}
)

with pytest.raises(BadRequestException) as e:
body = {
"publication": entities[0]["publication"].pulp_href,
"start_repository_version": zeroth,
}
fs_export_factory(entities[1]["exporter"], body=body)
with pytest.raises(BadRequestException):
fs_export_factory(
exporter,
body={"publication": publication.pulp_href, "start_repository_version": zeroth},
)
56 changes: 32 additions & 24 deletions pulp_file/tests/functional/api/test_mime_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,36 @@ def test_content_types(
file_bindings,
distribution_base_url,
file_repo_with_auto_publish,
file_content_unit_with_name_factory,
gen_object_with_cleanup,
monitor_task,
tmp_path,
):
"""Test if content-app correctly returns mime-types based on filenames."""
relative_paths = {
"tar.gz": f"{uuid.uuid4()}.tar.gz",
"xml.gz": f"{uuid.uuid4()}.xml.gz",
"xml.bz2": f"{uuid.uuid4()}.xml.bz2",
"xml.zstd": f"{uuid.uuid4()}.xml.zstd",
"xml.xz": f"{uuid.uuid4()}.xml.xz",
"json.zstd": f"{uuid.uuid4()}.json.zstd",
"json": f"{uuid.uuid4()}.json",
"txt": f"{uuid.uuid4()}.txt",
"xml": f"{uuid.uuid4()}.xml",
"jpg": f"{uuid.uuid4()}.jpg",
"JPG": f"{uuid.uuid4()}.JPG",
"halabala": f"{uuid.uuid4()}.halabala",
"noextension1": f"{uuid.uuid4()}.asd/.asd/a",
"noextension2": f"{uuid.uuid4()}.....f",
}

blob = tmp_path / "blob"
blob.write_bytes(b"mime-type-test")
files = {
"tar.gz": file_content_unit_with_name_factory(f"{str(uuid.uuid4())}.tar.gz"),
"xml.gz": file_content_unit_with_name_factory(f"{str(uuid.uuid4())}.xml.gz"),
"xml.bz2": file_content_unit_with_name_factory(f"{str(uuid.uuid4())}.xml.bz2"),
"xml.zstd": file_content_unit_with_name_factory(f"{str(uuid.uuid4())}.xml.zstd"),
"xml.xz": file_content_unit_with_name_factory(f"{str(uuid.uuid4())}.xml.xz"),
"json.zstd": file_content_unit_with_name_factory(f"{str(uuid.uuid4())}.json.zstd"),
"json": file_content_unit_with_name_factory(f"{str(uuid.uuid4())}.json"),
"txt": file_content_unit_with_name_factory(f"{str(uuid.uuid4())}.txt"),
"xml": file_content_unit_with_name_factory(f"{str(uuid.uuid4())}.xml"),
"jpg": file_content_unit_with_name_factory(f"{str(uuid.uuid4())}.jpg"),
"JPG": file_content_unit_with_name_factory(f"{str(uuid.uuid4())}.JPG"),
"halabala": file_content_unit_with_name_factory(f"{str(uuid.uuid4())}.halabala"),
"noextension1": file_content_unit_with_name_factory(f"{str(uuid.uuid4())}.asd/.asd/a"),
"noextension2": file_content_unit_with_name_factory(f"{str(uuid.uuid4())}.....f"),
extension: file_bindings.ContentFilesApi.upload(file=str(blob), relative_path=relative_path)
for extension, relative_path in relative_paths.items()
}

units_to_add = list(map(lambda f: f.pulp_href, files.values()))
data = RepositoryAddRemoveContent(add_content_units=units_to_add)
data = RepositoryAddRemoveContent(add_content_units=[f.pulp_href for f in files.values()])
monitor_task(
file_bindings.RepositoriesFileApi.modify(file_repo_with_auto_publish.pulp_href, data).task
)
Expand All @@ -49,18 +55,20 @@ def test_content_types(
distribution = gen_object_with_cleanup(file_bindings.DistributionsFileApi, data)
distribution_base_url = distribution_base_url(distribution.base_url)

received_mimetypes = {}
for extension, content_unit in files.items():
async def fetch_mimetypes():
async with aiohttp.ClientSession() as session:

async def get_content_type():
async with aiohttp.ClientSession() as session:
async def get_content_type(extension, content_unit):
url = urljoin(distribution_base_url, content_unit.relative_path)
async with session.get(url) as response:
return response.headers.get("Content-Type")
return extension, response.headers.get("Content-Type")

content_type = asyncio.run(get_content_type())
received_mimetypes[extension] = content_type
pairs = await asyncio.gather(
*(get_content_type(ext, unit) for ext, unit in files.items())
)
return dict(pairs)

received_mimetypes = asyncio.run(fetch_mimetypes())
expected_mimetypes = {
"tar.gz": "application/gzip",
"xml.gz": "application/gzip",
Expand Down
Loading
Loading