This repository has been archived by the owner on May 24, 2023. It is now read-only.
-
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.
Currently only supported version is /v1. Signed-off-by: Martin Bašti <mbasti@redhat.com>
- Loading branch information
1 parent
e3f103b
commit fcea465
Showing
12 changed files
with
211 additions
and
78 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
File renamed without changes.
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,10 @@ | ||
# | ||
# Copyright (C) 2019 Red Hat, Inc | ||
# see the LICENSE file for license | ||
# | ||
|
||
from flask import Blueprint | ||
|
||
API = Blueprint('v1', __name__) | ||
|
||
from . import packages, push # register routes |
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
File renamed without changes.
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,50 @@ | ||
# | ||
# Copyright (C) 2019 Red Hat, Inc | ||
# see the LICENSE file for license | ||
# | ||
|
||
from collections import namedtuple | ||
|
||
import pytest | ||
|
||
|
||
EntrypointMeta = namedtuple('EntrypointMeta', 'url_path,org,repo,version') | ||
|
||
|
||
@pytest.fixture(params=[ | ||
True, # endpoint with version | ||
False, # endpoint without version | ||
]) | ||
def endpoint_push_zipfile(request, release_version): | ||
"""Returns URL for zipfile endpoints""" | ||
organization = 'testorg' | ||
repo = 'repo-Y' | ||
version = release_version if request.param else None | ||
|
||
url_path = '/v1/{}/{}/zipfile'.format(organization, repo) | ||
if version: | ||
url_path = '{}/{}'.format(url_path, version) | ||
|
||
yield EntrypointMeta( | ||
url_path=url_path, org=organization, | ||
repo=repo, version=version | ||
) | ||
|
||
|
||
@pytest.fixture(params=[ | ||
True, # endpoint with version | ||
False, # endpoint without version | ||
]) | ||
def endpoint_packages(request, release_version): | ||
"""Returns URL for packages endpoints""" | ||
organization = 'testorg' | ||
repo = 'repo-Y' | ||
|
||
url_path = '/v1/{}/{}'.format(organization, repo) | ||
if request.param: | ||
url_path = '{}/{}'.format(url_path, release_version) | ||
|
||
yield EntrypointMeta( | ||
url_path=url_path, org=organization, | ||
repo=repo, version=release_version | ||
) |
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,117 @@ | ||
# | ||
# Copyright (C) 2019 Red Hat, Inc | ||
# see the LICENSE file for license | ||
# | ||
|
||
from io import BytesIO | ||
|
||
import pytest | ||
|
||
from omps import constants | ||
|
||
|
||
def test_push_zipfile( | ||
client, valid_manifests_archive, endpoint_push_zipfile, | ||
mocked_quay_io, mocked_op_courier_push): | ||
"""Test REST API for pushing operators form zipfile""" | ||
with open(valid_manifests_archive, 'rb') as f: | ||
data = { | ||
'file': (f, f.name), | ||
} | ||
rv = client.post( | ||
endpoint_push_zipfile.url_path, | ||
data=data, | ||
content_type='multipart/form-data', | ||
) | ||
|
||
assert rv.status_code == 200, rv.get_json() | ||
expected = { | ||
'organization': endpoint_push_zipfile.org, | ||
'repo': endpoint_push_zipfile.repo, | ||
'version': endpoint_push_zipfile.version or constants.DEFAULT_RELEASE_VERSION, | ||
'extracted_files': ['empty.yml'], | ||
} | ||
assert rv.get_json() == expected | ||
|
||
|
||
@pytest.mark.parametrize('filename', ( | ||
'test.json', # test invalid extension | ||
'test.zip', # test invalid content | ||
)) | ||
def test_push_zipfile_invalid_file( | ||
client, filename, endpoint_push_zipfile, | ||
mocked_quay_io): | ||
"""Test if proper error is returned when no zip file is being attached""" | ||
data = { | ||
'file': (BytesIO(b'randombytes'), filename), | ||
} | ||
rv = client.post( | ||
endpoint_push_zipfile.url_path, | ||
data=data, | ||
content_type='multipart/form-data', | ||
) | ||
|
||
assert rv.status_code == 400, rv.get_json() | ||
rv_json = rv.get_json() | ||
assert rv_json['status'] == 400 | ||
assert rv_json['error'] == 'OMPSUploadedFileError' | ||
|
||
|
||
def test_push_zipfile_no_file(client, endpoint_push_zipfile, mocked_quay_io): | ||
"""Test if proper error is returned when no file is being attached""" | ||
rv = client.post(endpoint_push_zipfile.url_path) | ||
assert rv.status_code == 400, rv.get_json() | ||
rv_json = rv.get_json() | ||
assert rv_json['status'] == 400 | ||
assert rv_json['error'] == 'OMPSExpectedFileError' | ||
|
||
|
||
def test_push_koji_nvr(client): | ||
"""Test REST API for pushing operators form koji by NVR""" | ||
rv = client.post('/v1/organization-X/repo-Y/koji/nvr-Z') | ||
assert rv.status_code == 200 | ||
expected = { | ||
'organization': 'organization-X', | ||
'repo': 'repo-Y', | ||
'nvr': 'nvr-Z', | ||
'msg': 'Not Implemented. Testing only' | ||
} | ||
assert rv.get_json() == expected | ||
|
||
|
||
ZIP_ENDPOINT_NOVER = '/v1/organization-X/repo-Y/zipfile' | ||
@pytest.mark.parametrize('endpoint', [ | ||
ZIP_ENDPOINT_NOVER, | ||
'/v1/organization-X/repo-Y/zipfile/1.0.1', | ||
'/v1/organization-X/repo-Y/koji/nvr-Z', | ||
]) | ||
@pytest.mark.parametrize('method', [ | ||
'GET', 'PATCH' 'PUT', 'HEAD', 'DELETE', 'TRACE', | ||
]) | ||
def test_method_not_allowed(client, endpoint, method): | ||
"""Specified endpoints currently support only POST method, test if other | ||
HTTP methods returns proper error code | ||
Method OPTIONS is excluded from testing due its special meaning | ||
""" | ||
if (endpoint, method) == (ZIP_ENDPOINT_NOVER, 'DELETE'): | ||
# accepted, collides with [DELETE] /org/repo/version | ||
return | ||
|
||
rv = client.open(endpoint, method=method) | ||
assert rv.status_code == 405 | ||
|
||
|
||
@pytest.mark.parametrize('endpoint', [ | ||
'/', | ||
'/v1' | ||
'/v1/organization-X/repo-Y/koji/', | ||
'/v1/organization-X/repo-Y/zipfile/version-Z/extra-something', | ||
]) | ||
def test_404_for_mistyped_entrypoints(client, endpoint): | ||
"""Test if HTTP 404 is returned for unexpected endpoints""" | ||
rv = client.post(endpoint) | ||
assert rv.status_code == 404 | ||
rv_json = rv.get_json() | ||
assert rv_json['error'] == 'NotFound' | ||
assert rv_json['status'] == 404 |
Oops, something went wrong.