Skip to content

Commit

Permalink
Add Python CRUD tests
Browse files Browse the repository at this point in the history
Add package `pulp_smash.tests.python`. Populate it with a variety of
modules, including a several utility modules and some CRUD tests. The
new CRUD tests pass with the following commands:

    python -m unittest2 discover pulp_smash.tests.python
    python -m unittest2 pulp_smash.tests.python.api_v2.test_crud
  • Loading branch information
Ichimonji10 committed Apr 18, 2016
1 parent 4b11dbb commit 752b15a
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ developers, not a gospel.
api/pulp_smash.tests.puppet.api_v2.test_sync_publish
api/pulp_smash.tests.puppet.api_v2.utils
api/pulp_smash.tests.puppet.utils
api/pulp_smash.tests.python
api/pulp_smash.tests.python.api_v2
api/pulp_smash.tests.python.api_v2.test_crud
api/pulp_smash.tests.python.api_v2.utils
api/pulp_smash.tests.python.utils
api/pulp_smash.tests.rpm
api/pulp_smash.tests.rpm.api_v2
api/pulp_smash.tests.rpm.api_v2.test_broker
Expand Down
3 changes: 3 additions & 0 deletions pulp_smash/tests/python/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# coding=utf-8
"""Functional tests for Pulp's Python plugin."""
from __future__ import unicode_literals
3 changes: 3 additions & 0 deletions pulp_smash/tests/python/api_v2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# coding=utf-8
"""Tests that communicate with the server via the v2 API."""
from __future__ import unicode_literals
68 changes: 68 additions & 0 deletions pulp_smash/tests/python/api_v2/test_crud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# coding=utf-8
"""Tests that CRUD Python repositories."""
from __future__ import unicode_literals

from pulp_smash import api, utils
from pulp_smash.constants import REPOSITORY_PATH
from pulp_smash.tests.python.api_v2.utils import gen_repo
from pulp_smash.tests.python.utils import set_up_module as setUpModule # noqa pylint:disable=unused-import


class CRUDTestCase(utils.BaseAPITestCase):
"""Test that one can create, read, update and delete a test case.
See:
Create
http://pulp.readthedocs.org/en/latest/dev-guide/integration/rest-api/repo/cud.html#create-a-repository
Read
http://pulp.readthedocs.org/en/latest/dev-guide/integration/rest-api/repo/retrieval.html#retrieve-a-single-repository
Update
http://pulp.readthedocs.org/en/latest/dev-guide/integration/rest-api/repo/cud.html#update-a-repository
Delete
http://pulp.readthedocs.org/en/latest/dev-guide/integration/rest-api/repo/cud.html#delete-a-repository
"""

@classmethod
def setUpClass(cls):
"""Create, update, read and delete a minimal Python repository."""
super(CRUDTestCase, cls).setUpClass()
client = api.Client(cls.cfg)
cls.bodies = (gen_repo(), {'delta': {'display_name': utils.uuid4()}})
cls.responses = {}
cls.responses['create'] = client.post(REPOSITORY_PATH, cls.bodies[0])
repo_href = cls.responses['create'].json()['_href']
cls.responses['update'] = client.put(repo_href, cls.bodies[1])
cls.responses['read'] = client.get(repo_href)
cls.responses['delete'] = client.delete(repo_href)

def test_status_codes(self):
"""Assert each response has a correct status code."""
for response, code in (
('create', 201),
('update', 200),
('read', 200),
('delete', 202)):
with self.subTest((response, code)):
self.assertEqual(self.responses[response].status_code, code)

def test_create(self):
"""Assert the repo create response has a correct repo ID."""
self.assertEqual(
self.bodies[0]['id'],
self.responses['create'].json()['id'],
)

def test_update(self):
"""Assert the repo update response has the requested changes."""
self.assertEqual(
self.bodies[1]['delta']['display_name'],
self.responses['update'].json()['result']['display_name'],
)

def test_read(self):
"""Assert the repo update response has the requested changes."""
self.assertEqual(
self.bodies[1]['delta']['display_name'],
self.responses['read'].json()['display_name'],
)
14 changes: 14 additions & 0 deletions pulp_smash/tests/python/api_v2/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# coding=utf-8
"""Utility functions for Python API tests."""
from __future__ import unicode_literals

from pulp_smash import utils


def gen_repo():
"""Return a semi-random dict for use in creating a Python repository."""
return {
'id': utils.uuid4(),
'importer_config': {},
'importer_type_id': 'python_importer',
}
13 changes: 13 additions & 0 deletions pulp_smash/tests/python/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# coding=utf-8
"""Utilities for Python tests."""
from __future__ import unicode_literals

from pulp_smash import utils


def set_up_module():
"""Skip tests if the Python plugin is not installed.
See :mod:`pulp_smash.tests` for more information.
"""
utils.skip_if_type_is_unsupported('python_package')

0 comments on commit 752b15a

Please sign in to comment.