Skip to content
This repository has been archived by the owner on May 24, 2023. It is now read-only.

Commit

Permalink
Merge 1ee101a into b351acc
Browse files Browse the repository at this point in the history
  • Loading branch information
csomh committed Mar 14, 2019
2 parents b351acc + 1ee101a commit 653faa0
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 101 deletions.
13 changes: 12 additions & 1 deletion example.test.env.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
---
# Configuration example for the integration tests.

# URL of the Quay App Registry API. No trailing '/'.
quay_app_registry_api: https://quay.io/cnr/api/v1
# URL of the Quay API. No trailing '/'.
quay_url: https://quay.io/cnr/api/v1
quay_api: https://quay.io/api/v1
# OAuth token to be used for request going to quay_api
quay_oauth_token: <quay application token>
# User to authenticate with Quay.
quay_user: <robot account>
# Password to authenticate with Quay.
Expand All @@ -22,3 +26,10 @@ koji_builds:
valid_zip: valid-operator-container-1.0.0-1
invalid_zip: invalid-operator-container-1.0.0-1
not_an_operator: etcd-container-1.0.0-1
# Configuration to test that an organization not configured
# to be made public is kept private.
private_org:
user: <robot account>
password: <robot token>
namespace: private-operators
package: integration-tests-private
8 changes: 4 additions & 4 deletions tests/integration/authorization/authorization_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
import shutil
import pytest
import requests
from tests.integration.utils import OMPS
from tests.integration.utils import OMPS, test_env


@pytest.fixture(scope='module')
def no_auth_omps(test_env):
def no_auth_omps():
return OMPS(test_env['omps_url'])


def test_upload_without_authorization(test_env, no_auth_omps, tmp_path):
def test_upload_without_authorization(no_auth_omps, tmp_path):
"""
Upload fails, when no 'Authorization' header is provided.
"""
Expand All @@ -28,7 +28,7 @@ def test_upload_without_authorization(test_env, no_auth_omps, tmp_path):
assert response.json()['error'] == 'OMPSAuthorizationHeaderRequired'


def test_delete_without_authorization(test_env, no_auth_omps, omps, quay, tmp_path):
def test_delete_without_authorization(no_auth_omps, omps, quay, tmp_path):
"""
Deleting a version fails, when no 'Authorization' header is provided.
"""
Expand Down
50 changes: 33 additions & 17 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,11 @@
#

import pytest
import yaml
from .utils import OMPS, QuayAppRegistry, Koji
from .utils import OMPS, QuayAppRegistry, Koji, test_env


@pytest.fixture(scope='session')
def test_env():
"""Test environment configuration.
"""
with open('test.env.yaml') as f:
env = yaml.safe_load(f)
return env


@pytest.fixture(scope='session')
def quay(test_env):
def quay():
"""Quay App Registry used for testing.
Args:
Expand All @@ -27,16 +17,18 @@ def quay(test_env):
Yields: An instance of QuayAppRegistry.
Raises: None.
"""
app_registry = QuayAppRegistry(test_env['quay_url'])
app_registry.login(test_env['quay_user'], test_env['quay_password'])
app_registry = QuayAppRegistry(test_env['quay_app_registry_api'],
test_env['quay_api'],
test_env['quay_oauth_token'])
app_registry.login_to_cnr(test_env['quay_user'], test_env['quay_password'])

yield app_registry

app_registry.clean_up(test_env['test_namespace'], test_env['test_package'])
app_registry.delete(test_env['test_namespace'], test_env['test_package'])


