-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add coverage for product-details rebuild
- Loading branch information
Showing
1 changed file
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,16 +3,33 @@ | |
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
import json | ||
import pathlib | ||
import re | ||
import subprocess | ||
from unittest import mock | ||
|
||
import aiohttp | ||
import pytest | ||
from aioresponses import aioresponses | ||
from sqlalchemy import engine, event | ||
|
||
import shipit_api.admin.product_details | ||
from shipit_api.admin.product_details import fetch_l10n_data | ||
from shipit_api.common.models import Release | ||
from shipit_api.admin.product_details import fetch_l10n_data, rebuild | ||
from shipit_api.common.models import Release, Version | ||
|
||
|
||
# product_details uses a postgresql-specific "split_part" sql function | ||
@event.listens_for(engine.Engine, "connect") | ||
def setup_split_part(dbapi_connection, conn_rec): | ||
def split_part(string, delimiter, position): | ||
return string.split(delimiter, position)[position - 1] | ||
|
||
dbapi_connection.create_function( | ||
"split_part", | ||
3, | ||
split_part, | ||
) | ||
|
||
|
||
def create_html(folder, items): | ||
|
@@ -72,3 +89,79 @@ async def test_fetch_l10n_data(): | |
m.get(url, status=200, payload=dict(a="a")) | ||
(_, changesets) = await fetch_l10n_data(session, release, raise_on_failure=True, use_cache=False) | ||
assert changesets == {"a": "a"} | ||
|
||
|
||
def mock_setup_working_copy(branch, url, secrets): | ||
subprocess.check_call(["git", "clone", "-n", url, str(shipit_api.common.config.PRODUCT_DETAILS_DIR)]) | ||
subprocess.check_call(["git", "checkout", "-b", branch, "906b7cd284728a2acec695ddcba9193b44d38982"], cwd=shipit_api.common.config.PRODUCT_DETAILS_DIR) | ||
subprocess.check_call(["git", "config", "user.email", "[email protected]"], cwd=shipit_api.common.config.PRODUCT_DETAILS_DIR) | ||
subprocess.check_call(["git", "config", "user.name", "Release Services Robot"], cwd=shipit_api.common.config.PRODUCT_DETAILS_DIR) | ||
|
||
|
||
def mock_git_push(branch, secrets): | ||
return | ||
|
||
|
||
@pytest.mark.asyncio | ||
@mock.patch("shipit_api.admin.product_details.setup_working_copy", mock_setup_working_copy) | ||
@mock.patch("shipit_api.admin.product_details.git_push", mock_git_push) | ||
async def test_rebuild(app, tmp_path): | ||
fxnightly = Version(product_name="firefox", current_version="135.0a1", product_channel="nightly") | ||
tbnightly = Version(product_name="thunderbird", current_version="135.0a1", product_channel="nightly") | ||
deved = Release( | ||
product="devedition", | ||
branch="releases/mozilla-beta", | ||
version="134.0b9", | ||
revision="615791f9752c70ef1757abf68544c8275f219ce3", | ||
build_number=1, | ||
release_eta=None, | ||
status="shipped", | ||
partial_updates=None, | ||
) | ||
beta = Release( | ||
product="firefox", | ||
branch="releases/mozilla-beta", | ||
version="134.0b8", | ||
revision="9fb87e89c26069198ce2a59a0a790a264d225169", | ||
build_number=1, | ||
release_eta=None, | ||
status="shipped", | ||
partial_updates=None, | ||
) | ||
release = Release( | ||
product="firefox", | ||
branch="releases/mozilla-release", | ||
version="133.0", | ||
revision="8141aab3ba856d7cbae6c851dd71f2e0cb69649c", | ||
build_number=2, | ||
release_eta=None, | ||
status="shipped", | ||
partial_updates=None, | ||
) | ||
app.db.session.add(fxnightly) | ||
app.db.session.add(tbnightly) | ||
app.db.session.add(deved) | ||
app.db.session.add(beta) | ||
app.db.session.add(release) | ||
app.db.session.commit() | ||
with ( | ||
mock.patch("shipit_api.common.config.PRODUCT_DETAILS_DIR", tmp_path / "product-details"), | ||
mock.patch("shipit_api.common.config.PRODUCT_DETAILS_NEW_DIR", tmp_path / "product-details-new"), | ||
mock.patch("shipit_api.common.config.PRODUCT_DETAILS_CACHE_DIR", tmp_path / "product-details-cache"), | ||
): | ||
await rebuild(app.db.session, "testing", "https://github.com/mozilla-releng/product-details", "public", 130) | ||
|
||
parent = tmp_path / "product-details" / "public" / "1.0" | ||
with (parent / "firefox_versions.json").open() as f: | ||
versions = json.load(f) | ||
assert versions["FIREFOX_NIGHTLY"] == "135.0a1" | ||
assert versions["FIREFOX_DEVEDITION"] == "134.0b9" | ||
assert versions["LATEST_FIREFOX_DEVEL_VERSION"] == "134.0b8" | ||
assert versions["LATEST_FIREFOX_VERSION"] == "133.0" | ||
|
||
with (parent / "firefox_primary_builds.json").open() as f: | ||
primary_builds = json.load(f) | ||
assert set(primary_builds["ach"].keys()) == {"133.0", "134.0b8", "134.0b9", "135.0a1"} | ||
|
||
assert not list(parent.glob("l10n/Devedition-*")) | ||
assert next(parent.glob("l10n/Firefox-134.0b8-*")).name == "Firefox-134.0b8-build1.json" |