diff --git a/.github/workflows/linters.yaml b/.github/workflows/linters.yaml index 6648427c..86293445 100644 --- a/.github/workflows/linters.yaml +++ b/.github/workflows/linters.yaml @@ -9,81 +9,56 @@ on: - release_* jobs: - # disable bandit because of the underlying docker image issue - # bandit: - # name: Bandit analyzer for Python ${{ matrix.os.python }} on - # ${{ matrix.os.name }}-${{ matrix.os.version }} - # runs-on: ubuntu-latest - - # strategy: - # fail-fast: false - # matrix: - # os: - # - name: centos - # version: 7 - # python: 3 - # engine: docker - - # - name: fedora - # version: 34 - # python: 3 - # engine: docker - - # steps: - # - uses: actions/checkout@v1 - - # - run: ./test.sh - # env: - # OS: ${{ matrix.os.name }} - # OS_VERSION: ${{ matrix.os.version }} - # PYTHON_VERSION: ${{ matrix.os.python }} - # ENGINE: ${{ matrix.os.engine }} - # ACTION: bandit - flake8: - name: Flake8 for Python 3 + name: Flake8 for Python ${{ matrix.python-version }} runs-on: ubuntu-latest + strategy: + matrix: + python-version: [ "3.8" ] + steps: - - name: Check out repo - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip setuptools tox - - name: Run flake8 for Python 3 - uses: containerbuildsystem/actions/flake8@master + - name: Run flake8 on python${{ matrix.python-version }} + run: python -m tox -e flake8 - # markdownlint: - # name: Markdownlint - # runs-on: ubuntu-latest + markdownlint: + name: Markdownlint + runs-on: ubuntu-latest - # steps: - # - name: Check out repo - # uses: actions/checkout@v2 + steps: + - name: Check out repo + uses: actions/checkout@v2 - # - name: Run markdownlint - # uses: containerbuildsystem/actions/markdownlint@master + - name: Run markdownlint + uses: containerbuildsystem/actions/markdownlint@master pylint: - name: Pylint analyzer for Python ${{ matrix.os.python }} + name: Pylint analyzer for Python ${{ matrix.python-version }} runs-on: ubuntu-latest strategy: matrix: - os: - - name: fedora - version: 34 - python: 3 - engine: docker + python-version: [ "3.8" ] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip setuptools tox - - run: ./test.sh - env: - OS: ${{ matrix.os.name }} - OS_VERSION: ${{ matrix.os.version }} - PYTHON_VERSION: ${{ matrix.os.python }} - ENGINE: ${{ matrix.os.engine }} - ACTION: pylint + - name: Run pylint on python${{ matrix.python-version }} + run: python -m tox -e pylint shellcheck: name: Shellcheck @@ -95,3 +70,43 @@ jobs: - name: Run ShellCheck uses: containerbuildsystem/actions/shellcheck@master + +# mypy: +# name: mypy type checker for Python ${{ matrix.python-version }} +# runs-on: ubuntu-latest +# +# strategy: +# matrix: +# python-version: [ "3.8" ] +# +# steps: +# - uses: actions/checkout@v3 +# - uses: actions/setup-python@v4 +# with: +# python-version: ${{ matrix.python-version }} +# - name: Install dependencies +# run: | +# python -m pip install --upgrade pip setuptools tox +# +# - name: Run mypy on python${{ matrix.python-version }} +# run: python -m tox -e mypy + + bandit: + name: Bandit analyzer for Python ${{ matrix.python-version }} + runs-on: ubuntu-latest + + strategy: + matrix: + python-version: [ "3.8" ] + + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip setuptools tox + + - name: Run bandit analyzer on python${{ matrix.python-version }} + run: python -m tox -e bandit diff --git a/.github/workflows/unittests.yaml b/.github/workflows/unittests.yaml index 4c45b551..b8af2770 100644 --- a/.github/workflows/unittests.yaml +++ b/.github/workflows/unittests.yaml @@ -10,68 +10,51 @@ on: jobs: test: - name: Python ${{ matrix.os.python }} tests on ${{ matrix.os.name }}-${{ matrix.os.version }} - runs-on: ubuntu-18.04 + name: Python ${{ matrix.python-version }} tests + runs-on: ubuntu-latest strategy: fail-fast: false matrix: - os: - - name: centos - version: 7 - python: 3 - engine: docker - - - name: fedora - version: 33 - python: 3 - engine: docker - - - name: fedora - version: 34 - python: 3 - engine: docker + python-version: ["3.6", "3.7", "3.8"] steps: - - name: Check out repo - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip setuptools tox - - name: pytests via test.sh - env: - OS: ${{ matrix.os.name }} - OS_VERSION: ${{ matrix.os.version }} - PYTHON_VERSION: ${{ matrix.os.python }} - ENGINE: ${{ matrix.os.engine }} - run: ./test.sh + - name: Run unittests on python${{ matrix.python-version }} + run: python -m tox -e test - name: Upload pytest html report uses: actions/upload-artifact@v2 if: failure() with: - path: __pytest_reports/atomic-reactor-unit-tests.html - name: atomic-reactor-unit-tests_${{ matrix.os.name }}_${{ matrix.os.version }}.python${{ matrix.os.python }}.html + path: __pytest_reports/charon-unit-tests.html + name: charon-unit-tests_python${{ matrix.os.python }}.html + - name: Run coveralls-python env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - COVERALLS_FLAG_NAME: ${{ matrix.os.name }}-${{ matrix.os.version }}-python${{ matrix.os.python }} + COVERALLS_FLAG_NAME: python${{ matrix.python-version }} COVERALLS_PARALLEL: true run: | - pip3 install --upgrade pip - pip3 install --upgrade setuptools - pip3 install --upgrade coveralls - /home/runner/.local/bin/coveralls --service=github + python -m pip install --upgrade coveralls + python -m coveralls --service=github coveralls-finish: name: Finish coveralls-python needs: test - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest steps: - name: Finished run: | - pip3 install --upgrade pip - pip3 install --upgrade setuptools - pip3 install --upgrade coveralls + pip3 install --upgrade pip setuptools coveralls /home/runner/.local/bin/coveralls --finish --service=github env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/charon/config.py b/charon/config.py index ed479bea..bfbdb743 100644 --- a/charon/config.py +++ b/charon/config.py @@ -61,7 +61,7 @@ def get_config() -> Optional[CharonConfig]: def get_template(template_file: str) -> str: template = os.path.join( - os.getenv("HOME"), ".charon/template", template_file + os.getenv("HOME", ''), ".charon/template", template_file ) if os.path.isfile(template): with open(template, encoding="utf-8") as file_: diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index fe70ffdf..00000000 --- a/pytest.ini +++ /dev/null @@ -1,3 +0,0 @@ -[pytest] -addopts = -ra --color=auto --html=__pytest_reports/atomic-reactor-unit-tests.html --self-contained-html -render_collapsed = True diff --git a/test-coverage.sh b/test-coverage.sh deleted file mode 100755 index 050feacd..00000000 --- a/test-coverage.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -pytest --cov charon -v --cov-report html diff --git a/test.sh b/test.sh deleted file mode 100755 index 6a234531..00000000 --- a/test.sh +++ /dev/null @@ -1,109 +0,0 @@ -#!/bin/bash -set -eux - -# Prepare env vars -ENGINE=${ENGINE:="podman"} -OS=${OS:="centos"} -OS_VERSION=${OS_VERSION:="7"} -PYTHON_VERSION=${PYTHON_VERSION:="3"} -ACTION=${ACTION:="test"} -IMAGE="$OS:$OS_VERSION" -CONTAINER_NAME="charon-$OS-$OS_VERSION-py$PYTHON_VERSION" - -# Use arrays to prevent globbing and word splitting -engine_mounts=(-v "$PWD":"$PWD":z) -for dir in ${EXTRA_MOUNT:-}; do - engine_mounts=("${engine_mounts[@]}" -v "$dir":"$dir":z) -done - -# Create or resurrect container if needed -if [[ $($ENGINE ps -qa -f name="$CONTAINER_NAME" | wc -l) -eq 0 ]]; then - $ENGINE run --name "$CONTAINER_NAME" -d "${engine_mounts[@]}" -w "$PWD" -ti "$IMAGE" sleep infinity -elif [[ $($ENGINE ps -q -f name="$CONTAINER_NAME" | wc -l) -eq 0 ]]; then - echo found stopped existing container, restarting. volume mounts cannot be updated. - $ENGINE container start "$CONTAINER_NAME" -fi - -function setup_charon() { - RUN="$ENGINE exec -i $CONTAINER_NAME" - PYTHON="python$PYTHON_VERSION" - PIP_PKG="$PYTHON-pip" - PIP="pip$PYTHON_VERSION" - PKG="dnf" - PKG_EXTRA=(dnf-plugins-core git "$PYTHON"-pylint) - BUILDDEP=(dnf builddep) - if [[ $OS == "centos" ]]; then - PKG="yum" - PKG_EXTRA=(yum-utils git "$PYTHON"-pylint) - BUILDDEP=(yum-builddep) - ENABLE_REPO= - else - ENABLE_REPO="--enablerepo=updates-testing" - fi - - - PIP_INST=("$PIP" install --index-url "${PYPI_INDEX:-https://pypi.org/simple}") - - if [[ $OS == "centos" ]]; then - # Don't let builddep enable *-source repos since they give 404 errors - $RUN rm -f /etc/yum.repos.d/CentOS-Sources.repo - # $RUN rm -f /etc/yum.repos.d/CentOS-Linux-AppStream.repo - # $RUN rm -f /etc/yum.repos.d/CentOS-Linux-BaseOS.repo - # This has to run *before* we try installing anything from EPEL - $RUN $PKG $ENABLE_REPO install -y epel-release - fi - - # RPM install basic dependencies - $RUN $PKG $ENABLE_REPO install -y "${PKG_EXTRA[@]}" - # RPM install build dependencies for charon - $RUN "${BUILDDEP[@]}" -y charon.spec - - # Install package - $RUN $PKG install -y $PIP_PKG - - # Upgrade pip to provide latest features for successful installation - $RUN "${PIP_INST[@]}" --upgrade pip - - if [[ $OS == centos ]]; then - # Pip install/upgrade setuptools. Older versions of setuptools don't understand the - # environment markers used by docker-squash's requirements, also - # CentOS needs to have setuptools updates to make pytest-cov work - $RUN "${PIP_INST[@]}" --upgrade setuptools - fi - - # install with RPM_PY_SYS=true to avoid error caused by installing on system python - #$RUN sh -c "RPM_PY_SYS=true ${PIP_INST[*]} rpm-py-installer" - # Setuptools install charon from source - $RUN $PIP install . - - # Pip install packages for unit tests - $RUN "${PIP_INST[@]}" -r tests/requirements.txt -} - -case ${ACTION} in -"test") - setup_charon - TEST_CMD="coverage run --source=charon -m pytest tests" - ;; -"pylint") - setup_charon - PACKAGES='charon tests' - TEST_CMD="${PYTHON} -m pylint ${PACKAGES}" - ;; -"bandit") - setup_charon - $RUN "${PIP_INST[@]}" bandit - TEST_CMD="bandit-baseline -r charon -ll -ii" - ;; -*) - echo "Unknown action: ${ACTION}" - exit 2 - ;; -esac - -# Run tests -# shellcheck disable=SC2086 -$RUN ${TEST_CMD} "$@" - -echo "To run tests again:" -echo "$RUN ${TEST_CMD}" diff --git a/tests/base.py b/tests/base.py index b2d26cac..f6f48559 100644 --- a/tests/base.py +++ b/tests/base.py @@ -27,6 +27,7 @@ from tests.commons import TEST_BUCKET, TEST_MANIFEST_BUCKET from moto import mock_s3 +from tests.constants import HERE SHORT_TEST_PREFIX = "ga" LONG_TEST_PREFIX = "earlyaccess/all" @@ -71,7 +72,7 @@ def change_home(self): def __prepare_template(self, config_base): template_path = os.path.join(config_base, 'template') os.mkdir(config_base) - shutil.copytree(os.path.join(os.getcwd(), "template"), template_path) + shutil.copytree(os.path.join(HERE, "../template"), template_path) if not os.path.isdir(template_path): self.fail("Template initilization failed!") diff --git a/tests/constants.py b/tests/constants.py new file mode 100644 index 00000000..2e6d111f --- /dev/null +++ b/tests/constants.py @@ -0,0 +1,19 @@ +""" +Copyright (C) 2022 Red Hat, Inc. (https://github.com/Commonjava/charon) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" +import os + +HERE = os.path.dirname(__file__) +INPUTS = os.path.join(HERE, 'input') diff --git a/tests/requirements.txt b/tests/requirements.txt index de68f7b1..04c28c8d 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,9 +1,8 @@ flexmock>=0.10.6 responses>=0.9.0,<0.10.8 -pytest>=5.0 +pytest<=7.1.3 pytest-cov pytest-html flake8 requests-mock moto==3.0.2.dev12 - diff --git a/tests/test_archive.py b/tests/test_archive.py index 9e303028..0e2ac09a 100644 --- a/tests/test_archive.py +++ b/tests/test_archive.py @@ -2,12 +2,14 @@ from charon.utils.archive import NpmArchiveType, detect_npm_archive import os +from tests.constants import INPUTS + class ArchiveTest(BaseTest): def test_detect_package(self): - mvn_tarball = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + mvn_tarball = os.path.join(INPUTS, "commons-client-4.5.6.zip") self.assertEqual(NpmArchiveType.NOT_NPM, detect_npm_archive(mvn_tarball)) - npm_tarball = os.path.join(os.getcwd(), "tests/input/code-frame-7.14.5.tgz") + npm_tarball = os.path.join(INPUTS, "code-frame-7.14.5.tgz") self.assertEqual(NpmArchiveType.TAR_FILE, detect_npm_archive(npm_tarball)) def test_download_archive(self): diff --git a/tests/test_manifest_del.py b/tests/test_manifest_del.py index 413caa57..fc5ff35c 100644 --- a/tests/test_manifest_del.py +++ b/tests/test_manifest_del.py @@ -25,6 +25,7 @@ TEST_BUCKET, TEST_MANIFEST_BUCKET, TEST_TARGET, COMMONS_CLIENT_456_MANIFEST, CODE_FRAME_7_14_5_MANIFEST ) +from tests.constants import INPUTS @mock_s3 @@ -38,11 +39,11 @@ def test_maven_manifest_delete(self): self.assertEqual(1, len(manifests)) self.assertIn(COMMONS_CLIENT_456_MANIFEST, manifests) - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") product = "commons-client-4.5.6" handle_maven_del( test_zip, product, - buckets=[(TEST_TARGET, TEST_BUCKET, None, None)], + buckets=[(TEST_TARGET, TEST_BUCKET, '', '')], dir_=self.tempdir, do_index=False, manifest_bucket_name=TEST_MANIFEST_BUCKET @@ -59,11 +60,11 @@ def test_npm_manifest_delete(self): self.assertEqual(1, len(manifests)) self.assertIn(CODE_FRAME_7_14_5_MANIFEST, manifests) - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.14.5.tgz") + test_tgz = os.path.join(INPUTS, "code-frame-7.14.5.tgz") product = "code-frame-7.14.5" handle_npm_del( test_tgz, product, - buckets=[(TEST_TARGET, TEST_BUCKET, None, None)], + buckets=[(TEST_TARGET, TEST_BUCKET, '', '')], dir_=self.tempdir, do_index=False, manifest_bucket_name=TEST_MANIFEST_BUCKET @@ -73,22 +74,22 @@ def test_npm_manifest_delete(self): self.assertEqual(0, len(manifests)) def __prepare_maven_content(self): - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") product = "commons-client-4.5.6" handle_maven_uploading( test_zip, product, - buckets=[(TEST_TARGET, TEST_BUCKET, None, None)], + buckets=[(TEST_TARGET, TEST_BUCKET, '', '')], dir_=self.tempdir, do_index=False, manifest_bucket_name=TEST_MANIFEST_BUCKET ) def __prepare_npm_content(self): - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.14.5.tgz") + test_tgz = os.path.join(INPUTS, "code-frame-7.14.5.tgz") product = "code-frame-7.14.5" handle_npm_uploading( test_tgz, product, - buckets=[(TEST_TARGET, TEST_BUCKET, None, DEFAULT_REGISTRY)], + buckets=[(TEST_TARGET, TEST_BUCKET, '', DEFAULT_REGISTRY)], dir_=self.tempdir, do_index=False, manifest_bucket_name=TEST_MANIFEST_BUCKET diff --git a/tests/test_manifest_upload.py b/tests/test_manifest_upload.py index ec16dcc0..e6aa43e9 100644 --- a/tests/test_manifest_upload.py +++ b/tests/test_manifest_upload.py @@ -26,17 +26,18 @@ COMMONS_CLIENT_META_NUM, COMMONS_CLIENT_456_MANIFEST, COMMONS_CLIENT_456_FILES, COMMONS_LOGGING_FILES, CODE_FRAME_7_14_5_MANIFEST, CODE_FRAME_7_14_5_FILES ) +from tests.constants import INPUTS @mock_s3 class ManifestUploadTest(PackageBaseTest): def test_maven_manifest_upload(self): - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") product = "commons-client-4.5.6" handle_maven_uploading( test_zip, product, - buckets=[(TEST_TARGET, TEST_BUCKET, None, None)], + buckets=[(TEST_TARGET, TEST_BUCKET, '', '')], dir_=self.tempdir, do_index=False, manifest_bucket_name=TEST_MANIFEST_BUCKET @@ -62,11 +63,11 @@ def test_maven_manifest_upload(self): self.assertIn(f, manifest_content) def test_npm_manifest_upload(self): - test_zip = os.path.join(os.getcwd(), "tests/input/code-frame-7.14.5.tgz") + test_zip = os.path.join(INPUTS, "code-frame-7.14.5.tgz") product = "code-frame-7.14.5" handle_npm_uploading( test_zip, product, - buckets=[(TEST_TARGET, TEST_BUCKET, None, DEFAULT_REGISTRY)], + buckets=[(TEST_TARGET, TEST_BUCKET, '', DEFAULT_REGISTRY)], dir_=self.tempdir, do_index=False, manifest_bucket_name=TEST_MANIFEST_BUCKET diff --git a/tests/test_maven_del.py b/tests/test_maven_del.py index 338c103b..c26e6d4a 100644 --- a/tests/test_maven_del.py +++ b/tests/test_maven_del.py @@ -27,6 +27,8 @@ from moto import mock_s3 import os +from tests.constants import INPUTS + @mock_s3 class MavenDeleteTest(PackageBaseTest): @@ -48,12 +50,12 @@ def test_ignore_del(self): product_459 = "commons-client-4.5.9" product_mix = [product_456, product_459] - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") handle_maven_del( test_zip, product_456, ignore_patterns=[".*.sha1"], - buckets=[(None, TEST_BUCKET, None, None)], + buckets=[('', TEST_BUCKET, '', '')], dir_=self.tempdir, do_index=False ) @@ -98,11 +100,11 @@ def test_ignore_del(self): def __test_prefix_deletion(self, prefix: str): self.__prepare_content(prefix) - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") product_456 = "commons-client-4.5.6" handle_maven_del( test_zip, product_456, - buckets=[(None, TEST_BUCKET, prefix, None)], + buckets=[('', TEST_BUCKET, prefix, '')], dir_=self.tempdir, do_index=False ) @@ -173,10 +175,10 @@ def __test_prefix_deletion(self, prefix: str): self.assertIn("1.2", meta_content_logging) self.assertIn("1.2", meta_content_logging) - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.9.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.9.zip") handle_maven_del( test_zip, product_459, - buckets=[(None, TEST_BUCKET, prefix, None)], + buckets=[('', TEST_BUCKET, prefix, '')], dir_=self.tempdir, do_index=False ) @@ -185,20 +187,20 @@ def __test_prefix_deletion(self, prefix: str): self.assertEqual(0, len(objs)) def __prepare_content(self, prefix=None): - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") product_456 = "commons-client-4.5.6" handle_maven_uploading( test_zip, product_456, - buckets=[(None, TEST_BUCKET, prefix, None)], + buckets=[('', TEST_BUCKET, prefix, '')], dir_=self.tempdir, do_index=False ) - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.9.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.9.zip") product_459 = "commons-client-4.5.9" handle_maven_uploading( test_zip, product_459, - buckets=[(None, TEST_BUCKET, prefix, None)], + buckets=[('', TEST_BUCKET, prefix, '')], dir_=self.tempdir, do_index=False ) diff --git a/tests/test_maven_del_multi_tgts.py b/tests/test_maven_del_multi_tgts.py index dea261ff..ffc60954 100644 --- a/tests/test_maven_del_multi_tgts.py +++ b/tests/test_maven_del_multi_tgts.py @@ -27,6 +27,8 @@ from moto import mock_s3 import os +from tests.constants import INPUTS + @mock_s3 class MavenDeleteMultiTgtsTest(PackageBaseTest): @@ -58,12 +60,12 @@ def test_ignore_del(self): product_459 = "commons-client-4.5.9" product_mix = [product_456, product_459] - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") handle_maven_del( test_zip, product_456, ignore_patterns=[".*.sha1"], - buckets=[(None, TEST_BUCKET, None, None)], + buckets=[('', TEST_BUCKET, '', '')], dir_=self.tempdir, do_index=False ) @@ -108,8 +110,8 @@ def test_ignore_del(self): def __test_prefix_deletion(self, prefix: str): self.__prepare_content(prefix) - targets_ = [(None, TEST_BUCKET, prefix, None), (None, TEST_BUCKET_2, prefix, None)] - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + targets_ = [('', TEST_BUCKET, prefix, ''), ('', TEST_BUCKET_2, prefix, '')] + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") product_456 = "commons-client-4.5.6" handle_maven_del( test_zip, product_456, @@ -238,7 +240,7 @@ def __test_prefix_deletion(self, prefix: str): msg=f'{bucket_name}' ) - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.9.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.9.zip") handle_maven_del( test_zip, product_459, buckets=targets_, @@ -253,9 +255,9 @@ def __test_prefix_deletion(self, prefix: str): self.assertEqual(0, len(objs), msg=f'{bucket_name}') def __prepare_content(self, prefix=None): - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") product_456 = "commons-client-4.5.6" - targets_ = [(None, TEST_BUCKET, prefix, None), (None, TEST_BUCKET_2, prefix, None)] + targets_ = [('', TEST_BUCKET, prefix, ''), ('', TEST_BUCKET_2, prefix, '')] handle_maven_uploading( test_zip, product_456, buckets=targets_, @@ -263,7 +265,7 @@ def __prepare_content(self, prefix=None): do_index=False ) - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.9.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.9.zip") product_459 = "commons-client-4.5.9" handle_maven_uploading( test_zip, product_459, diff --git a/tests/test_maven_index.py b/tests/test_maven_index.py index e136adee..d5647ecd 100644 --- a/tests/test_maven_index.py +++ b/tests/test_maven_index.py @@ -26,16 +26,18 @@ from moto import mock_s3 import os +from tests.constants import INPUTS + @mock_s3 class MavenFileIndexTest(PackageBaseTest): def test_uploading_index(self): - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") product = "commons-client-4.5.6" handle_maven_uploading( test_zip, product, - buckets=[(None, TEST_BUCKET, None, None)], + buckets=[('', TEST_BUCKET, '', '')], dir_=self.tempdir ) @@ -75,19 +77,19 @@ def test_uploading_index(self): self.assertNotIn(PROD_INFO_SUFFIX, index_content) def test_overlap_upload_index(self): - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") product_456 = "commons-client-4.5.6" handle_maven_uploading( test_zip, product_456, - buckets=[(None, TEST_BUCKET, None, None)], + buckets=[('', TEST_BUCKET, '', '')], dir_=self.tempdir ) - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.9.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.9.zip") product_459 = "commons-client-4.5.9" handle_maven_uploading( test_zip, product_459, - buckets=[(None, TEST_BUCKET, None, None)], + buckets=[('', TEST_BUCKET, '', '')], dir_=self.tempdir ) @@ -135,11 +137,11 @@ def test_upload_index_with_root_prefix(self): self.__test_upload_index_with_prefix("/") def __test_upload_index_with_prefix(self, prefix: str): - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") product = "commons-client-4.5.6" handle_maven_uploading( test_zip, product, - buckets=[(None, TEST_BUCKET, prefix, None)], + buckets=[('', TEST_BUCKET, prefix, '')], dir_=self.tempdir ) @@ -187,11 +189,11 @@ def __test_upload_index_with_prefix(self, prefix: str): def test_deletion_index(self): self.__prepare_content() - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") product_456 = "commons-client-4.5.6" handle_maven_del( test_zip, product_456, - buckets=[(None, TEST_BUCKET, None, None)], + buckets=[('', TEST_BUCKET, '', '')], dir_=self.tempdir ) @@ -236,10 +238,10 @@ def test_deletion_index(self): self.assertNotIn(PROD_INFO_SUFFIX, index_content) product_459 = "commons-client-4.5.9" - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.9.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.9.zip") handle_maven_del( test_zip, product_459, - buckets=[(None, TEST_BUCKET, None, None)], + buckets=[('', TEST_BUCKET, '', '')], dir_=self.tempdir ) @@ -258,11 +260,11 @@ def test_deletion_index_with_root_prefix(self): def __test_deletion_index_with_prefix(self, prefix: str): self.__prepare_content(prefix) - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") product_456 = "commons-client-4.5.6" handle_maven_del( test_zip, product_456, - buckets=[(None, TEST_BUCKET, prefix, None)], + buckets=[('', TEST_BUCKET, prefix, '')], dir_=self.tempdir ) @@ -306,10 +308,10 @@ def __test_deletion_index_with_prefix(self, prefix: str): self.assertNotIn("../", index_content) self.assertNotIn(PROD_INFO_SUFFIX, index_content) - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.9.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.9.zip") handle_maven_del( test_zip, product_459, - buckets=[(None, TEST_BUCKET, prefix, None)], + buckets=[('', TEST_BUCKET, prefix, '')], dir_=self.tempdir ) @@ -317,18 +319,18 @@ def __test_deletion_index_with_prefix(self, prefix: str): self.assertEqual(0, len(objs)) def __prepare_content(self, prefix=None): - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") product_456 = "commons-client-4.5.6" handle_maven_uploading( test_zip, product_456, - buckets=[(None, TEST_BUCKET, prefix, None)], + buckets=[('', TEST_BUCKET, prefix, '')], dir_=self.tempdir ) - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.9.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.9.zip") product_459 = "commons-client-4.5.9" handle_maven_uploading( test_zip, product_459, - buckets=[(None, TEST_BUCKET, prefix, None)], + buckets=[('', TEST_BUCKET, prefix, '')], dir_=self.tempdir ) diff --git a/tests/test_maven_index_multi_tgts.py b/tests/test_maven_index_multi_tgts.py index eaf05a15..a02707f2 100644 --- a/tests/test_maven_index_multi_tgts.py +++ b/tests/test_maven_index_multi_tgts.py @@ -26,6 +26,8 @@ from moto import mock_s3 import os +from tests.constants import INPUTS + @mock_s3 class MavenFileIndexMultiTgtsTest(PackageBaseTest): @@ -40,8 +42,8 @@ def tearDown(self): super().tearDown() def test_uploading_index(self): - targets_ = [(None, TEST_BUCKET, None, None), (None, TEST_BUCKET_2, None, None)] - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + targets_ = [('', TEST_BUCKET, '', ''), ('', TEST_BUCKET_2, '', '')] + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") product = "commons-client-4.5.6" handle_maven_uploading( test_zip, product, @@ -100,8 +102,8 @@ def test_uploading_index(self): self.assertNotIn(PROD_INFO_SUFFIX, index_content, msg=f'{bucket_name}') def test_overlap_upload_index(self): - targets_ = [(None, TEST_BUCKET, None, None), (None, TEST_BUCKET_2, None, None)] - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + targets_ = [('', TEST_BUCKET, '', ''), ('', TEST_BUCKET_2, '', '')] + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") product_456 = "commons-client-4.5.6" handle_maven_uploading( test_zip, product_456, @@ -109,7 +111,7 @@ def test_overlap_upload_index(self): dir_=self.tempdir ) - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.9.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.9.zip") product_459 = "commons-client-4.5.9" handle_maven_uploading( test_zip, product_459, @@ -188,8 +190,8 @@ def test_upload_index_with_root_prefix(self): self.__test_upload_index_with_prefix("/") def __test_upload_index_with_prefix(self, prefix: str): - targets_ = [(None, TEST_BUCKET, prefix, None), (None, TEST_BUCKET_2, prefix, None)] - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + targets_ = [('', TEST_BUCKET, prefix, ''), ('', TEST_BUCKET_2, prefix, '')] + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") product = "commons-client-4.5.6" handle_maven_uploading( test_zip, product, @@ -256,11 +258,11 @@ def __test_upload_index_with_prefix(self, prefix: str): def test_deletion_index(self): self.__prepare_content() - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") product_456 = "commons-client-4.5.6" handle_maven_del( test_zip, product_456, - buckets=[(None, TEST_BUCKET, None, None)], + buckets=[('', TEST_BUCKET, '', '')], dir_=self.tempdir ) @@ -305,10 +307,10 @@ def test_deletion_index(self): self.assertNotIn(PROD_INFO_SUFFIX, index_content) product_459 = "commons-client-4.5.9" - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.9.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.9.zip") handle_maven_del( test_zip, product_459, - buckets=[(None, TEST_BUCKET, None, None)], + buckets=[('', TEST_BUCKET, '', '')], dir_=self.tempdir ) @@ -326,8 +328,8 @@ def test_deletion_index_with_root_prefix(self): def __test_deletion_index_with_prefix(self, prefix: str): self.__prepare_content(prefix) - targets_ = [(None, TEST_BUCKET, prefix, None), (None, TEST_BUCKET_2, prefix, None)] - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + targets_ = [('', TEST_BUCKET, prefix, ''), ('', TEST_BUCKET_2, prefix, '')] + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") product_456 = "commons-client-4.5.6" handle_maven_del( test_zip, product_456, @@ -397,7 +399,7 @@ def __test_deletion_index_with_prefix(self, prefix: str): ) self.assertNotIn(PROD_INFO_SUFFIX, index_content, msg=f'{bucket_name}') - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.9.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.9.zip") handle_maven_del( test_zip, product_459, buckets=targets_, @@ -411,8 +413,8 @@ def __test_deletion_index_with_prefix(self, prefix: str): self.assertEqual(0, len(objs), msg=f'{bucket_name}') def __prepare_content(self, prefix=None): - targets_ = [(None, TEST_BUCKET, prefix, None), (None, TEST_BUCKET_2, prefix, None)] - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + targets_ = [('', TEST_BUCKET, prefix, ''), ('', TEST_BUCKET_2, prefix, '')] + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") product_456 = "commons-client-4.5.6" handle_maven_uploading( test_zip, product_456, @@ -420,7 +422,7 @@ def __prepare_content(self, prefix=None): dir_=self.tempdir ) - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.9.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.9.zip") product_459 = "commons-client-4.5.9" handle_maven_uploading( test_zip, product_459, diff --git a/tests/test_maven_meta.py b/tests/test_maven_meta.py index 7c86c6c4..a905c17d 100644 --- a/tests/test_maven_meta.py +++ b/tests/test_maven_meta.py @@ -21,6 +21,7 @@ import charon.pkgs.maven as mvn import charon.utils.archive as archive from tests.base import BaseTest +from tests.constants import INPUTS class MavenMetadataTest(BaseTest): @@ -58,7 +59,7 @@ def test_parse_gavs(self): def test_gen_meta_file(self): test_zip = zipfile.ZipFile( - os.path.join(os.getcwd(), "tests/input/commons-lang3.zip") + os.path.join(INPUTS, "commons-lang3.zip") ) temp_root = os.path.join(self.tempdir, "tmp_zip") os.mkdir(temp_root) diff --git a/tests/test_maven_upload.py b/tests/test_maven_upload.py index e1a477b1..431475a8 100644 --- a/tests/test_maven_upload.py +++ b/tests/test_maven_upload.py @@ -26,6 +26,8 @@ from moto import mock_s3 import os +from tests.constants import INPUTS + @mock_s3 class MavenUploadTest(PackageBaseTest): @@ -42,19 +44,19 @@ def test_root_prefix_upload(self): self.__test_prefix_upload("/") def test_overlap_upload(self): - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") product_456 = "commons-client-4.5.6" handle_maven_uploading( test_zip, product_456, - buckets=[(None, TEST_BUCKET, None, None)], + buckets=[('', TEST_BUCKET, '', '')], dir_=self.tempdir, do_index=False ) - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.9.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.9.zip") product_459 = "commons-client-4.5.9" handle_maven_uploading( test_zip, product_459, - buckets=[(None, TEST_BUCKET, None, None)], + buckets=[('', TEST_BUCKET, '', '')], dir_=self.tempdir, do_index=False ) @@ -109,11 +111,11 @@ def test_overlap_upload(self): self.assertIn("org.apache.httpcomponents", cat_content) def test_ignore_upload(self): - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") product_456 = "commons-client-4.5.6" handle_maven_uploading( test_zip, product_456, [".*.sha1"], - buckets=[(None, TEST_BUCKET, None, None)], + buckets=[('', TEST_BUCKET, '', '')], dir_=self.tempdir, do_index=False ) @@ -138,11 +140,11 @@ def test_ignore_upload(self): self.assertNotIn(f, actual_files) def __test_prefix_upload(self, prefix: str): - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") product = "commons-client-4.5.6" handle_maven_uploading( test_zip, product, - buckets=[(None, TEST_BUCKET, prefix, None)], + buckets=[('', TEST_BUCKET, prefix, '')], dir_=self.tempdir, do_index=False ) diff --git a/tests/test_maven_upload_multi_tgts.py b/tests/test_maven_upload_multi_tgts.py index 22d517db..ffb41d20 100644 --- a/tests/test_maven_upload_multi_tgts.py +++ b/tests/test_maven_upload_multi_tgts.py @@ -27,6 +27,8 @@ from moto import mock_s3 import os +from tests.constants import INPUTS + @mock_s3 class MavenUploadMultiTgtsTest(PackageBaseTest): @@ -42,28 +44,28 @@ def tearDown(self): def test_fresh_upload(self): self.__test_prefix_upload( - [(None, TEST_BUCKET, ""), (None, TEST_BUCKET_2, "", None)] + [('', TEST_BUCKET, ""), ('', TEST_BUCKET_2, "", '')] ) def test_short_prefix_upload(self): self.__test_prefix_upload( - [(None, TEST_BUCKET, SHORT_TEST_PREFIX), (None, TEST_BUCKET_2, SHORT_TEST_PREFIX, None)] + [('', TEST_BUCKET, SHORT_TEST_PREFIX), ('', TEST_BUCKET_2, SHORT_TEST_PREFIX, '')] ) def test_long_prefix_upload(self): self.__test_prefix_upload( - [(None, TEST_BUCKET, LONG_TEST_PREFIX), (None, TEST_BUCKET_2, LONG_TEST_PREFIX, None)] + [('', TEST_BUCKET, LONG_TEST_PREFIX), ('', TEST_BUCKET_2, LONG_TEST_PREFIX, '')] ) def test_root_prefix_upload(self): - self.__test_prefix_upload([(None, TEST_BUCKET, "/", None), - (None, TEST_BUCKET_2, "/", None)]) + self.__test_prefix_upload([('', TEST_BUCKET, "/", ''), + ('', TEST_BUCKET_2, "/", '')]) def test_overlap_upload(self): - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") product_456 = "commons-client-4.5.6" targets_ = [ - (None, TEST_BUCKET, None, None), (None, TEST_BUCKET_2, None, None) + ('', TEST_BUCKET, '', ''), ('', TEST_BUCKET_2, '', '') ] handle_maven_uploading( test_zip, product_456, @@ -71,7 +73,7 @@ def test_overlap_upload(self): dir_=self.tempdir, do_index=False ) - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.9.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.9.zip") product_459 = "commons-client-4.5.9" handle_maven_uploading( test_zip, product_459, @@ -178,10 +180,10 @@ def test_overlap_upload(self): ) def test_ignore_upload(self): - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") product_456 = "commons-client-4.5.6" targets_ = [ - (None, TEST_BUCKET, None, None), (None, TEST_BUCKET_2, None, None) + ('', TEST_BUCKET, '', ''), ('', TEST_BUCKET_2, '', '') ] handle_maven_uploading( test_zip, product_456, [".*.sha1"], @@ -216,7 +218,7 @@ def test_ignore_upload(self): self.assertNotIn(f, actual_files, msg=f'{bucket_name}') def __test_prefix_upload(self, targets: List[Tuple[str, str, str, str]]): - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") product = "commons-client-4.5.6" handle_maven_uploading( test_zip, product, diff --git a/tests/test_npm_del.py b/tests/test_npm_del.py index a58d4a95..ad2b1f8e 100644 --- a/tests/test_npm_del.py +++ b/tests/test_npm_del.py @@ -20,6 +20,7 @@ from charon.storage import CHECKSUM_META_KEY from tests.base import LONG_TEST_PREFIX, SHORT_TEST_PREFIX, PackageBaseTest from tests.commons import TEST_BUCKET, CODE_FRAME_7_14_5_FILES, CODE_FRAME_META +from tests.constants import INPUTS @mock_s3 @@ -39,11 +40,11 @@ def test_npm_deletion_with_root_prefix(self): def __test_prefix(self, prefix: str = None): self.__prepare_content(prefix) - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.14.5.tgz") + test_tgz = os.path.join(INPUTS, "code-frame-7.14.5.tgz") product_7_14_5 = "code-frame-7.14.5" handle_npm_del( test_tgz, product_7_14_5, - buckets=[(None, TEST_BUCKET, prefix, None)], + buckets=[('', TEST_BUCKET, prefix, '')], dir_=self.tempdir, do_index=False ) @@ -84,28 +85,28 @@ def __test_prefix(self, prefix: str = None): self.assertIn("\"license\": \"MIT\"", meta_content_client) self.assertIn("\"dist_tags\": {\"latest\": \"7.15.8\"}", meta_content_client) - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.15.8.tgz") + test_tgz = os.path.join(INPUTS, "code-frame-7.15.8.tgz") handle_npm_del( test_tgz, product_7_15_8, - buckets=[(None, TEST_BUCKET, prefix, None)], + buckets=[('', TEST_BUCKET, prefix, '')], dir_=self.tempdir, do_index=False ) objs = list(test_bucket.objects.all()) self.assertEqual(0, len(objs)) def __prepare_content(self, prefix: str = None): - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.14.5.tgz") + test_tgz = os.path.join(INPUTS, "code-frame-7.14.5.tgz") product_7_14_5 = "code-frame-7.14.5" handle_npm_uploading( test_tgz, product_7_14_5, - buckets=[(None, TEST_BUCKET, prefix, DEFAULT_REGISTRY)], + buckets=[('', TEST_BUCKET, prefix, DEFAULT_REGISTRY)], dir_=self.tempdir, do_index=False ) - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.15.8.tgz") + test_tgz = os.path.join(INPUTS, "code-frame-7.15.8.tgz") product_7_15_8 = "code-frame-7.15.8" handle_npm_uploading( test_tgz, product_7_15_8, - buckets=[(None, TEST_BUCKET, prefix, DEFAULT_REGISTRY)], + buckets=[('', TEST_BUCKET, prefix, DEFAULT_REGISTRY)], dir_=self.tempdir, do_index=False ) diff --git a/tests/test_npm_del_multi_tgts.py b/tests/test_npm_del_multi_tgts.py index b0e3880b..1746fba5 100644 --- a/tests/test_npm_del_multi_tgts.py +++ b/tests/test_npm_del_multi_tgts.py @@ -20,6 +20,7 @@ from charon.storage import CHECKSUM_META_KEY from tests.base import LONG_TEST_PREFIX, SHORT_TEST_PREFIX, PackageBaseTest from tests.commons import TEST_BUCKET, CODE_FRAME_7_14_5_FILES, CODE_FRAME_META, TEST_BUCKET_2 +from tests.constants import INPUTS @mock_s3 @@ -48,8 +49,8 @@ def test_npm_deletion_with_root_prefix(self): def __test_prefix(self, prefix: str = None): self.__prepare_content(prefix) - targets_ = [(None, TEST_BUCKET, prefix, None), (None, TEST_BUCKET_2, prefix, None)] - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.14.5.tgz") + targets_ = [('', TEST_BUCKET, prefix, ''), ('', TEST_BUCKET_2, prefix, '')] + test_tgz = os.path.join(INPUTS, "code-frame-7.14.5.tgz") product_7_14_5 = "code-frame-7.14.5" handle_npm_del( test_tgz, product_7_14_5, @@ -120,7 +121,7 @@ def __test_prefix(self, prefix: str = None): meta_content_client, msg=f'{bucket_name}' ) - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.15.8.tgz") + test_tgz = os.path.join(INPUTS, "code-frame-7.15.8.tgz") handle_npm_del( test_tgz, product_7_15_8, buckets=targets_, @@ -133,9 +134,9 @@ def __test_prefix(self, prefix: str = None): self.assertEqual(0, len(objs)) def __prepare_content(self, prefix: str = None): - targets_ = [(None, TEST_BUCKET, prefix, DEFAULT_REGISTRY), - (None, TEST_BUCKET_2, prefix, DEFAULT_REGISTRY)] - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.14.5.tgz") + targets_ = [('', TEST_BUCKET, prefix, DEFAULT_REGISTRY), + ('', TEST_BUCKET_2, prefix, DEFAULT_REGISTRY)] + test_tgz = os.path.join(INPUTS, "code-frame-7.14.5.tgz") product_7_14_5 = "code-frame-7.14.5" handle_npm_uploading( test_tgz, product_7_14_5, @@ -143,7 +144,7 @@ def __prepare_content(self, prefix: str = None): dir_=self.tempdir, do_index=False ) - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.15.8.tgz") + test_tgz = os.path.join(INPUTS, "code-frame-7.15.8.tgz") product_7_15_8 = "code-frame-7.15.8" handle_npm_uploading( test_tgz, product_7_15_8, diff --git a/tests/test_npm_dist_gen.py b/tests/test_npm_dist_gen.py index ca1414e5..438cc094 100644 --- a/tests/test_npm_dist_gen.py +++ b/tests/test_npm_dist_gen.py @@ -23,6 +23,7 @@ TEST_BUCKET, TEST_BUCKET_2, CODE_FRAME_META, CODE_FRAME_7_14_5_META ) +from tests.constants import INPUTS @mock_s3 @@ -33,8 +34,8 @@ def setUp(self): self.test_bucket_2 = self.mock_s3.Bucket(TEST_BUCKET_2) def test_dist_gen_in_single_target(self): - targets_ = [(None, TEST_BUCKET, None, "npm1.registry.redhat.com")] - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.14.5.tgz") + targets_ = [('', TEST_BUCKET, '', "npm1.registry.redhat.com")] + test_tgz = os.path.join(INPUTS, "code-frame-7.14.5.tgz") product_7_14_5 = "code-frame-7.14.5" handle_npm_uploading( test_tgz, product_7_14_5, @@ -75,9 +76,9 @@ def test_dist_gen_in_single_target(self): "+vOtCS5ndmJicPJhKAwYRI6UfFw==\"", merged_meta_content_client) def test_dist_gen_in_multi_targets(self): - targets_ = [(None, TEST_BUCKET, None, "npm1.registry.redhat.com"), - (None, TEST_BUCKET_2, None, "npm2.registry.redhat.com")] - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.14.5.tgz") + targets_ = [('', TEST_BUCKET, '', "npm1.registry.redhat.com"), + ('', TEST_BUCKET_2, '', "npm2.registry.redhat.com")] + test_tgz = os.path.join(INPUTS, "code-frame-7.14.5.tgz") product_7_14_5 = "code-frame-7.14.5" handle_npm_uploading( test_tgz, product_7_14_5, @@ -111,8 +112,8 @@ def test_dist_gen_in_multi_targets(self): "-frame-7.14.5.tgz\"", merged_meta_content_client) def test_overlapping_registry_dist_gen(self): - targets_ = [(None, TEST_BUCKET, None, "npm1.registry.redhat.com")] - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.14.5.tgz") + targets_ = [('', TEST_BUCKET, '', "npm1.registry.redhat.com")] + test_tgz = os.path.join(INPUTS, "code-frame-7.14.5.tgz") product_7_14_5 = "code-frame-7.14.5" handle_npm_uploading( test_tgz, product_7_14_5, @@ -132,8 +133,8 @@ def test_overlapping_registry_dist_gen(self): self.assertIn("\"tarball\": \"https://npm1.registry.redhat.com/@babel/code-frame/-/code" "-frame-7.14.5.tgz\"", merged_meta_content_client) - targets_overlapping_ = [(None, TEST_BUCKET, None, "npm1.overlapping.registry.redhat.com")] - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.14.5.tgz") + targets_overlapping_ = [('', TEST_BUCKET, '', "npm1.overlapping.registry.redhat.com")] + test_tgz = os.path.join(INPUTS, "code-frame-7.14.5.tgz") product_7_14_5 = "code-frame-7.14.5" handle_npm_uploading( test_tgz, product_7_14_5, diff --git a/tests/test_npm_index.py b/tests/test_npm_index.py index 86d0f0fb..fa0ebc3a 100644 --- a/tests/test_npm_index.py +++ b/tests/test_npm_index.py @@ -24,6 +24,8 @@ from moto import mock_s3 import os +from tests.constants import INPUTS + NAMESPACE_BABEL_INDEX = "@babel/index.html" @@ -42,11 +44,11 @@ def test_uploding_index_with_root_prefix(self): self.__test_upload_prefix("/") def __test_upload_prefix(self, prefix: str = None): - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.14.5.tgz") + test_tgz = os.path.join(INPUTS, "code-frame-7.14.5.tgz") product_7_14_5 = "code-frame-7.14.5" handle_npm_uploading( test_tgz, product_7_14_5, - buckets=[(None, TEST_BUCKET, prefix, DEFAULT_REGISTRY)], + buckets=[('', TEST_BUCKET, prefix, DEFAULT_REGISTRY)], dir_=self.tempdir, ) @@ -122,11 +124,11 @@ def test_deletion_index_with_root_prefix(self): def __test_deletion_prefix(self, prefix: str = None): self.__prepare_content(prefix) - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.14.5.tgz") + test_tgz = os.path.join(INPUTS, "code-frame-7.14.5.tgz") product_7_14_5 = "code-frame-7.14.5" handle_npm_del( test_tgz, product_7_14_5, - buckets=[(None, TEST_BUCKET, prefix, None)], + buckets=[('', TEST_BUCKET, prefix, '')], dir_=self.tempdir ) @@ -154,10 +156,10 @@ def __test_deletion_prefix(self, prefix: str = None): self.assertNotIn(PROD_INFO_SUFFIX, index_content) product_7_15_8 = "code-frame-7.15.8" - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.15.8.tgz") + test_tgz = os.path.join(INPUTS, "code-frame-7.15.8.tgz") handle_npm_del( test_tgz, product_7_15_8, - buckets=[(None, TEST_BUCKET, prefix, None)], + buckets=[('', TEST_BUCKET, prefix, '')], dir_=self.tempdir ) @@ -165,18 +167,18 @@ def __test_deletion_prefix(self, prefix: str = None): self.assertEqual(0, len(objs)) def __prepare_content(self, prefix: str = None): - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.14.5.tgz") + test_tgz = os.path.join(INPUTS, "code-frame-7.14.5.tgz") product_7_14_5 = "code-frame-7.14.5" handle_npm_uploading( test_tgz, product_7_14_5, - buckets=[(None, TEST_BUCKET, prefix, DEFAULT_REGISTRY)], + buckets=[('', TEST_BUCKET, prefix, DEFAULT_REGISTRY)], dir_=self.tempdir ) - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.15.8.tgz") + test_tgz = os.path.join(INPUTS, "code-frame-7.15.8.tgz") product_7_15_8 = "code-frame-7.15.8" handle_npm_uploading( test_tgz, product_7_15_8, - buckets=[(None, TEST_BUCKET, prefix, DEFAULT_REGISTRY)], + buckets=[('', TEST_BUCKET, prefix, DEFAULT_REGISTRY)], dir_=self.tempdir ) diff --git a/tests/test_npm_index_multi_tgts.py b/tests/test_npm_index_multi_tgts.py index f449077d..ef653303 100644 --- a/tests/test_npm_index_multi_tgts.py +++ b/tests/test_npm_index_multi_tgts.py @@ -25,6 +25,8 @@ from moto import mock_s3 import os +from tests.constants import INPUTS + NAMESPACE_BABEL_INDEX = "@babel/index.html" @@ -53,9 +55,9 @@ def test_uploding_index_with_root_prefix(self): self.__test_upload_prefix("/") def __test_upload_prefix(self, prefix: str = None): - targets_ = [(None, TEST_BUCKET, prefix, DEFAULT_REGISTRY), - (None, TEST_BUCKET_2, prefix, DEFAULT_REGISTRY)] - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.14.5.tgz") + targets_ = [('', TEST_BUCKET, prefix, DEFAULT_REGISTRY), + ('', TEST_BUCKET_2, prefix, DEFAULT_REGISTRY)] + test_tgz = os.path.join(INPUTS, "code-frame-7.14.5.tgz") product_7_14_5 = "code-frame-7.14.5" handle_npm_uploading( test_tgz, product_7_14_5, @@ -118,7 +120,7 @@ def __test_upload_prefix(self, prefix: str = None): def test_overlap_upload_index(self): self.__prepare_content() - targets_ = [(None, TEST_BUCKET, None), (None, TEST_BUCKET_2, None)] + targets_ = [('', TEST_BUCKET, ''), ('', TEST_BUCKET_2, '')] for target in targets_: bucket_name = target[1] bucket = self.mock_s3.Bucket(bucket_name) @@ -162,8 +164,8 @@ def test_deletion_index_with_root_prefix(self): def __test_deletion_prefix(self, prefix: str = None): self.__prepare_content(prefix) - targets_ = [(None, TEST_BUCKET, prefix, None), (None, TEST_BUCKET_2, prefix, None)] - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.14.5.tgz") + targets_ = [('', TEST_BUCKET, prefix, ''), ('', TEST_BUCKET_2, prefix, '')] + test_tgz = os.path.join(INPUTS, "code-frame-7.14.5.tgz") product_7_14_5 = "code-frame-7.14.5" handle_npm_del( test_tgz, product_7_14_5, @@ -206,7 +208,7 @@ def __test_deletion_prefix(self, prefix: str = None): self.assertNotIn(PROD_INFO_SUFFIX, index_content, msg=f'{bucket_name}') product_7_15_8 = "code-frame-7.15.8" - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.15.8.tgz") + test_tgz = os.path.join(INPUTS, "code-frame-7.15.8.tgz") handle_npm_del( test_tgz, product_7_15_8, buckets=targets_, @@ -220,9 +222,9 @@ def __test_deletion_prefix(self, prefix: str = None): self.assertEqual(0, len(objs), msg=f'{bucket_name}') def __prepare_content(self, prefix: str = None): - targets_ = [(None, TEST_BUCKET, prefix, DEFAULT_REGISTRY), - (None, TEST_BUCKET_2, prefix, DEFAULT_REGISTRY)] - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.14.5.tgz") + targets_ = [('', TEST_BUCKET, prefix, DEFAULT_REGISTRY), + ('', TEST_BUCKET_2, prefix, DEFAULT_REGISTRY)] + test_tgz = os.path.join(INPUTS, "code-frame-7.14.5.tgz") product_7_14_5 = "code-frame-7.14.5" handle_npm_uploading( test_tgz, product_7_14_5, @@ -230,7 +232,7 @@ def __prepare_content(self, prefix: str = None): dir_=self.tempdir ) - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.15.8.tgz") + test_tgz = os.path.join(INPUTS, "code-frame-7.15.8.tgz") product_7_15_8 = "code-frame-7.15.8" handle_npm_uploading( test_tgz, product_7_15_8, diff --git a/tests/test_npm_meta.py b/tests/test_npm_meta.py index 3d7b030b..df660492 100644 --- a/tests/test_npm_meta.py +++ b/tests/test_npm_meta.py @@ -22,6 +22,7 @@ from charon.storage import S3Client from charon.constants import DEFAULT_REGISTRY from tests.base import BaseTest +from tests.constants import INPUTS MY_BUCKET = "npm_bucket" @@ -63,13 +64,10 @@ def test_handle_npm_uploading_for_old_version(self): Key='@redhat/kogito-tooling-workspace/package.json', Body=str(original_version_0_5_8_package_json) ) - tarball_test_path = os.path.join( - os.getcwd(), - 'tests/input/kogito-tooling-workspace-0.9.0-3.tgz' - ) + tarball_test_path = os.path.join(INPUTS, 'kogito-tooling-workspace-0.9.0-3.tgz') handle_npm_uploading( tarball_test_path, "kogito-tooling-workspace-0.9.0-3", - buckets=[(None, MY_BUCKET, None, DEFAULT_REGISTRY)], + buckets=[('', MY_BUCKET, '', DEFAULT_REGISTRY)], dir_=self.tempdir ) (files, _) = self.s3_client.get_files( @@ -116,13 +114,10 @@ def test_handle_npm_uploading_for_new_version(self): Key='@redhat/kogito-tooling-workspace/package.json', Body=str(original_version_1_0_1_package_json) ) - tarball_test_path = os.path.join( - os.getcwd(), - 'tests/input/kogito-tooling-workspace-0.9.0-3.tgz' - ) + tarball_test_path = os.path.join(INPUTS, 'kogito-tooling-workspace-0.9.0-3.tgz') handle_npm_uploading( tarball_test_path, "kogito-tooling-workspace-0.9.0-3", - buckets=[(None, MY_BUCKET, None, DEFAULT_REGISTRY)], + buckets=[('', MY_BUCKET, '', DEFAULT_REGISTRY)], dir_=self.tempdir ) (files, _) = self.s3_client.get_files( diff --git a/tests/test_npm_upload.py b/tests/test_npm_upload.py index c76a259b..1130b4d0 100644 --- a/tests/test_npm_upload.py +++ b/tests/test_npm_upload.py @@ -26,6 +26,7 @@ TEST_BUCKET, CODE_FRAME_7_14_5_FILES, CODE_FRAME_7_15_8_FILES, CODE_FRAME_META ) +from tests.constants import INPUTS @mock_s3 @@ -44,18 +45,18 @@ def test_upload_with_root_prefix(self): self.__test_prefix("/") def test_double_uploads(self): - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.14.5.tgz") + test_tgz = os.path.join(INPUTS, "code-frame-7.14.5.tgz") product_7_14_5 = "code-frame-7.14.5" handle_npm_uploading( test_tgz, product_7_14_5, - buckets=[(None, TEST_BUCKET, None, DEFAULT_REGISTRY)], + buckets=[('', TEST_BUCKET, '', DEFAULT_REGISTRY)], dir_=self.tempdir, do_index=False ) - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.15.8.tgz") + test_tgz = os.path.join(INPUTS, "code-frame-7.15.8.tgz") product_7_15_8 = "code-frame-7.15.8" handle_npm_uploading( test_tgz, product_7_15_8, - buckets=[(None, TEST_BUCKET, None, DEFAULT_REGISTRY)], + buckets=[('', TEST_BUCKET, '', DEFAULT_REGISTRY)], dir_=self.tempdir, do_index=False ) test_bucket = self.mock_s3.Bucket(TEST_BUCKET) @@ -88,11 +89,11 @@ def test_double_uploads(self): self.assertIn("\"dist_tags\": {\"latest\": \"7.15.8\"}", meta_content_client) def __test_prefix(self, prefix: str = None): - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.14.5.tgz") + test_tgz = os.path.join(INPUTS, "code-frame-7.14.5.tgz") product_7_14_5 = "code-frame-7.14.5" handle_npm_uploading( test_tgz, product_7_14_5, - buckets=[(None, TEST_BUCKET, prefix, DEFAULT_REGISTRY)], + buckets=[('', TEST_BUCKET, prefix, DEFAULT_REGISTRY)], dir_=self.tempdir, do_index=False ) diff --git a/tests/test_npm_upload_multi_tgts.py b/tests/test_npm_upload_multi_tgts.py index 2be3bdc9..d95868bd 100644 --- a/tests/test_npm_upload_multi_tgts.py +++ b/tests/test_npm_upload_multi_tgts.py @@ -26,6 +26,7 @@ TEST_BUCKET, CODE_FRAME_7_14_5_FILES, CODE_FRAME_7_15_8_FILES, CODE_FRAME_META, TEST_BUCKET_2 ) +from tests.constants import INPUTS @mock_s3 @@ -53,16 +54,16 @@ def test_upload_with_root_prefix(self): self.__test_prefix("/") def test_double_uploads(self): - targets_ = [(None, TEST_BUCKET, None, DEFAULT_REGISTRY), - (None, TEST_BUCKET_2, None, DEFAULT_REGISTRY)] - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.14.5.tgz") + targets_ = [('', TEST_BUCKET, '', DEFAULT_REGISTRY), + ('', TEST_BUCKET_2, '', DEFAULT_REGISTRY)] + test_tgz = os.path.join(INPUTS, "code-frame-7.14.5.tgz") product_7_14_5 = "code-frame-7.14.5" handle_npm_uploading( test_tgz, product_7_14_5, buckets=targets_, dir_=self.tempdir, do_index=False ) - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.15.8.tgz") + test_tgz = os.path.join(INPUTS, "code-frame-7.15.8.tgz") product_7_15_8 = "code-frame-7.15.8" handle_npm_uploading( test_tgz, product_7_15_8, @@ -124,9 +125,9 @@ def test_double_uploads(self): ) def __test_prefix(self, prefix: str = None): - targets_ = [(None, TEST_BUCKET, prefix, DEFAULT_REGISTRY), - (None, TEST_BUCKET_2, prefix, DEFAULT_REGISTRY)] - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.14.5.tgz") + targets_ = [('', TEST_BUCKET, prefix, DEFAULT_REGISTRY), + ('', TEST_BUCKET_2, prefix, DEFAULT_REGISTRY)] + test_tgz = os.path.join(INPUTS, "code-frame-7.14.5.tgz") product_7_14_5 = "code-frame-7.14.5" handle_npm_uploading( test_tgz, product_7_14_5, diff --git a/tests/test_pkgs_dryrun.py b/tests/test_pkgs_dryrun.py index e5502de8..7f2b004e 100644 --- a/tests/test_pkgs_dryrun.py +++ b/tests/test_pkgs_dryrun.py @@ -21,15 +21,17 @@ from moto import mock_s3 import os +from tests.constants import INPUTS + @mock_s3 class PkgsDryRunTest(PackageBaseTest): def test_maven_upload_dry_run(self): - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") product = "commons-client-4.5.6" handle_maven_uploading( test_zip, product, - buckets=[(None, TEST_BUCKET, None, None)], + buckets=[('', TEST_BUCKET, '', '')], dir_=self.tempdir, dry_run=True ) @@ -41,11 +43,11 @@ def test_maven_upload_dry_run(self): def test_maven_delete_dry_run(self): self.__prepare_maven_content() - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") product_456 = "commons-client-4.5.6" handle_maven_del( test_zip, product_456, - buckets=[(None, TEST_BUCKET, None, None)], + buckets=[('', TEST_BUCKET, '', '')], dir_=self.tempdir, dry_run=True ) @@ -55,11 +57,11 @@ def test_maven_delete_dry_run(self): self.assertEqual(50, len(objs)) def test_npm_upload_dry_run(self): - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.14.5.tgz") + test_tgz = os.path.join(INPUTS, "code-frame-7.14.5.tgz") product_7_14_5 = "code-frame-7.14.5" handle_npm_uploading( test_tgz, product_7_14_5, - buckets=[(None, TEST_BUCKET, None, DEFAULT_REGISTRY)], + buckets=[('', TEST_BUCKET, '', DEFAULT_REGISTRY)], dir_=self.tempdir, dry_run=True ) @@ -71,11 +73,11 @@ def test_npm_upload_dry_run(self): def test_npm_deletion_dry_run(self): self.__prepare_npm_content() - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.14.5.tgz") + test_tgz = os.path.join(INPUTS, "code-frame-7.14.5.tgz") product_7_14_5 = "code-frame-7.14.5" handle_npm_del( test_tgz, product_7_14_5, - buckets=[(None, TEST_BUCKET, None, None)], + buckets=[('', TEST_BUCKET, '', '')], dir_=self.tempdir, dry_run=True ) @@ -85,35 +87,35 @@ def test_npm_deletion_dry_run(self): self.assertEqual(11, len(objs)) def __prepare_maven_content(self): - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip") product_456 = "commons-client-4.5.6" handle_maven_uploading( test_zip, product_456, - buckets=[(None, TEST_BUCKET, None, None)], + buckets=[('', TEST_BUCKET, '', '')], dir_=self.tempdir ) - test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.9.zip") + test_zip = os.path.join(INPUTS, "commons-client-4.5.9.zip") product_459 = "commons-client-4.5.9" handle_maven_uploading( test_zip, product_459, - buckets=[(None, TEST_BUCKET, None, None)], + buckets=[('', TEST_BUCKET, '', '')], dir_=self.tempdir ) def __prepare_npm_content(self): - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.14.5.tgz") + test_tgz = os.path.join(INPUTS, "code-frame-7.14.5.tgz") product_7_14_5 = "code-frame-7.14.5" handle_npm_uploading( test_tgz, product_7_14_5, - buckets=[(None, TEST_BUCKET, None, DEFAULT_REGISTRY)], + buckets=[('', TEST_BUCKET, '', DEFAULT_REGISTRY)], dir_=self.tempdir ) - test_tgz = os.path.join(os.getcwd(), "tests/input/code-frame-7.15.8.tgz") + test_tgz = os.path.join(INPUTS, "code-frame-7.15.8.tgz") product_7_15_8 = "code-frame-7.15.8" handle_npm_uploading( test_tgz, product_7_15_8, - buckets=[(None, TEST_BUCKET, None, DEFAULT_REGISTRY)], + buckets=[('', TEST_BUCKET, '', DEFAULT_REGISTRY)], dir_=self.tempdir ) diff --git a/tests/test_s3client.py b/tests/test_s3client.py index cfb98f83..1c78db2b 100644 --- a/tests/test_s3client.py +++ b/tests/test_s3client.py @@ -26,6 +26,7 @@ import zipfile import shutil +from tests.constants import INPUTS MY_BUCKET = "my_bucket" MY_PREFIX = "mock_folder" @@ -148,7 +149,7 @@ def test_upload_and_delete_files(self): bucket = self.mock_s3.Bucket(MY_BUCKET) # test upload existed files with the product. The product will be added to metadata self.s3_client.upload_files( - all_files, targets=[(MY_BUCKET, None)], + all_files, targets=[(MY_BUCKET, '')], product="apache-commons", root=root ) @@ -170,7 +171,7 @@ def content_check(products: List[str], objs: List): # test upload existed files with extra product. The extra product will be added to metadata self.s3_client.upload_files( - all_files, targets=[(MY_BUCKET, None)], + all_files, targets=[(MY_BUCKET, '')], product="commons-lang3", root=root ) objects = list(bucket.objects.all()) @@ -178,14 +179,14 @@ def content_check(products: List[str], objs: List): # test delete files with one product. The file will not be deleted, but the product will # be removed from metadata. - self.s3_client.delete_files(all_files, target=(MY_BUCKET, None), product="apache-commons", + self.s3_client.delete_files(all_files, target=(MY_BUCKET, ''), product="apache-commons", root=root) objects = list(bucket.objects.all()) content_check(["commons-lang3"], objects) # test delete files with left product. The file will be deleted, because all products # have been removed from metadata. - self.s3_client.delete_files(all_files, target=(MY_BUCKET, None), product="commons-lang3", + self.s3_client.delete_files(all_files, target=(MY_BUCKET, ''), product="commons-lang3", root=root) self.assertEqual(0, len(list(bucket.objects.all()))) @@ -230,7 +231,7 @@ def test_upload_file_with_checksum(self): overwrite_file(file, content1) sha1_1 = read_sha1(file) self.s3_client.upload_files( - [file], targets=[(MY_BUCKET, None)], + [file], targets=[(MY_BUCKET, '')], product="foo-bar-1.0", root=temp_root ) objects = list(bucket.objects.all()) @@ -251,7 +252,7 @@ def test_upload_file_with_checksum(self): sha1_2 = read_sha1(file) self.assertNotEqual(sha1_1, sha1_2) self.s3_client.upload_files( - [file], targets=[(MY_BUCKET, None)], + [file], targets=[(MY_BUCKET, '')], product="foo-bar-1.0-2", root=temp_root ) objects = list(bucket.objects.all()) @@ -289,7 +290,7 @@ def test_upload_metadata_with_checksum(self): overwrite_file(file, content1) sha1_1 = read_sha1(file) self.s3_client.upload_metadatas( - [file], target=(MY_BUCKET, None), root=temp_root + [file], target=(MY_BUCKET, ''), root=temp_root ) objects = list(bucket.objects.all()) self.assertEqual(1, len(objects)) @@ -304,7 +305,7 @@ def test_upload_metadata_with_checksum(self): self.assertEqual(sha1_1, sha1_1_repeated) self.s3_client.upload_metadatas( [file], - target=(MY_BUCKET, None), + target=(MY_BUCKET, ''), root=temp_root, ) objects = list(bucket.objects.all()) @@ -334,7 +335,7 @@ def test_upload_metadata_with_checksum(self): sha1_2 = read_sha1(file) self.assertNotEqual(sha1_1, sha1_2) self.s3_client.upload_metadatas( - [file], target=(MY_BUCKET, None), root=temp_root + [file], target=(MY_BUCKET, ''), root=temp_root ) objects = list(bucket.objects.all()) self.assertEqual(1, len(objects)) @@ -360,7 +361,7 @@ def test_failed_paths(self): shutil.rmtree(root) failed_paths = self.s3_client.upload_files( - all_files, targets=[(MY_BUCKET, None)], + all_files, targets=[(MY_BUCKET, '')], product="apache-commons", root=temp_root ) @@ -369,7 +370,7 @@ def test_failed_paths(self): def test_exists_override_failing(self): (temp_root, _, all_files) = self.__prepare_files() failed_paths = self.s3_client.upload_files( - all_files, targets=[(MY_BUCKET, None)], + all_files, targets=[(MY_BUCKET, '')], product="apache-commons", root=temp_root ) self.assertEqual(0, len(failed_paths)) @@ -382,7 +383,7 @@ def test_exists_override_failing(self): sha1_changed = read_sha1(all_files[0]) self.assertNotEqual(sha1, sha1_changed) failed_paths = self.s3_client.upload_files( - all_files, targets=[(MY_BUCKET, None)], + all_files, targets=[(MY_BUCKET, '')], product="apache-commons-2", root=temp_root ) bucket = self.mock_s3.Bucket(MY_BUCKET) @@ -391,7 +392,7 @@ def test_exists_override_failing(self): def __prepare_files(self): test_zip = zipfile.ZipFile( - os.path.join(os.getcwd(), "tests/input/commons-lang3.zip") + os.path.join(INPUTS, "commons-lang3.zip") ) temp_root = os.path.join(self.tempdir, "tmp_zip") os.mkdir(temp_root) diff --git a/tests/test_util.py b/tests/test_util.py index 584920c2..35c9deff 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -17,10 +17,12 @@ import os import unittest +from tests.constants import INPUTS + class UtilTest(unittest.TestCase): def test_digest(self): - test_file = os.path.join(os.getcwd(), "tests/input/commons-lang3.zip") + test_file = os.path.join(INPUTS, "commons-lang3.zip") self.assertEqual("bd4fe0a8111df64430b6b419a91e4218ddf44734", digest(test_file)) self.assertEqual( "61ff1d38cfeb281b05fcd6b9a2318ed47cd62c7f99b8a9d3e819591c03fe6804", @@ -28,7 +30,7 @@ def test_digest(self): ) def test_read_sha1(self): - test_file = os.path.join(os.getcwd(), "tests/input/commons-lang3.zip") + test_file = os.path.join(INPUTS, "commons-lang3.zip") # read the real sha1 hash self.assertEqual("bd4fe0a8111df64430b6b419a91e4218ddf44734", digest(test_file)) # read hash from .sha1 file @@ -37,5 +39,5 @@ def test_read_sha1(self): ) # For .sha1 file itself, will use digest directly - test_file = os.path.join(os.getcwd(), "tests/input/commons-lang3.zip.sha1") + test_file = os.path.join(INPUTS, "commons-lang3.zip.sha1") self.assertEqual(digest(test_file), read_sha1(test_file)) diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..218f0a61 --- /dev/null +++ b/tox.ini @@ -0,0 +1,40 @@ +[tox] +envlist = test,flake8,pylint,bandit + +[testenv] +basepython=python3 +skip_install = true + +[testenv:test] +sitepackages = true +deps = -r requirements-dev.txt +commands = python3 -m pytest --cov=charon {posargs:"tests"} + +[testenv:pylint] +deps = pylint==2.9.6 +commands = python3 -m pylint charon tests + +[testenv:flake8] +deps = flake8 +commands = python3 -m flake8 charon tests + +[testenv:bandit] +deps = bandit +commands = bandit-baseline -r charon -ll -ii + +[testenv:mypy] +deps = mypy==0.910 +commands = + mypy \ + --install-types \ + --non-interactive \ + --ignore-missing-imports \ + --package {posargs:"charon"} + +[coverage:report] +skip_covered = true +sort = Cover + +[pytest] +addopts = -ra --color=auto --html=__pytest_reports/charon-unit-tests.html --self-contained-html +render_collapsed = True