-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
561cd58
commit 9a44238
Showing
9 changed files
with
372 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,10 @@ | |
# We undertake not to change the open source license (MIT license) applicable | ||
# to the current version of the project delivered to anyone in the future. | ||
# | ||
import os | ||
import subprocess | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from apigateway.apps.support.api_sdk.distributors.pypi import PypiSourceDistributor | ||
|
@@ -57,9 +61,37 @@ def sdist(tmpdir, sdk_context): | |
dist = tmpdir.join("dist") | ||
dist.mkdir() | ||
|
||
source_tar = dist.join(f"{sdk_context.name}.tar.gz") | ||
source_tar.write("") | ||
return source_tar | ||
# Create a simple package structure | ||
package_dir = tmpdir.join(sdk_context.name) | ||
package_dir.mkdir() | ||
|
||
init_file = package_dir.join("__init__.py") | ||
init_file.write("# Sample package") | ||
|
||
# Create a setup.py file with necessary metadata | ||
setup_py = tmpdir.join("setup.py") | ||
setup_py.write(f"""\ | ||
from setuptools import setup, find_packages | ||
setup( | ||
name='{sdk_context.name}', | ||
version='1.0.0', | ||
packages=find_packages(), | ||
description='A test Python package', | ||
author='Your Name', | ||
author_email='[email protected]', | ||
url='https://example.com', | ||
) | ||
""") | ||
|
||
# Build the source distribution | ||
current_dir = os.getcwd() | ||
os.chdir(tmpdir) | ||
try: | ||
subprocess.check_call([os.sys.executable, "setup.py", "sdist"]) | ||
finally: | ||
os.chdir(current_dir) | ||
return dist.join(f"{sdk_context.name}-1.0.0.tar.gz") | ||
|
||
|
||
@pytest.fixture | ||
|
@@ -80,16 +112,14 @@ def test_pypirc( | |
def test_distribute( | ||
output_dir, | ||
sdk_context, | ||
python_setup_script, | ||
sdist, | ||
python_setup_history, | ||
distributor: PypiSourceDistributor, | ||
package_searcher_result, | ||
): | ||
result = distributor.distribute(output_dir, [sdist]) | ||
|
||
python_setup_history = python_setup_history.read() | ||
assert f"setup.py sdist upload -r {distributor.repository}" in python_setup_history | ||
# Mock the check_call to prevent actual call to `twine upload` | ||
with patch("subprocess.check_call") as mock_check_call: | ||
mock_check_call.return_value = 0 # Simulate successful execution | ||
result = distributor.distribute(output_dir, [sdist]) | ||
|
||
assert sdk_context.config["python"]["is_uploaded_to_pypi"] | ||
assert sdk_context.config["python"]["repository"] == distributor.repository | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.