-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add upload test case for collection. closes: #5262
- Loading branch information
koliveir
committed
Aug 15, 2019
1 parent
5eff697
commit c9e4a6a
Showing
3 changed files
with
70 additions
and
4 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
Add upload test case |
55 changes: 55 additions & 0 deletions
55
pulp_ansible/tests/functional/api/collection/test_upload.py
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,55 @@ | ||
# coding=utf-8 | ||
"""Tests related to upload of collections.""" | ||
import hashlib | ||
import unittest | ||
from urllib.parse import urljoin | ||
|
||
from pulp_smash import api, config | ||
from pulp_smash.pulp3.utils import delete_orphans | ||
from pulp_smash.utils import http_get | ||
from requests.exceptions import HTTPError | ||
|
||
from pulp_ansible.tests.functional.constants import ( | ||
ANSIBLE_COLLECTION_UPLOAD_FIXTURE_URL, | ||
COLLECTION_METADATA, | ||
) | ||
from pulp_ansible.tests.functional.utils import set_up_module as setUpModule # noqa:F401 | ||
|
||
|
||
class UploadCollectionTestCase(unittest.TestCase): | ||
"""Upload a collection.""" | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
"""Create class-wide variables.""" | ||
cls.cfg = config.get_config() | ||
delete_orphans(cls.cfg) | ||
cls.client = api.Client(cls.cfg) | ||
|
||
cls.collection = {"file": http_get(ANSIBLE_COLLECTION_UPLOAD_FIXTURE_URL)} | ||
cls.collection_sha256 = hashlib.sha256(cls.collection["file"]).hexdigest() | ||
|
||
def test_collection_upload(self): | ||
"""Upload a collection. | ||
This test targets the following issue: | ||
* `Pulp #5262 <https://pulp.plan.io/issues/5262>`_ | ||
""" | ||
UPLOAD_PATH = urljoin(self.cfg.get_base_url(), "ansible/collections/") | ||
response = self.client.post(UPLOAD_PATH, files=self.collection) | ||
|
||
for key, value in response.items(): | ||
with self.subTest(key=key): | ||
if key in COLLECTION_METADATA.keys(): | ||
self.assertEqual(COLLECTION_METADATA[key], value, response) | ||
|
||
self.assertEqual(response["sha256"], self.collection_sha256, response) | ||
|
||
with self.assertRaises(HTTPError) as ctx: | ||
self.client.using_handler(api.code_handler).post(UPLOAD_PATH, files=self.collection) | ||
|
||
for key in ("artifact", "already", "exists"): | ||
self.assertIn(key, ctx.exception.response.json()[0].lower(), ctx.exception.response) | ||
|
||
delete_orphans(self.cfg) |
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