Skip to content

Commit 6920aa9

Browse files
authored
Merge pull request #190 from fossology/fix/minor-issues
Fix/minor issues
2 parents 6605571 + d0511ee commit 6920aa9

15 files changed

Lines changed: 86 additions & 76 deletions

‎.github/workflows/foss_cli_tests.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ jobs:
2828
- name: Install host dependencies
2929
run: |
3030
apt-get -qq update
31-
apt-get install -qq gcc git nmap xz-utils
31+
apt-get install -qq bzip2 gcc git nmap xz-utils
3232
rm -rf /var/lib/apt/lists/*
3333
- name: Install Python dependencies
3434
run: |
3535
pip install poetry
3636
poetry install --with=dev
3737
- name: Install files in shared volume
3838
run: |
39-
tar xJf tests/files/base-files_11.tar.xz -C /tmp
39+
tar xvf tests/files/base-files_10.3-debian10-test.tar.bz2 -C /tmp
4040
- name: Check services
4141
run: nmap fossology -p 80
4242
- name: Run tests

‎.github/workflows/fossologytests.yml‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,33 @@ jobs:
2828
- name: Install host dependencies
2929
run: |
3030
apt-get -qq update
31-
apt-get install -qq gcc git nmap xz-utils
31+
apt-get install -qq bzip2 curl gcc git nmap xz-utils
3232
rm -rf /var/lib/apt/lists/*
3333
- name: Install Python dependencies
3434
run: |
3535
pip install poetry
3636
poetry install --with=dev
3737
- name: Install files in shared volume
3838
run: |
39-
tar xJf tests/files/base-files_11.tar.xz -C /tmp
39+
tar xvf tests/files/base-files_10.3-debian10-test.tar.bz2 -C /tmp
4040
- name: Check services
41-
run: nmap fossology -p 80
41+
run: |
42+
nmap fossology -p 80
43+
for i in $(seq 1 60); do
44+
if curl --fail --silent --show-error http://fossology/repo/api/v1/info > /dev/null; then
45+
echo "Fossology API is up"
46+
break
47+
fi
48+
if [ "$i" -eq 60 ]; then
49+
echo "Fossology API did not become ready in time" >&2
50+
exit 1
51+
fi
52+
echo "Waiting for Fossology API... attempt $i/60"
53+
sleep 5
54+
done
4255
- name: Run tests
4356
run: |
44-
poetry run coverage run --source=fossology -m pytest
57+
poetry run coverage run --source=fossology -m pytest --ignore-glob="tests/test_foss_cli*.py"
4558
poetry run coverage report -m
4659
- name: upload codecoverage results only if the PR originates from the upstream repository
4760
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}

‎README.rst‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Fossology Python also offers a command line interface to simplify interactions w
148148

149149
.. code:: bash
150150
151-
$ foss_cli -vv upload_file tests/files/zlib_1.2.11.dfsg-0ubuntu2.debian.tar.xz \
151+
$ foss_cli -vv upload_file tests/files/base-files_10.3-debian10-test.tar.bz2 \
152152
--folder_name FossFolder
153153
--access_level public
154154
@@ -200,6 +200,25 @@ Develop
200200
To avoid running the whole testsuite during development of a new branch with changing only touching the code related
201201
to the CLI, name your branch ``feat/cli-{something}`` and only the ``test_foss_cli_*`` will run in the pull request context.
202202
203+
**Testing Requirements for New Code**
204+
205+
When contributing new features or API extensions, ensure comprehensive test coverage using these guidelines:
206+
207+
- **Unit Tests with Responses Framework**: Use the `responses <https://github.com/getsentry/responses>`_ library
208+
to mock HTTP requests and provide unit test coverage for all code paths. This allows fast, isolated testing without
209+
requiring a running Fossology instance. See existing tests in ``tests/`` directory for examples of the
210+
``@responses.activate`` decorator pattern.
211+
212+
- **Integration Tests**: Provide at least one generic integration test that runs against an actual Fossology instance.
213+
These tests validate real API behavior and can be executed:
214+
215+
- **Locally**: Run against a Fossology Docker container (see the Test section below for setup instructions)
216+
- **In CI/CD**: Tests automatically run via GitHub Actions in the `API Tests job
217+
<https://github.com/fossology/fossology-python/.github/workflows/fossologytests.yml>`_
218+
219+
- **Coverage Requirements**: All new code paths must be covered by tests. Pull requests without adequate test
220+
coverage will not be accepted. Use ``poetry run coverage`` to verify coverage locally.
221+
203222
**AI-Assisted Contributions**
204223
205224
AI coding agents are active in this repository. If you are an AI agent or using AI-assisted tooling,
@@ -275,7 +294,8 @@ The testsuite available in this project expects a running Fossology instance und
275294
.. code:: shell
276295
277296
docker pull fossology/fossology
278-
tar xJf tests/files/base-files_11.tar.xz -C /tmp
297+
tar xvf tests/files/base-files_10.3-debian10-test.tar.bz2 -C /tmp
298+
chmod a+r /tmp/base-files-10.3
279299
docker run --mount src="/tmp",dst=/tmp,type=bind --name fossology -p 80:80 fossology/fossology
280300
281301
- Start the complete test suite or a specific test case (and generate coverage report):

‎docs-source/conf.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
copyright = "2021, Siemens AG"
2323

2424
# The full version, including major/minor/patch tags
25-
release = "3.5.0"
25+
release = "3.6.0"
2626

2727

2828
# -- General configuration ---------------------------------------------------

‎docs-source/sample_workflow.rst‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ We first get an example file from our github repository test environment and the
111111
upload it to the server.
112112

113113

114-
>>> filename = "my_base-files_11.tar.xz"
114+
>>> filename = "my_base-files_10.3-debian10-test.tar.bz2"
115115
>>> path_to_upload_file = pathlib.Path.cwd() / filename
116116
>>> if not path_to_upload_file.exists():
117-
... url = "https://github.com/fossology/fossology-python/blob/master/tests/files/base-files_11.tar.xz"
117+
... url = "https://github.com/fossology/fossology-python/blob/master/tests/files/base-files_10.3-debian10-test.tar.bz2"
118118
... r = requests.get(url)
119119
... with open(path_to_upload_file, "wb") as fp:
120120
... len = fp.write(r.content)

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ version_toml = [
3232
"pyproject.toml:tool.poetry.version",
3333
]
3434
version_variables = [
35-
"docs-source/conf.py:version",
35+
"docs-source/conf.py:release",
3636
]
3737

3838
[tool.poetry.dependencies]

‎tests/conftest.py‎

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,6 @@ def foss_v2(foss_server: str, foss_token: str, foss_agents: Agents):
185185
foss.close()
186186

187187

188-
@pytest.fixture(scope="session")
189-
def test_file_path() -> str:
190-
return "tests/files/base-files_11.tar.xz"
191-
192-
193188
@pytest.fixture(scope="session")
194189
def upload_folder(foss: fossology.Fossology) -> Generator:
195190
name = "UploadFolderTest"
@@ -227,7 +222,7 @@ def upload(
227222
time.sleep(5)
228223

229224

230-
@pytest.fixture(scope="function")
225+
@pytest.fixture(scope="session")
231226
def upload_v2(
232227
foss_v2: fossology.Fossology,
233228
test_file_path: str,
@@ -248,23 +243,11 @@ def upload_v2(
248243

249244
@pytest.fixture(scope="session")
250245
def upload_with_jobs(
251-
foss: fossology.Fossology, test_file_path: str, foss_schedule_agents: dict
252-
) -> Generator:
253-
upload = foss.upload_file(
254-
foss.rootFolder,
255-
file=test_file_path,
256-
description="Test upload_with_jobs via fossology-python lib",
257-
access_level=AccessLevel.PUBLIC,
258-
wait_time=5,
259-
)
260-
if upload:
261-
jobs_lookup(foss, upload)
262-
foss.schedule_jobs(foss.rootFolder, upload, foss_schedule_agents)
263-
jobs_lookup(foss, upload)
264-
yield upload
265-
foss.delete_upload(upload)
266-
time.sleep(5)
267-
246+
foss: fossology.Fossology, upload: Upload, foss_schedule_agents: dict
247+
):
248+
foss.schedule_jobs(foss.rootFolder, upload, foss_schedule_agents)
249+
jobs_lookup(foss, upload)
250+
return upload
268251

269252
@pytest.fixture(scope="session")
270253
def created_foss_user(foss: fossology.Fossology, foss_user: dict) -> Generator:
@@ -275,15 +258,9 @@ def created_foss_user(foss: fossology.Fossology, foss_user: dict) -> Generator:
275258
foss.delete_user(user)
276259

277260

278-
# foss_cli specific
279261
@pytest.fixture(scope="session")
280-
def click_test_file_path() -> str:
281-
return "tests/files"
282-
283-
284-
@pytest.fixture(scope="session")
285-
def click_test_file() -> str:
286-
return "zlib_1.2.11.dfsg-0ubuntu2.debian.tar.xz"
262+
def test_file_path() -> str:
263+
return "tests/files/base-files_10.3-debian10-test.tar.bz2"
287264

288265

289266
@pytest.fixture(scope="session")

‎tests/files/base-files_11.tar.xz‎

-63.8 KB
Binary file not shown.
-17.9 KB
Binary file not shown.

‎tests/test_foss_cli_flow_cmds.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
from fossology import foss_cli
1111

1212

13-
def test_upload_file(runner, click_test_file_path, click_test_file, click_test_dict):
13+
def test_upload_file(runner, test_file_path, click_test_dict):
1414
"""Test the CLI."""
1515
d = click_test_dict
16-
q_path = PurePath(click_test_file_path, click_test_file)
16+
q_path = PurePath(test_file_path)
1717
result = runner.invoke(
1818
foss_cli.cli,
1919
[
@@ -30,15 +30,15 @@ def test_upload_file(runner, click_test_file_path, click_test_file, click_test_d
3030
assert result.exit_code == 0
3131
assert d["VERBOSE"] == 2
3232
assert d["DEBUG"]
33-
assert d["UPLOAD"].uploadname == click_test_file
33+
assert d["UPLOAD"].uploadname == q_path.name
3434
assert "Summary of upload" in result.output
3535
time.sleep(2)
3636
result = runner.invoke(
3737
foss_cli.cli,
3838
[
3939
"-vv",
4040
"delete_upload",
41-
click_test_file,
41+
q_path.name,
4242
],
4343
obj=d,
4444
catch_exceptions=False,

0 commit comments

Comments
 (0)