Skip to content

Commit

Permalink
Merge pull request #3694 from rochacbruno/fix_smash_1124
Browse files Browse the repository at this point in the history
Add test to ensure specific fields are returned from API
  • Loading branch information
dralley committed Oct 4, 2018
2 parents 1355cde + d876276 commit dc3eb83
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 2 deletions.
31 changes: 31 additions & 0 deletions pulpcore/tests/functional/api/test_crud_distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""Tests that CRUD distributions."""
import unittest

from itertools import permutations
from requests.exceptions import HTTPError

from pulp_smash import api, config, utils
Expand Down Expand Up @@ -52,6 +53,36 @@ def test_02_read_distribution(self):
with self.subTest(key=key):
self.assertEqual(distribution[key], val)

@skip_if(bool, 'distribution', False)
def test_02_read_distribution_with_specific_fields(self):
"""Read a distribution by its href providing specific field list.
Permutate field list to ensure different combinations on result.
"""
fields = ('_href', 'base_path', 'base_url', 'created')
for field_pair in permutations(fields, 2):
# ex: field_pair = ('_href', 'base_url)
with self.subTest(field_pair=field_pair):
distribution = self.client.get(
self.distribution['_href'],
params={'fields': ','.join(field_pair)}
)
self.assertEqual(
sorted(field_pair), sorted(distribution.keys())
)

@skip_if(bool, 'distribution', False)
def test_02_read_distribution_without_specific_fields(self):
"""Read a distribution by its href excluding specific fields."""
# requests doesn't allow the use of != in parameters.
url = '{}?fields!=base_path,base_url'.format(
self.distribution['_href']
)
distribution = self.client.get(url)
response_fields = distribution.keys()
self.assertNotIn('base_path', response_fields)
self.assertNotIn('base_url', response_fields)

@skip_if(bool, 'distribution', False)
def test_02_read_distributions(self):
"""Read a distribution using query parameters.
Expand Down
30 changes: 30 additions & 0 deletions pulpcore/tests/functional/api/test_crud_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""Tests that CRUD repositories."""
import unittest

from itertools import permutations
from requests.exceptions import HTTPError

from pulp_smash import api, config, utils
Expand Down Expand Up @@ -47,6 +48,35 @@ def test_02_read_repo(self):
with self.subTest(key=key):
self.assertEqual(repo[key], val)

@skip_if(bool, 'repo', False)
def test_02_read_repo_with_specific_fields(self):
"""Read a repository by its href providing specific field list.
Permutate field list to ensure different combinations on result.
"""
fields = (
'_href', 'created', '_versions_href', '_latest_version_href',
'name', 'description', 'notes'
)
for field_pair in permutations(fields, 2):
# ex: field_pair = ('_href', 'notes)
with self.subTest(field_pair=field_pair):
repo = self.client.get(
self.repo['_href'],
params={'fields': ','.join(field_pair)}
)
self.assertEqual(sorted(field_pair), sorted(repo.keys()))

@skip_if(bool, 'repo', False)
def test_02_read_repo_without_specific_fields(self):
"""Read a repo by its href excluding specific fields."""
# requests doesn't allow the use of != in parameters.
url = '{}?fields!=created,name'.format(self.repo['_href'])
repo = self.client.get(url)
response_fields = repo.keys()
self.assertNotIn('created', response_fields)
self.assertNotIn('name', response_fields)

@skip_if(bool, 'repo', False)
def test_02_read_repos(self):
"""Read the repository by its name."""
Expand Down
19 changes: 19 additions & 0 deletions pulpcore/tests/functional/api/test_crud_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,25 @@ def test_02_read_user(self):
with self.subTest(key=key):
self.assertEqual(val, self.user[key])

@skip_if(bool, 'user', False)
def test_02_read_user_with_specific_fields(self):
"""Read a user byt its _href providing specific field name."""
for field in ('_href', 'username'):
user = self.client.get(
self.user['_href'],
params={'fields': field}
)
with self.subTest(key=field):
self.assertEqual((field,), tuple(user.keys()))

@skip_if(bool, 'user', False)
def test_02_read_user_without_specific_fields(self):
"""Read a user by its href excluding specific fields."""
# requests doesn't allow the use of != in parameters.
url = '{}?fields!=username'.format(self.user['_href'])
user = self.client.get(url)
self.assertNotIn('username', user.keys())

@skip_if(bool, 'user', False)
def test_02_read_username(self):
"""Read a user by its username.
Expand Down
31 changes: 31 additions & 0 deletions pulpcore/tests/functional/api/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,37 @@ def test_02_read_href(self):
with self.subTest(key=key):
self.assertEqual(task[key], val, task)

