Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration tests #72

Draft
wants to merge 40 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5634a61
Fix softprops/action-gh-release version
Hind-M Jan 7, 2025
3d0f4af
Fix files
Hind-M Jan 7, 2025
8119209
Add token
Hind-M Jan 7, 2025
db30418
Add fetch_release tests
Hind-M Jan 8, 2025
cc320e0
Add gitignore
Hind-M Jan 8, 2025
acef6a9
Use softprops/[email protected]
Hind-M Jan 8, 2025
5c90d06
Add more tests
Hind-M Jan 8, 2025
d8a1569
Fix os env var
Hind-M Jan 8, 2025
5bbdab0
Remove 1.5.10 for now
Hind-M Jan 8, 2025
d200164
Change test
Hind-M Jan 8, 2025
61dafcf
Fix test
Hind-M Jan 8, 2025
fe6d72d
Add tests
Hind-M Jan 9, 2025
d14510f
Change tests
Hind-M Jan 9, 2025
814fe60
Use version
Hind-M Jan 9, 2025
7d78859
Add print
Hind-M Jan 9, 2025
6e9d143
Change version
Hind-M Jan 9, 2025
f6f5c94
Change specs in env file
Hind-M Jan 9, 2025
53e7909
Add mock test
Hind-M Jan 9, 2025
a26579d
Add missing subdirs
Hind-M Jan 9, 2025
2579980
Add ','
Hind-M Jan 9, 2025
190f0f6
Add missing keys
Hind-M Jan 9, 2025
3cee4bb
Add mock_check_call
Hind-M Jan 9, 2025
966eb36
Comment leftover
Hind-M Jan 9, 2025
b844419
Mock copyfile
Hind-M Jan 9, 2025
898c642
mock_copyfile_side_effect
Hind-M Jan 9, 2025
4602c6b
Add raise_for_status
Hind-M Jan 9, 2025
409600e
Not use module
Hind-M Jan 9, 2025
6b728fc
Add checks
Hind-M Jan 10, 2025
11ae570
Add fetch_release
Hind-M Jan 10, 2025
93c7c73
Remove symlink arg
Hind-M Jan 10, 2025
2652b38
Set mock_copyfile.return_value
Hind-M Jan 10, 2025
a81df81
Add None
Hind-M Jan 10, 2025
180b081
Add args and kargs
Hind-M Jan 10, 2025
1eaca56
Add raise_for_status
Hind-M Jan 10, 2025
03009ff
Remove .github/workflows/test_release_publisher.yml
Hind-M Jan 10, 2025
55ffcf5
Use two mock functions for get requests
Hind-M Jan 10, 2025
772f8ea
Add module name before func
Hind-M Jan 10, 2025
61eef66
Put func outside
Hind-M Jan 10, 2025
f39ab3b
Add fixtures
Hind-M Jan 10, 2025
d4e6cb0
add module
Hind-M Jan 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Put func outside
Hind-M committed Jan 10, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 61eef664c57aca3e12add193663511333d9784a7
248 changes: 169 additions & 79 deletions tests/test_fetch_release.py
Original file line number Diff line number Diff line change
@@ -97,10 +97,100 @@ def test_get_micromamba_non_existing_version(use_default_version):

#TODO mock test for non existing versions => new_version_1_x, new_version_2_x, new_prerelease

@patch('requests.get') # TODO remove fetch_release?
@pytest.fixture
def mock_github_tags():
"""Mock GitHub tags to simulate existing tags."""
with patch('fetch_release.get_all_tags_github') as mock:
mock.return_value = {"2.0.5-0"}
yield mock

@pytest.fixture
def mock_anaconda_api():
"""Mock Anaconda.org API response."""
with patch('requests.get') as mock:
# Simulate a new version available
mock.status_code = 200
mock_response.raise_for_status = MagicMock()

mocked_content = b"some random binary data representing a tar.bz2 file"
mock_response.content = mocked_content

sha256 = hashlib.sha256()
sha256.update(mocked_content)
computed_checksum = sha256.hexdigest()