@pytest.fixture(scope='session')
def omps(test_env, quay):
def omps(quay):
"""OMPS used for testing.
Args:
Expand All @@ -50,7 +42,7 @@ def omps(test_env, quay):


@pytest.fixture(scope='session')
def koji(test_env):
def koji():
"""Koji instance configured in OMPS.
Args:
Expand All @@ -60,3 +52,27 @@ def koji(test_env):
Raises: None.
"""
return Koji(test_env['kojihub'], test_env['kojiroot'])


@pytest.fixture
def private_quay():
quay = None

if test_env.get('private_org'):
quay = QuayAppRegistry(test_env['quay_app_registry_api'],
test_env['quay_api'],
test_env['quay_oauth_token'])
quay.login_to_cnr(test_env['private_org']['user'],
test_env['private_org']['password'])

yield quay

if quay:
quay.delete(test_env['private_org']['namespace'],
test_env['private_org']['package'])


@pytest.fixture
def private_omps(private_quay):
if private_quay:
return OMPS(test_env['omps_url'], private_quay.token)
25 changes: 17 additions & 8 deletions tests/integration/delete_version/delete_version_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import shutil
import requests
import pytest
from tests.integration.utils import test_env


def test_delete_version(test_env, omps, quay, tmp_path):
def test_delete_version(omps, quay, tmp_path):
"""
When a version is requested to be deleted,
and a release matching that version exists for the package,
Expand All @@ -34,10 +35,12 @@ def test_delete_version(test_env, omps, quay, tmp_path):
'repo': test_env['test_package'],
}
assert not quay.get_release(test_env['test_namespace'],
test_env['test_package'], version)
test_env['test_package'],
version,
authorization=None)


def test_version_does_not_exist(test_env, omps, quay, tmp_path):
def test_version_does_not_exist(omps, quay, tmp_path):
"""
If the version requested to be deleted, is not present in the package,
a 'QuayPackageNotFound' error is returned.
Expand Down Expand Up @@ -68,7 +71,7 @@ def test_version_does_not_exist(test_env, omps, quay, tmp_path):
assert "doesn't exist" in response.json()['message']


def test_delete_all_versions(test_env, omps, quay, tmp_path):
def test_delete_all_versions(omps, quay, tmp_path):
"""
When there is no version specified for the delete operation,
all the releases of the package are deleted.
Expand All @@ -95,8 +98,12 @@ def test_delete_all_versions(test_env, omps, quay, tmp_path):
'repo': test_env['test_package'],
}

assert not quay.get_releases(test_env['test_namespace'],
test_env['test_package'],
authorization=None)

def test_organization_unaccessible_in_quay(test_env, omps):

def test_organization_unaccessible_in_quay(omps):
"""
Delete fails, if the organization is not configured with OMPS.
"""
Expand All @@ -107,7 +114,7 @@ def test_organization_unaccessible_in_quay(test_env, omps):
assert 'Unauthorized access' in response.json()['message']


def test_package_does_not_exist(test_env, omps, quay):
def test_package_does_not_exist(omps, quay):
"""
Delete fails, if the package does not exist in Quay.
"""
Expand All @@ -131,7 +138,7 @@ def test_package_does_not_exist(test_env, omps, quay):
pytest.param('6.0.2', '5.0.0', id='highest version'),
pytest.param('4.0.1', '7.0.0', id='previous version'),
])
def test_increment_version_after_delete(test_env, omps, quay, tmp_path,
def test_increment_version_after_delete(omps, quay, tmp_path,
delete_version, next_version):
"""
Auto-incrementing the version works as expected,
Expand Down Expand Up @@ -167,4 +174,6 @@ def test_increment_version_after_delete(test_env, omps, quay, tmp_path,
assert response.status_code == requests.codes.ok
assert response.json()['version'] == next_version
assert quay.get_release(test_env['test_namespace'],
test_env['test_package'], next_version)
test_env['test_package'],
next_version,
authorization=None)
36 changes: 22 additions & 14 deletions tests/integration/push_archive/push_archive_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import shutil
import pytest
import requests
from tests.integration.utils import test_env


def test_initial_upload(test_env, omps, quay, tmp_path):
def test_initial_upload(omps, quay, tmp_path):
"""
When uploading an archive to a repository which is empty,
and no version is specified during the upload
Expand All @@ -30,13 +31,15 @@ def test_initial_upload(test_env, omps, quay, tmp_path):
assert response['repo'] == test_env['test_package']
assert response['version'] == '1.0.0'

releases = quay.get_releases(test_env['test_namespace'], test_env['test_package'])
releases = quay.get_releases(test_env['test_namespace'],
test_env['test_package'],
authorization=None)
assert releases
assert len(releases) == 1
assert releases[0]['release'] == '1.0.0'


def test_upload_with_version(test_env, omps, quay, tmp_path):
def test_upload_with_version(omps, quay, tmp_path):
"""
When specifying the version for an upload,
then the release is created with the version specified.
Expand All @@ -58,10 +61,13 @@ def test_upload_with_version(test_env, omps, quay, tmp_path):
assert response['repo'] == test_env['test_package']
assert response['version'] == version

assert quay.get_release(test_env['test_namespace'], test_env['test_package'], version)
assert quay.get_release(test_env['test_namespace'],
test_env['test_package'],
version,
authorization=None)


def test_increment_version(test_env, omps, quay, tmp_path):
def test_increment_version(omps, quay, tmp_path):
"""
When no version is specified, and there already are some releases in
the package,
Expand Down Expand Up @@ -93,10 +99,12 @@ def test_increment_version(test_env, omps, quay, tmp_path):
assert response['version'] == next_release

assert quay.get_release(test_env['test_namespace'],
test_env['test_package'], next_release)
test_env['test_package'],
next_release,
authorization=None)


