Skip to content
Merged
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
7 changes: 4 additions & 3 deletions landoscript/src/landoscript/actions/android_l10n_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ async def run(
toml_contents = await l10n_github_client.get_files(toml_files)
l10n_files: list[L10nFile] = []

missing = [fn for fn, contents in toml_contents.items() if contents is None]
if missing:
raise LandoscriptError(f"toml_file(s) {' '.join(missing)} are not present in repository")

for info in android_l10n_import_info.toml_info:
toml_file = info.toml_path
log.info(f"processing toml file: {toml_file}")

if toml_contents[toml_file] is None:
raise LandoscriptError(f"toml_file '{toml_file}' is not present in repository")

contents = tomllib.loads(str(toml_contents[toml_file]))
src_file_prefix = Path(toml_file).parent
dst_file_prefix = Path(info.dest_path)
Expand Down
7 changes: 4 additions & 3 deletions landoscript/src/landoscript/actions/android_l10n_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ async def run(github_client: GithubClient, public_artifact_dir: str, android_l10
toml_contents = await github_client.get_files(toml_files, branch=from_branch)
l10n_files: list[L10nFile] = []

missing = [fn for fn, contents in toml_contents.items() if contents is None]
if missing:
raise LandoscriptError(f"toml_file(s) {' '.join(missing)} are not present in repository")

for info in android_l10n_sync_info.toml_info:
toml_file = info.toml_path
log.info(f"processing toml file: {toml_file}")

if toml_contents[toml_file] is None:
raise LandoscriptError(f"toml_file '{toml_file}' is not present in repository")

contents = tomllib.loads(str(toml_contents[toml_file]))
src_file_prefix = Path(toml_file).parent
dst_file_prefix = src_file_prefix
Expand Down
66 changes: 65 additions & 1 deletion landoscript/tests/test_android_l10n_import.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest
from yarl import URL

from landoscript.errors import LandoscriptError
from landoscript.script import async_main
from tests.conftest import (
assert_add_commit_response,
Expand Down Expand Up @@ -241,7 +243,9 @@ async def test_success(
"lando_repo": "repo_name",
"android_l10n_import_info": android_l10n_import_info,
}
# done here because setup_test sets up github_installation_response too soon...argh
# this is the same setup that's done in `setup_test`, but in a slightly different
# order to accommodate the fact that we query the `mozilla-l10n` repository before
# the `lando_repo` repository.
from yarl import URL

lando_repo = payload["lando_repo"]
Expand Down Expand Up @@ -309,3 +313,63 @@ async def test_success(
else:
assert ("POST", submit_uri) not in aioresponses.requests
assert ("GET", status_uri) not in aioresponses.requests


@pytest.mark.asyncio
async def test_missing_toml_file(aioresponses, github_installation_responses, context):
payload = {
"actions": ["android_l10n_import"],
"lando_repo": "repo_name",
"android_l10n_import_info": {
"from_repo_url": "https://github.com/mozilla-l10n/android-l10n",
"toml_info": [
{
"dest_path": "mobile/android/fenix",
"toml_path": "mozilla-mobile/fenix/l10n.toml",
},
{
"dest_path": "mobile/android/focus-android",
"toml_path": "mozilla-mobile/focus-android/l10n.toml",
},
{
"dest_path": "mobile/android/android-components",
"toml_path": "mozilla-mobile/android-components/l10n.toml",
},
],
},
}

scopes = [f"project:releng:lando:repo:repo_name"]
scopes.append(f"project:releng:lando:action:android_l10n_import")

lando_api = context.config["lando_api"]
repo_info_uri = URL(f"{lando_api}/api/repoinfo/repo_name")
aioresponses.get(
repo_info_uri,
status=200,
payload={
"repo_url": f"https://github.com/faker/repo_name",
"branch_name": "fake_branch",
"scm_level": "whatever",
},
)

github_installation_responses("mozilla-l10n")
setup_github_graphql_responses(
aioresponses,
# toml files needed before fetching anything else
fetch_files_payload(
{
"mozilla-mobile/fenix/l10n.toml": None,
"mozilla-mobile/focus-android/l10n.toml": focus_l10n_toml,
"mozilla-mobile/android-components/l10n.toml": ac_l10n_toml,
}
),
)

context.task = {"payload": payload, "scopes": scopes}
try:
await async_main(context)
assert False, "should've raised LandoscriptError"
except LandoscriptError as e:
assert "toml_file(s) mozilla-mobile/fenix/l10n.toml are not present" in e.args[0]
45 changes: 45 additions & 0 deletions landoscript/tests/test_android_l10n_sync.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
from scriptworker_client.github_client import TransportQueryError

from landoscript.errors import LandoscriptError
from tests.conftest import (
assert_add_commit_response,
get_file_listing_payload,
Expand Down Expand Up @@ -246,3 +247,47 @@ def assert_func(req):
should_submit = True

await run_test(aioresponses, github_installation_responses, context, payload, ["android_l10n_sync"], should_submit, assert_func)


@pytest.mark.asyncio
async def test_missing_toml_file(aioresponses, github_installation_responses, context):
payload = {
"actions": ["android_l10n_sync"],
"lando_repo": "repo_name",
"android_l10n_sync_info": {
"from_branch": "main",
"toml_info": [
{
"toml_path": "mobile/android/fenix/l10n.toml",
},
{
"toml_path": "mobile/android/focus-android/l10n.toml",
},
{
"toml_path": "mobile/android/android-components/l10n.toml",
},
],
},
}

setup_github_graphql_responses(
aioresponses,
# toml files needed before fetching anything else
fetch_files_payload(
{
"mobile/android/fenix/l10n.toml": None,
"mobile/android/focus-android/l10n.toml": focus_l10n_toml,
"mobile/android/android-components/l10n.toml": ac_l10n_toml,
}
),
)

await run_test(
aioresponses,
github_installation_responses,
context,
payload,
["android_l10n_sync"],
err=LandoscriptError,
errmsg="toml_file(s) mobile/android/fenix/l10n.toml are not present",
)