mock_response.json.return_value = {
"distributions": [
{
"attrs": {
"subdir": "linux-64",
"build_number": 1
},
"download_url": "https://anaconda-api/conda-forge/micromamba/10.11.12/linux-64/micromamba-10.11.12-1.tar.bz2",
"sha256": computed_checksum,
"basename": "linux-64/micromamba-10.11.12-linux-64.tar.bz2",
"version": "10.11.12"
},
{
"attrs": {
"subdir": "linux-aarch64",
"build_number": 1
},
"download_url": "https://anaconda-api/conda-forge/micromamba/10.11.12/linux-aarch64/micromamba-10.11.12-1.tar.bz2",
"sha256": computed_checksum,
"basename": "linux-aarch64/micromamba-10.11.12-linux-aarch64.tar.bz2",
"version": "10.11.12"
},
{
"attrs": {
"subdir": "linux-ppc64le",
"build_number": 1
},
"download_url": "https://anaconda-api/conda-forge/micromamba/10.11.12/linux-ppc64le/micromamba-10.11.12-1.tar.bz2",
"sha256": computed_checksum,
"basename": "linux-ppc64le/micromamba-10.11.12-linux-ppc64le.tar.bz2",
"version": "10.11.12"
},
{
"attrs": {
"subdir": "win-64",
"build_number": 1
},
"download_url": "https://anaconda-api/conda-forge/micromamba/10.11.12/win-64/micromamba-10.11.12-1.tar.bz2",
"sha256": computed_checksum,
"basename": "win-64/micromamba-10.11.12-win-64.tar.bz2",
"version": "10.11.12"
},
{
"attrs": {
"subdir": "osx-64",
"build_number": 1
},
"download_url": "https://anaconda-api/conda-forge/micromamba/10.11.12/osx-64/micromamba-10.11.12-1.tar.bz2",
"sha256": computed_checksum,
"basename": "osx-64/micromamba-10.11.12-osx-64.tar.bz2",
"version": "10.11.12"
},
{
"attrs": {
"subdir": "osx-arm64",
"build_number": 1
},
"download_url": "https://anaconda-api/conda-forge/micromamba/10.11.12/osx-arm64/micromamba-10.11.12-1.tar.bz2",
"sha256": computed_checksum,
"basename": "osx-arm64/micromamba-10.11.12-osx-arm64.tar.bz2",
"version": "10.11.12"
}
]
}

yield mock