@skip_if(bool, 'task', False)
def test_02_read_href_with_specific_fields(self):
"""Read a task by its _href providing specific fields."""
fields = ('_href', 'state', 'worker')
task = self.client.get(
self.task['_href'],
params={'fields': ','.join(fields)}
)
self.assertEqual(sorted(fields), sorted(task.keys()))

@skip_if(bool, 'task', False)
def test_02_read_task_without_specific_fields(self):
"""Read a task by its href excluding specific fields."""
# requests doesn't allow the use of != in parameters.
url = '{}?fields!=state'.format(self.task['_href'])
task = self.client.get(url)
self.assertNotIn('state', task.keys())

@skip_if(bool, 'task', False)
def test_02_read_task_with_minimal_fields(self):
"""Read a task by its href filtering minimal fields."""
task = self.client.get(
self.task['_href'],
params={'minimal': True}
)
response_fields = task.keys()
self.assertNotIn('progress_reports', response_fields)
self.assertNotIn('spawned_tasks', response_fields)
self.assertNotIn('error', response_fields)
self.assertNotIn('non_fatal_errors', response_fields)

@skip_if(bool, 'task', False)
def test_02_read_invalid_worker(self):
"""Read a task using an invalid worker name."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
"""Tests that perform actions over publications."""
import unittest

from itertools import permutations
from requests.exceptions import HTTPError

from pulp_smash import api, config
from pulp_smash.pulp3.constants import DISTRIBUTION_PATH, PUBLICATIONS_PATH, REPO_PATH
from pulp_smash.pulp3.constants import (
DISTRIBUTION_PATH,
PUBLICATIONS_PATH,
REPO_PATH
)
from pulp_smash.pulp3.utils import (
gen_distribution,
gen_repo,
publish,
sync,
sync
)

from tests.functional.api.using_plugin.constants import (
Expand Down Expand Up @@ -70,6 +75,32 @@ def test_02_read_publication(self):
with self.subTest(key=key):
self.assertEqual(publication[key], val)

@skip_if(bool, 'publication', False)
def test_02_read_publication_with_specific_fields(self):
"""Read a publication by its href providing specific field list.
Permutate field list to ensure different combinations on result.
"""
fields = ('_href', 'created', 'distributions', 'publisher')
for field_pair in permutations(fields, 2):
# ex: field_pair = ('_href', 'created)
with self.subTest(field_pair=field_pair):
publication = self.client.get(
self.publication['_href'],
params={'fields': ','.join(field_pair)}
)
self.assertEqual(
sorted(field_pair), sorted(publication.keys())
)

@skip_if(bool, 'publication', False)
def test_02_read_publication_without_specific_fields(self):
"""Read a publication by its href excluding specific fields."""
# requests doesn't allow the use of != in parameters.
url = '{}?fields!=distributions'.format(self.publication['_href'])
publication = self.client.get(url)
self.assertNotIn('distributions', publication.keys())

@skip_if(bool, 'publication', False)
def test_02_read_publications(self):
"""Read a publication by its repository version."""
Expand Down

0 comments on commit dc3eb83

Please sign in to comment.