-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from colinhoglund/fix_source_trimming
BUGFIX: Fix source trimming when source is CWD ('.') and refactor test suite
- Loading branch information
Showing
7 changed files
with
127 additions
and
103 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
__version__ = '0.1.0' | ||
__version__ = '0.1.1' | ||
__description__ = 'piprepo creates PEP-503 compliant package repositories.' |
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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import os | ||
import pytest | ||
import shutil | ||
import tempfile | ||
|
||
PACKAGES = [ | ||
'Django-1.11.2-py2.py3-none-any.whl', | ||
'ansible-2.0.0.0.tar.gz', | ||
'ansible-2.3.1.0.tar.gz', | ||
'python_http_client-2.2.1-py2.py3-none-any.whl', | ||
'avocado-framework-plugin-varianter-yaml-to-mux-53.0.tar.gz', | ||
'affinitic.recipe.fakezope2eggs-0.3-py2.4.egg', | ||
'foursquare-1!2016.9.12.tar.gz' | ||
] | ||
|
||
|
||
@pytest.yield_fixture(scope="function") | ||
def tempindex(): | ||
temp = tempfile.mkdtemp() | ||
index = { | ||
'packages': PACKAGES, | ||
'source': os.path.join(temp, 'source'), | ||
'destination': os.path.join(temp, 'destination'), | ||
} | ||
os.mkdir(index['source']) | ||
os.mkdir(index['destination']) | ||
for package in index['packages']: | ||
with open(os.path.join(index['source'], package), 'w') as f: | ||
f.write(package) | ||
yield index | ||
shutil.rmtree(temp) |
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import boto3 | ||
import os | ||
from botocore.exceptions import ClientError | ||
from moto import mock_s3 | ||
from piprepo.models import S3Index | ||
from piprepo.utils import get_project_name_from_file | ||
from .conftest import PACKAGES | ||
|
||
|
||
def assert_s3_bucket_contents(conn, bucket, prefix=''): | ||
for package in PACKAGES: | ||
package_obj = conn.Object(bucket.name, os.path.join(prefix, package)) | ||
package_index_obj = conn.Object( | ||
bucket.name, os.path.join(prefix, 'simple', get_project_name_from_file(package), 'index.html') | ||
) | ||
root_index_obj = conn.Object(bucket.name, os.path.join(prefix, 'simple', 'index.html')) | ||
|
||
assert s3_object_exists(package_obj) | ||
assert s3_object_exists(package_index_obj) | ||
assert s3_object_exists(root_index_obj) | ||
assert get_project_name_from_file(package).encode() in root_index_obj.get()['Body'].read() | ||
assert package.encode() in package_index_obj.get()['Body'].read() | ||
|
||
|
||
@mock_s3 | ||
def assert_s3_sync(source, destination): | ||
conn = boto3.resource("s3") | ||
bucket = conn.create_bucket(Bucket='piprepo') | ||
with S3Index(source, destination) as index: | ||
prefix = index.prefix | ||
assert_s3_bucket_contents(conn, bucket, prefix) | ||
|
||
|
||
def test_s3_sync_with_prefix(tempindex): | ||
assert_s3_sync(tempindex['source'], 's3://piprepo/prefix') | ||
|
||
|
||
def test_s3_sync_with_prefix_trailing_slash(tempindex): | ||
assert_s3_sync(tempindex['source'] + '/', 's3://piprepo/prefix/') | ||
|
||
|
||
def test_s3_sync_with_prefix_from_source_dir(tempindex): | ||
os.chdir(tempindex['source']) | ||
assert_s3_sync('.', 's3://piprepo/prefix') | ||
|
||
|
||
def test_s3_sync_without_prefix(tempindex): | ||
assert_s3_sync(tempindex['source'], 's3://piprepo') | ||
|
||
|
||
def test_s3_sync_without_prefix_trailing_slash(tempindex): | ||
assert_s3_sync(tempindex['source'] + '/', 's3://piprepo/') | ||
|
||
|
||
def test_s3_sync_without_prefix_from_source_dir(tempindex): | ||
os.chdir(tempindex['source']) | ||
assert_s3_sync('.', 's3://piprepo') | ||
|
||
|
||
def s3_object_exists(obj): | ||
try: | ||
obj.load() | ||
except ClientError as e: | ||
if e.response['Error']['Code'] == "404": | ||
return False | ||
else: | ||
raise | ||
return True |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from piprepo import models, utils | ||
from .conftest import PACKAGES | ||
|
||
|
||
def test_project_names(): | ||
expected = { | ||
'affinitic-recipe-fakezope2eggs', | ||
'ansible', | ||
'avocado-framework-plugin-varianter-yaml-to-mux', | ||
'django', | ||
'foursquare', | ||
'python-http-client' | ||
} | ||
|
||
assert {utils.get_project_name_from_file(p) for p in PACKAGES} == expected | ||
|
||
|
||
def test_skip_invalid_package(tempindex): | ||
index = models.LocalIndex(tempindex['source'], tempindex['destination']) | ||
index._build_packages(['invalidpackage.txt']) | ||
assert index.packages == {} |