Skip to content

Commit

Permalink
tests: improve coverage and reporting
Browse files Browse the repository at this point in the history
Add tests for missing functions with better response checking.
Add context output for html report.

Signed-off-by: Eric Fahlgren <[email protected]>
  • Loading branch information
efahl authored and aparcar committed Sep 28, 2024
1 parent afcbf00 commit 67fc5ee
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 19 deletions.
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ isort = "^5.13.2"
fakeredis = "^2.24.1"


[tool.coverage.run]
dynamic_context = "test_function"

[tool.coverage.report]
precision = 1

[tool.coverage.html]
show_contexts = "true"
title = "ASU Server Regression Test Coverage"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def redis_load_mock_data(redis):
redis.sadd("packages:21.02:21.02.7:ath79/generic", "vim", "tmux")
redis.sadd("packages:21.02:21.02.7:x86/64", "vim", "tmux")

redis.set("revision:21.02.7:x86/64", "r16847-f8282da11e")

redis.hset(
"mapping:1.2:1.2.3:testtarget/testsubtarget",
mapping={"testvendor,testprofile": "testprofile"},
Expand Down
7 changes: 7 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,13 @@ def test_api_version_update(app):
assert response.status_code == 403


def test_api_revision(client):
response = client.get("/api/v1/revision/21.02.7/x86/64", follow_redirects=False)
assert response.status_code == 200
data = response.json()
assert data["revision"] == "r16847-f8282da11e"


def test_api_stats(client):
response = client.get("/api/v1/stats", follow_redirects=False)
assert response.status_code == 200
Expand Down
69 changes: 50 additions & 19 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from asu.build_request import BuildRequest
from asu.util import (
httpx, # For monkeypatching.
check_manifest,
diff_packages,
fingerprint_pubkey_usign,
Expand All @@ -15,7 +16,8 @@
get_podman,
get_request_hash,
get_str_hash,
parse_packages_versions,
parse_packages_file,
parse_feeds_conf,
run_cmd,
verify_usign,
)
Expand Down Expand Up @@ -100,24 +102,29 @@ def test_get_version_container_tag():
assert get_container_version_tag("SNAPP-SNAPSHOT") == "openwrt-SNAPP"


def test_get_packages_versions():
text = (
"Package: libusb-1.0-0\n"
"ABIVersion: -0\n"
"Version: 1.2.3\n"
"Architecture: x86_64\n"
"\n"
"Package: libpython-3.3-3\n"
"ABIVersion: -3\n"
"Version: 1.2.3\n"
"\n"
"Package: bort\n"
"Version: 9.9.9\n"
"\n"
"\n" # Add two more to fake malformed input.
"\n"
)
index = parse_packages_versions(text)
def test_get_packages_versions(monkeypatch):
class Response:
status_code = 200
text = (
"Package: libusb-1.0-0\n"
"ABIVersion: -0\n"
"Version: 1.2.3\n"
"Architecture: x86_64\n"
"\n"
"Package: libpython-3.3-3\n"
"ABIVersion: -3\n"
"Version: 1.2.3\n"
"\n"
"Package: bort\n"
"Version: 9.9.9\n"
"\n"
"\n" # Add two more to fake malformed input.
"\n"
)

monkeypatch.setattr(httpx, "get", lambda url: Response())

index = parse_packages_file("httpx://fake_url")
packages = index["packages"]

assert index["architecture"] == "x86_64"
Expand All @@ -126,6 +133,30 @@ def test_get_packages_versions():
assert packages["libpython-3.3"] == "1.2.3"
assert packages["bort"] == "9.9.9"

Response.status_code = 404
index = parse_packages_file("abc://fake")
assert index == {}


def test_get_feeds(monkeypatch):
class Response:
status_code = 200
text = (
"src-git packages https://git.openwrt.org/feed/packages.git^b1635b8\n"
"src-git luci https://git.openwrt.org/project/luci.git^63d8b79\n"
)

monkeypatch.setattr(httpx, "get", lambda url: Response())

feeds = parse_feeds_conf("httpx://fake_url")
assert len(feeds) == 2
assert feeds[0] == "packages"
assert feeds[1] == "luci"

Response.status_code = 404
feeds = parse_feeds_conf("httpx://fake_url")
assert feeds == []


def test_check_manifest():
assert check_manifest({"test": "1.0"}, {"test": "1.0"}) is None
Expand Down

0 comments on commit 67fc5ee

Please sign in to comment.