#@patch('requests.get')
@patch("subprocess.check_call")
@patch("shutil.copyfile")
def test_get_micromamba_new_2_x_version(mock_get, mock_check_call, mock_copyfile):
def test_get_micromamba_new_2_x_version(mock_github_tags, mock_anaconda_api, mock_check_call, mock_copyfile):
# Create a mock response object for get_all_tags_github (GitHub API)
#mock_github_response = MagicMock()
#mock_github_response.status_code = 200
@@ -116,82 +206,82 @@ def test_get_micromamba_new_2_x_version(mock_get, mock_check_call, mock_copyfile
#mock_anaconda_response.raise_for_status = MagicMock()

## Mock the response from the Anaconda API
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.raise_for_status = MagicMock()
#mock_response = MagicMock()
#mock_response.status_code = 200
#mock_response.raise_for_status = MagicMock()

# Mock request content to return a byte string
mocked_content = b"some random binary data representing a tar.bz2 file"
mock_response.content = mocked_content

sha256 = hashlib.sha256()
sha256.update(mocked_content)
computed_checksum = sha256.hexdigest()

mock_response.json.return_value = {
"distributions": [
{
"attrs": {
"subdir": "linux-64",
"build_number": 1
},
"download_url": "https://anaconda-api/conda-forge/micromamba/10.11.12/linux-64/micromamba-10.11.12-1.tar.bz2",
"sha256": computed_checksum,
"basename": "linux-64/micromamba-10.11.12-linux-64.tar.bz2",
"version": "10.11.12"
},
{
"attrs": {
"subdir": "linux-aarch64",
"build_number": 1
},
"download_url": "https://anaconda-api/conda-forge/micromamba/10.11.12/linux-aarch64/micromamba-10.11.12-1.tar.bz2",
"sha256": computed_checksum,
"basename": "linux-aarch64/micromamba-10.11.12-linux-aarch64.tar.bz2",
"version": "10.11.12"
},
{
"attrs": {
"subdir": "linux-ppc64le",
"build_number": 1
},
"download_url": "https://anaconda-api/conda-forge/micromamba/10.11.12/linux-ppc64le/micromamba-10.11.12-1.tar.bz2",
"sha256": computed_checksum,
"basename": "linux-ppc64le/micromamba-10.11.12-linux-ppc64le.tar.bz2",
"version": "10.11.12"
},
{
"attrs": {
"subdir": "win-64",
"build_number": 1
},
"download_url": "https://anaconda-api/conda-forge/micromamba/10.11.12/win-64/micromamba-10.11.12-1.tar.bz2",
"sha256": computed_checksum,
"basename": "win-64/micromamba-10.11.12-win-64.tar.bz2",
"version": "10.11.12"
},
{
"attrs": {
"subdir": "osx-64",
"build_number": 1
},
"download_url": "https://anaconda-api/conda-forge/micromamba/10.11.12/osx-64/micromamba-10.11.12-1.tar.bz2",
"sha256": computed_checksum,
"basename": "osx-64/micromamba-10.11.12-osx-64.tar.bz2",
"version": "10.11.12"
},
{
"attrs": {
"subdir": "osx-arm64",
"build_number": 1
},
"download_url": "https://anaconda-api/conda-forge/micromamba/10.11.12/osx-arm64/micromamba-10.11.12-1.tar.bz2",
"sha256": computed_checksum,
"basename": "osx-arm64/micromamba-10.11.12-osx-arm64.tar.bz2",
"version": "10.11.12"
}
]
}
#mocked_content = b"some random binary data representing a tar.bz2 file"
#mock_response.content = mocked_content

#sha256 = hashlib.sha256()
#sha256.update(mocked_content)
#computed_checksum = sha256.hexdigest()

#mock_response.json.return_value = {
#"distributions": [
#{
#"attrs": {
#"subdir": "linux-64",
#"build_number": 1
#},
#"download_url": "https://anaconda-api/conda-forge/micromamba/10.11.12/linux-64/micromamba-10.11.12-1.tar.bz2",
#"sha256": computed_checksum,
#"basename": "linux-64/micromamba-10.11.12-linux-64.tar.bz2",
#"version": "10.11.12"
#},
#{
#"attrs": {
#"subdir": "linux-aarch64",
#"build_number": 1
#},
#"download_url": "https://anaconda-api/conda-forge/micromamba/10.11.12/linux-aarch64/micromamba-10.11.12-1.tar.bz2",
#"sha256": computed_checksum,
#"basename": "linux-aarch64/micromamba-10.11.12-linux-aarch64.tar.bz2",
#"version": "10.11.12"
#},
#{
#"attrs": {
#"subdir": "linux-ppc64le",
#"build_number": 1
#},
#"download_url": "https://anaconda-api/conda-forge/micromamba/10.11.12/linux-ppc64le/micromamba-10.11.12-1.tar.bz2",
#"sha256": computed_checksum,
#"basename": "linux-ppc64le/micromamba-10.11.12-linux-ppc64le.tar.bz2",
#"version": "10.11.12"
#},
#{
#"attrs": {
#"subdir": "win-64",
#"build_number": 1
#},
#"download_url": "https://anaconda-api/conda-forge/micromamba/10.11.12/win-64/micromamba-10.11.12-1.tar.bz2",
#"sha256": computed_checksum,
#"basename": "win-64/micromamba-10.11.12-win-64.tar.bz2",
#"version": "10.11.12"
#},
#{
#"attrs": {
#"subdir": "osx-64",
#"build_number": 1
#},
#"download_url": "https://anaconda-api/conda-forge/micromamba/10.11.12/osx-64/micromamba-10.11.12-1.tar.bz2",
#"sha256": computed_checksum,
#"basename": "osx-64/micromamba-10.11.12-osx-64.tar.bz2",
#"version": "10.11.12"
#},
#{
#"attrs": {
#"subdir": "osx-arm64",
#"build_number": 1
#},
#"download_url": "https://anaconda-api/conda-forge/micromamba/10.11.12/osx-arm64/micromamba-10.11.12-1.tar.bz2",
#"sha256": computed_checksum,
#"basename": "osx-arm64/micromamba-10.11.12-osx-arm64.tar.bz2",
#"version": "10.11.12"
#}
#]
#}

# Use side_effect to simulate different responses for different requests
#def side_effect(url, timeout=10):
@@ -205,7 +295,7 @@ def test_get_micromamba_new_2_x_version(mock_get, mock_check_call, mock_copyfile
# Set the side_effect to mock_get
#mock_get.side_effect = side_effect

mock_get.return_value = mock_response
#mock_get.return_value = mock_response

# Mock subprocess.check_call to prevent actual command execution
mock_check_call.return_value = None # Simulate a successful call
@@ -226,12 +316,12 @@ def mock_copyfile_side_effect(*args, **kwargs): #src=None, dst=None, follow_syml
mock_copyfile.side_effect = mock_copyfile_side_effect

# Mock existing GitHub tags to simulate the version already being tagged
with patch.object(fetch_release, 'fetch_release.get_all_tags_github', return_value={'2.0.5-0'}):
with patch.object(fetch_release, 'get_all_tags_github', return_value={'2.0.5-0'}):
# Run the method with the mocked data
fetch_release.get_micromamba('10.11.12', False)

# Check that the `requests.get` method was called as expected
mock_get.assert_called_once_with("https://api.anaconda.org/release/conda-forge/micromamba/10.11.12")
#mock_get.assert_called_once_with("https://api.anaconda.org/release/conda-forge/micromamba/10.11.12")

# Ensure that subprocess.check_call was called to extract the archive
mock_check_call.assert_called_once_with(