Skip to content

Commit

Permalink
add new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matteius committed Sep 28, 2024
1 parent 57467d6 commit 120dfbf
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/integration/test_install_vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,34 @@ def test_install_github_vcs(pipenv_instance_pypi):
c = p.pipenv("install git+https://github.com/reagento/[email protected]")
assert not c.returncode
assert "dataclass-factory" in p.pipfile["packages"]


@pytest.mark.basic
@pytest.mark.install
@pytest.mark.parametrize("use_credentials", [True, False])
def test_install_github_vcs_with_credentials(pipenv_instance_pypi, use_credentials):
with pipenv_instance_pypi() as p:
# Set environment variables
os.environ['GIT_REPO'] = 'github.com/reagento/adaptix.git'

Check failure on line 19 in tests/integration/test_install_vcs.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F821)

tests/integration/test_install_vcs.py:19:9: F821 Undefined name `os`
if use_credentials:
os.environ['GIT_USERNAME'] = 'git' # Use 'git' as a dummy username

Check failure on line 21 in tests/integration/test_install_vcs.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F821)

tests/integration/test_install_vcs.py:21:13: F821 Undefined name `os`
os.environ['GIT_PASSWORD'] = '' # Empty password for public repos

Check failure on line 22 in tests/integration/test_install_vcs.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F821)

tests/integration/test_install_vcs.py:22:13: F821 Undefined name `os`
url = f"git+https://${{GIT_USERNAME}}:${{GIT_PASSWORD}}@${{GIT_REPO}}@2.16"

Check failure on line 23 in tests/integration/test_install_vcs.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F541)

tests/integration/test_install_vcs.py:23:19: F541 f-string without any placeholders
else:
url = f"git+https://${{GIT_REPO}}@2.16"

Check failure on line 25 in tests/integration/test_install_vcs.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F541)

tests/integration/test_install_vcs.py:25:19: F541 f-string without any placeholders

c = p.pipenv(f"install {url}")
assert not c.returncode
assert "adaptix" in p.pipfile["packages"]

# Check if the URL in the lockfile still contains the environment variables
lockfile_content = p.lockfile
assert "${GIT_REPO}" in lockfile_content['default']['adaptix']['git']
if use_credentials:
assert "${GIT_USERNAME}" in lockfile_content['default']['adaptix']['git']
assert "${GIT_PASSWORD}" in lockfile_content['default']['adaptix']['git']

# Verify that the package is installed and usable
c = p.pipenv("run python -c 'import adaptix; print(adaptix.__version__)'")
assert not c.returncode
assert "2.16" in c.stdout
31 changes: 31 additions & 0 deletions tests/unit/test_dependencies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pytest
from pipenv.utils.dependencies import clean_resolved_dep

def test_clean_resolved_dep_with_vcs_url():
project = {} # Mock project object, adjust as needed
dep = {
"name": "example-package",
"git": "git+https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/username/repo.git",
"ref": "main"
}

result = clean_resolved_dep(project, dep)

assert "example-package" in result
assert result["example-package"]["git"] == "git+https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/username/repo.git"
assert result["example-package"]["ref"] == "main"

def test_clean_resolved_dep_with_vcs_url_and_extras():
project = {} # Mock project object, adjust as needed
dep = {
"name": "example-package",
"git": "git+https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/username/repo.git[extra1,extra2]",
"ref": "main"
}

result = clean_resolved_dep(project, dep)

assert "example-package" in result
assert result["example-package"]["git"] == "git+https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/username/repo.git[extra1,extra2]"
assert result["example-package"]["ref"] == "main"
assert result["example-package"]["extras"] == ["extra1", "extra2"]

0 comments on commit 120dfbf

Please sign in to comment.