From 52ec5f195b8ced130e32fa86513bdd757f85cd57 Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Tue, 2 Aug 2022 16:40:39 +1000 Subject: [PATCH] Add a test running entire command --- repo_autoindex/_impl/cmd.py | 3 +- .../pkgs/w/walrus-5.21-1.noarch.rpm | Bin 0 -> 2445 bytes ...384ad654e7214266648c37f0b-filelists.xml.gz | Bin 0 -> 243 bytes ...529bbfa22d0c890285ce6aa3129-primary.xml.gz | Bin 0 -> 598 bytes ...e3d28420987132d7d2c176127b9db-other.xml.gz | Bin 0 -> 229 bytes tests/sample_repo/repodata/repomd.xml | 28 +++++++++ tests/test_cmd.py | 58 ++++++++++++++++++ 7 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 tests/sample_repo/pkgs/w/walrus-5.21-1.noarch.rpm create mode 100644 tests/sample_repo/repodata/33795fed0c0144a7fe732a9ded8d7529940e4a1384ad654e7214266648c37f0b-filelists.xml.gz create mode 100644 tests/sample_repo/repodata/3a7a286e13883d497b2e3c7029ceb7c372ff2529bbfa22d0c890285ce6aa3129-primary.xml.gz create mode 100644 tests/sample_repo/repodata/834b12e38d809c4b5afd1a7c03ad48c0e15e3d28420987132d7d2c176127b9db-other.xml.gz create mode 100644 tests/sample_repo/repodata/repomd.xml create mode 100644 tests/test_cmd.py diff --git a/repo_autoindex/_impl/cmd.py b/repo_autoindex/_impl/cmd.py index b521e75..6389ffb 100644 --- a/repo_autoindex/_impl/cmd.py +++ b/repo_autoindex/_impl/cmd.py @@ -1,6 +1,5 @@ import argparse import asyncio -import gzip import logging import os @@ -19,7 +18,7 @@ async def dump_autoindices(args: argparse.Namespace) -> None: LOG.info("Wrote %s", output) -def entrypoint(): +def entrypoint() -> None: parser = argparse.ArgumentParser() parser.add_argument("url") parser.add_argument("--index-filename", default="index.html") diff --git a/tests/sample_repo/pkgs/w/walrus-5.21-1.noarch.rpm b/tests/sample_repo/pkgs/w/walrus-5.21-1.noarch.rpm new file mode 100644 index 0000000000000000000000000000000000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5S2vMSB9}-$8Nw)szQ8(T;hH&wEI@jPf6p z_j%YG$HrPo8T;ba+yD4XZ;`{W1!n}KDd+cK9abFT#>=sWCG>eXZ2S8Pd2EUTQT-sl$I; z;FO4Tq`%I~vK=fWDVCWFV`H)uBq~GT?HRlf9B#8&%mz*{TQeLaRS;~?2L}rd!Oj^{ ztpX=E@kXniv+-7&g_m3HDa2yV$jl)bR?conb&r=@N$@m^RBH?-g@y~!>lI9>R;vvO zF&H?G)2KBXwTjVVtlh2Ef`xQjFp(`)NM$KfS-M6A7a=o)pPRyG z@OHC-7;I)MNm*yM5$&T;c_JpW^Tt$8ka?o$c?zzD@MXHFD5=21;6}5ZHwaey+DBGU zW&h6lh;_$i9nG)LYGfxk(d6E2U9LggJVs6~#5D!QOUZ=5PsK3INrq8L+I*gVqu@E8 zj@*M$YigWdcQ&EDCBD7!Y|GZd+&Xe=g`S+a-4Z@}`>4@3 WyL-C)E1k|pSmQ%PLG3{>bAJMMz);!% literal 0 HcmV?d00001 diff --git a/tests/sample_repo/repodata/33795fed0c0144a7fe732a9ded8d7529940e4a1384ad654e7214266648c37f0b-filelists.xml.gz b/tests/sample_repo/repodata/33795fed0c0144a7fe732a9ded8d7529940e4a1384ad654e7214266648c37f0b-filelists.xml.gz new file mode 100644 index 0000000000000000000000000000000000000000..77d3cec661439d97b1a512d3470bf484e0e53d4a GIT binary patch literal 243 zcmVhiwFP!0000013gbma)cld-RBfk?<0buk`iZ^6C?*fY-T7CEycv+2Pf97 z`uF;M+S@UC@`LN<=AeLOIS>qH9$dI9`2PBQZ{XIwwbps`Zi^d9_^>H>#JGG=>Rs56 zY}iN4aMEjs(+`8hbd6*g?`}|lO;PKr5XMMpWmW4sw?*0Ws_C^B z9CKSTZkWhZ+o0s7wW80ZWmby1upCIx6Ds)Ce%+IrUd=;6n9rKz2x+fy1ef_drGROp tKxCW&S<#=q=o5LG?r5AA`p=fdBeu^d$v3@>pY1DM_Xh+{9&JDY002!$cZL7} literal 0 HcmV?d00001 diff --git a/tests/sample_repo/repodata/3a7a286e13883d497b2e3c7029ceb7c372ff2529bbfa22d0c890285ce6aa3129-primary.xml.gz b/tests/sample_repo/repodata/3a7a286e13883d497b2e3c7029ceb7c372ff2529bbfa22d0c890285ce6aa3129-primary.xml.gz new file mode 100644 index 0000000000000000000000000000000000000000..9455510ef5907ba659f3ff09bee7ebf4630400b2 GIT binary patch literal 598 zcmV-c0;&BUiwFP!000001BH`KbKD>dhVS_m4EHtb&$Tl)nH*Y)RWuCtlz@`D?$oKGKfZt1<@AByl><0Y z3nvKT%2u>>ZoFr#@6_}X)YBOPs3*2kOzL6Kiq7=C8HaZ>kfCH0@+?k(=Z6%FE-rD` z5i05len&{D!~pzR^k%XpyE#58jBL5meks|_@zJF-0;85~MX@`KR5T5ukP-vEuf%So zY(bvwG%VF@E21>RE1geWUD2OU-zbMXK8P$%r7Vi3$PVJLZ{p+_W%*HvG=hDTgpmx> zJ(@WbQPMQ&abGlHQ>2HuiAuH>xmCn<5a!AsNsZQZ?Vjj{tlh1M$7`_Cbfd#|{+IF= z^JxoWc*$N(AD>Lmmzg;0jF7E%B50u2MvS1x9s+GnCG(u;T{i$}x*oL&v$ROUB1=%i z}sIXp|%=C7rTP^gSS-M3nd;br-)|WJ^}BrSLZ=t%0VZ zD86OSY;JAmhqeoYdB%Z%4s%kY%^;jN(ZTS2-$_sw_{T4wFDUxk&<0&VVXJ)JUYu?B zWb`!hPs)K&;Mn6h;t98_**RkdwuGAwt+tNa;TPF`0!p(O~)nJe-CrlNCsN}67r k@Yg+krSJa~Jcj*yc*)iwyuLDTuD_fA0m#(_c4q_t03ppUSpWb4 literal 0 HcmV?d00001 diff --git a/tests/sample_repo/repodata/834b12e38d809c4b5afd1a7c03ad48c0e15e3d28420987132d7d2c176127b9db-other.xml.gz b/tests/sample_repo/repodata/834b12e38d809c4b5afd1a7c03ad48c0e15e3d28420987132d7d2c176127b9db-other.xml.gz new file mode 100644 index 0000000000000000000000000000000000000000..1c896caf79e35554ec052f941394158ac2e19ed7 GIT binary patch literal 229 zcmVqlo7b(MgGHI72prtp_Tg#q>+|Ei!pHrsp7)N|mUe>3hs|QQ@5@by zu@A>9X^(*uZVxf>PA4V)c!Y)AKu?am#CYXuVHuu%Ymuw0q$1PK8RJb+QknWJZ&Xn= zL|Sp`bE%xvX_OTkm3yz7)OhKQE;FwX0!?i3hsO2T5NLIs#W0^Wz5}SQV8F|Ku41@2 fv8WRz5mp{gUm_Y4m$Os;N4@_7j*tA;9RUCU^389# literal 0 HcmV?d00001 diff --git a/tests/sample_repo/repodata/repomd.xml b/tests/sample_repo/repodata/repomd.xml new file mode 100644 index 0000000..3dd3bd0 --- /dev/null +++ b/tests/sample_repo/repodata/repomd.xml @@ -0,0 +1,28 @@ + + + 1659419679 + + 3a7a286e13883d497b2e3c7029ceb7c372ff2529bbfa22d0c890285ce6aa3129 + ad4149ec99b72282ab4891ea5d224db02cc3d7e0ad5c1bdaba56c21cbd4ab132 + + 1659419679 + 598 + 1127 + + + 33795fed0c0144a7fe732a9ded8d7529940e4a1384ad654e7214266648c37f0b + ae8aa2cca2e1eba056ed56a66da2b1f6cdb142e465a13bb55f603c7481239e39 + + 1659419679 + 243 + 320 + + + 834b12e38d809c4b5afd1a7c03ad48c0e15e3d28420987132d7d2c176127b9db + ee1c6e87c3b7ebfa2e85d9b56e245ef097a0d928794da75ab63d43ac5593d9d0 + + 1659419679 + 229 + 285 + + diff --git a/tests/test_cmd.py b/tests/test_cmd.py new file mode 100644 index 0000000..657a9bf --- /dev/null +++ b/tests/test_cmd.py @@ -0,0 +1,58 @@ +import pathlib +import asyncio + +import pytest + +from aiohttp import web, test_utils + +from repo_autoindex._impl.cmd import entrypoint + + +THIS_DIR = pathlib.Path(__file__).parent + + +async def test_command(monkeypatch: pytest.MonkeyPatch, tmp_path: pathlib.Path): + """Run the repo-autoindex command against a sample repo and check the generated index.""" + + monkeypatch.chdir(tmp_path) + + entrypoint_coro = [] + + def fake_run(coro): + assert asyncio.iscoroutine(coro) + entrypoint_coro.append(coro) + + monkeypatch.setattr("asyncio.run", fake_run) + + app = web.Application() + app.add_routes([web.static("/", THIS_DIR)]) + + async with test_utils.TestServer(app) as server: + repo_url = server.make_url("/sample_repo") + monkeypatch.setattr("sys.argv", ["repo-autoindex", str(repo_url)]) + + entrypoint() + + assert entrypoint_coro + await entrypoint_coro[0] + + # It should have written index files reproducing the structure + index_toplevel = tmp_path.joinpath("index.html") + index_pkgs = tmp_path.joinpath("pkgs", "index.html") + index_w = tmp_path.joinpath("pkgs", "w", "index.html") + + assert index_toplevel.exists() + assert index_pkgs.exists() + assert index_w.exists() + + # Simple sanity check of some expected content + toplevel = index_toplevel.read_text() + pkgs = index_pkgs.read_text() + w = index_w.read_text() + + assert 'repodata/' in toplevel + assert 'pkgs/' in toplevel + + assert 'w/' in pkgs + + assert 'walrus-5.21-1.noarch.rpm' in w