def test_version_exists(test_env, omps, quay, tmp_path):
def test_version_exists(omps, quay, tmp_path):
"""
When the version already exists in the package,
then creating the new release fails.
Expand Down Expand Up @@ -127,7 +135,7 @@ def test_version_exists(test_env, omps, quay, tmp_path):
('1.a.2'),
('1.1'),
])
def test_incorrect_version(test_env, omps, tmp_path, version):
def test_incorrect_version(omps, tmp_path, version):
"""
When the version specified does not meet OMPS requirements,
then the push fails.
Expand All @@ -143,7 +151,7 @@ def test_incorrect_version(test_env, omps, tmp_path, version):
assert version in response.json()['message']


def test_filetype_not_supported(test_env, omps, tmpdir):
def test_filetype_not_supported(omps, tmpdir):
"""
If the file uploaded is not a ZIP file,
then the push fails.
Expand All @@ -157,7 +165,7 @@ def test_filetype_not_supported(test_env, omps, tmpdir):
assert 'not a zip file' in response.json()['message']


def test_file_extension_not_zip(test_env, omps, tmpdir):
def test_file_extension_not_zip(omps, tmpdir):
"""
If the extension of the file is not '.zip',
then the push fails.
Expand All @@ -171,7 +179,7 @@ def test_file_extension_not_zip(test_env, omps, tmpdir):
assert 'file extension' in response.json()['message']


def test_no_file_field(test_env, omps, tmp_path):
def test_no_file_field(omps, tmp_path):
"""
The ZIP file uploaded must be assigned to the 'file' field.
"""
Expand All @@ -186,7 +194,7 @@ def test_no_file_field(test_env, omps, tmp_path):
assert 'No field "file"' in response.json()['message']


def test_organization_unaccessible_in_quay(test_env, omps, tmp_path):
def test_organization_unaccessible_in_quay(omps, tmp_path):
"""
Push fails, if the organization is not configured in OMPS.
"""
Expand All @@ -201,7 +209,7 @@ def test_organization_unaccessible_in_quay(test_env, omps, tmp_path):
assert 'Cannot retrieve information about package' in response.json()['message']


def test_upload_password_protected_zip(test_env, omps):
def test_upload_password_protected_zip(omps):
"""
Push fails, if the ZIP-file is password-protected.
"""
Expand All @@ -214,7 +222,7 @@ def test_upload_password_protected_zip(test_env, omps):
assert 'is encrypted' in response.json()['message']


def test_upload_invalid_artifact(test_env, omps, tmp_path):
def test_upload_invalid_artifact(omps, tmp_path):
"""
Push fails, if the artifact does not pass quay-courier validation.
"""
Expand Down
Loading

0 comments on commit 653faa0

Please sign in to comment.