# Path: pulp_auto/task.py
# class Task(TaskDetails, AbstractTask, Item):
#     '''an item-view task'''
#     path = '/tasks/'
# 
#     @classmethod
#     def wait_for_response(cls, pulp, response, timeout=120):
#         '''a shortcut for wait & from_response'''
#         ret = cls.from_response(response)
#         if isinstance(ret, list):
#             # more than one task pending
#             for task in ret:
#                 task.wait(pulp, timeout=timeout)
#         else:
#             ret.wait(pulp, timeout=timeout)
# 
#     @classmethod
#     def from_report(cls, pulp, report):
#         # report-based constructor
#         # now every asyncronous call returns a call report object
#         # call report has 'spawned_tasks' that contains list of tasks
#         # meanwhile every tasks can have its own spawned tasks
#         data = report.json()
#         assert 'spawned_tasks' in data, 'invalid report data: %s' % data
#         reported_tasks = data['spawned_tasks']
#         if not reported_tasks:
#             return []
#         ret = []
#         for reported_task in reported_tasks:
#             response = pulp.send(Request('GET', strip_url(reported_task['_href'])))
#             assert pulp.is_ok, response.reason
#             task = Task.from_response(response)
#             ret.append(task)
#             if 'spawned_tasks' in task.data:
#                 # recurse
#                 ret += cls.from_report(pulp, response)
#         return ret
# 
#     @classmethod
#     def from_call_report_data(cls, data):
#         # older interface; event-listeners still use this to report tasks
#         assert 'call_report' in data, 'invalid data format: %s' % data
#         return cls(data['call_report'])
# 
# 
# 
#     @classmethod
#     def wait_for_report(cls, pulp, response, timeout=300):
#         tasks = Task.from_report(pulp, response)
#         for task in tasks:
#             task.wait(pulp, timeout=timeout)
# 
#     @classmethod
#     def wait_for_reports(cls, pulp, responses, timeout=300):
#         # a wrapper for multiple task report waiting
#         # will take up to sum(tasks.time)
#         # single-exception breaks
#         for response in responses:
#             cls.wait_for_report(pulp, response, timeout)
# 
# class TaskFailure(TaskError):
#     '''task failed'''
# 
# Path: tests/pulp_test.py
# class PulpTest(unittest.TestCase):
#     @classmethod
#     def setUpClass(cls):
#         if getattr(cls, '__unittest_skip__', False):
#             # FIXME: suggest a unittest patch dealing setUpClass being called even though __unittest_skip__ is set
#             raise unittest.SkipTest(getattr(cls, '__unittest_skip_why__', ''))
#         cls.pulp = Pulp(ROLES.pulp.url, tuple(ROLES.pulp.auth), ROLES.pulp.verify_api_ssl)
#         cls.log = logging.getLogger(cls.__name__)
# 
#     def assertPulpOK(self):
#         self.assertTrue(
#             self.pulp.is_ok,
#             "pulp was not OK:\n%s" % format_response(self.pulp.last_response)
#         )
# 
#     def assertPulp(self, code=200, data={}):
#         self.assertEqual(
#             self.pulp.last_response.status_code,
#             code
#         )
#         response_data = self.pulp.last_response.json()
#         for k, v in data:
#             self.assertIn(k, response_data)
#             self.assertEqual(v, response_data[k])
# 
#     def assertEqual(self, a, b, msg=None):
#         if msg is None:
#             super(PulpTest, self).assertEqual(a, b, pprint.pformat("%r != %r" % (a, b)))
#         else:
#             super(PulpTest, self).assertEqual(a, b, msg)
# 
#     @classmethod
#     def tearDownClass(cls):
#         '''nothing to do'''
#         pass
# 
# def requires_any(thing, condition=lambda item: True):
#     '''skip test case unless there are any thing items ROLES for which the condition holds'''
#     @requires(thing)
#     def wrapped():
#         '''create propper decorator --- either skipping one or "empty" one'''
#         if not any(map(condition, locate_ns_item(ROLES, thing))):
#             return unittest.skip("no suitable items found in ROLES.%s" % thing)
#         return lambda function: function
#     return wrapped()
# 
# Path: tests/conf/roles.py

# 
# Path: tests/conf/facade/yum.py
# class YumRepo(Repo):
# 
#     def __init__(self, notes={'_repo-type': 'rpm-repo'}, **kvs):
#         super(YumRepo, self).__init__(notes=notes, **kvs)
# 
#     @classmethod
#     def from_role(cls, repo):
#         importer = YumImporter.from_role(repo)
#         distributors = [YumDistributor.from_role(repo)]
#         return cls(id=repo.id, display_name=repo.get('display_name'),
#                     description=repo.get('description'), importer=importer,
#                     distributors=distributors)


from pulp_auto.consumer import (Cli, RpmUnit, YumRepo, RpmRepo, Consumer)
from pulp_auto.task import (Task, TaskFailure)
from tests.pulp_test import (PulpTest, requires_any)
from tests.conf.roles import ROLES
from tests.conf.facade.yum import YumRepo as FacadeYumRepo

def setUpModule():
    pass

def tearDownModule():
    pass

@requires_any('consumers')

# Path: pulp_auto/task.py
# class Task(TaskDetails, AbstractTask, Item):
#     '''an item-view task'''
#     path = '/tasks/'
# 
#     @classmethod
#     def wait_for_response(cls, pulp, response, timeout=120):
#         '''a shortcut for wait & from_response'''
#         ret = cls.from_response(response)
#         if isinstance(ret, list):
#             # more than one task pending
#             for task in ret:
#                 task.wait(pulp, timeout=timeout)
#         else:
#             ret.wait(pulp, timeout=timeout)
# 
#     @classmethod
#     def from_report(cls, pulp, report):
#         # report-based constructor
#         # now every asyncronous call returns a call report object
#         # call report has 'spawned_tasks' that contains list of tasks
#         # meanwhile every tasks can have its own spawned tasks
#         data = report.json()
#         assert 'spawned_tasks' in data, 'invalid report data: %s' % data
#         reported_tasks = data['spawned_tasks']
#         if not reported_tasks:
#             return []
#         ret = []
#         for reported_task in reported_tasks:
#             response = pulp.send(Request('GET', strip_url(reported_task['_href'])))
#             assert pulp.is_ok, response.reason
#             task = Task.from_response(response)
#             ret.append(task)
#             if 'spawned_tasks' in task.data:
#                 # recurse
#                 ret += cls.from_report(pulp, response)
#         return ret
# 
#     @classmethod
#     def from_call_report_data(cls, data):
#         # older interface; event-listeners still use this to report tasks
#         assert 'call_report' in data, 'invalid data format: %s' % data
#         return cls(data['call_report'])
# 
# 
# 
#     @classmethod
#     def wait_for_report(cls, pulp, response, timeout=300):
#         tasks = Task.from_report(pulp, response)
#         for task in tasks:
#             task.wait(pulp, timeout=timeout)
# 
#     @classmethod
#     def wait_for_reports(cls, pulp, responses, timeout=300):
#         # a wrapper for multiple task report waiting
#         # will take up to sum(tasks.time)
#         # single-exception breaks
#         for response in responses:
#             cls.wait_for_report(pulp, response, timeout)
# 
# class TaskFailure(TaskError):
#     '''task failed'''
# 
# Path: tests/pulp_test.py
# class PulpTest(unittest.TestCase):
#     @classmethod
#     def setUpClass(cls):
#         if getattr(cls, '__unittest_skip__', False):
#             # FIXME: suggest a unittest patch dealing setUpClass being called even though __unittest_skip__ is set
#             raise unittest.SkipTest(getattr(cls, '__unittest_skip_why__', ''))
#         cls.pulp = Pulp(ROLES.pulp.url, tuple(ROLES.pulp.auth), ROLES.pulp.verify_api_ssl)
#         cls.log = logging.getLogger(cls.__name__)
# 
#     def assertPulpOK(self):
#         self.assertTrue(
#             self.pulp.is_ok,
#             "pulp was not OK:\n%s" % format_response(self.pulp.last_response)
#         )
# 
#     def assertPulp(self, code=200, data={}):
#         self.assertEqual(
#             self.pulp.last_response.status_code,
#             code
#         )
#         response_data = self.pulp.last_response.json()
#         for k, v in data:
#             self.assertIn(k, response_data)
#             self.assertEqual(v, response_data[k])
# 
#     def assertEqual(self, a, b, msg=None):
#         if msg is None:
#             super(PulpTest, self).assertEqual(a, b, pprint.pformat("%r != %r" % (a, b)))
#         else:
#             super(PulpTest, self).assertEqual(a, b, msg)
# 
#     @classmethod
#     def tearDownClass(cls):
#         '''nothing to do'''
#         pass
# 
# def requires_any(thing, condition=lambda item: True):
#     '''skip test case unless there are any thing items ROLES for which the condition holds'''
#     @requires(thing)
#     def wrapped():
#         '''create propper decorator --- either skipping one or "empty" one'''
#         if not any(map(condition, locate_ns_item(ROLES, thing))):
#             return unittest.skip("no suitable items found in ROLES.%s" % thing)
#         return lambda function: function
#     return wrapped()
# 
# Path: tests/conf/roles.py

# 
# Path: tests/conf/facade/yum.py
# class YumRepo(Repo):
# 
#     def __init__(self, notes={'_repo-type': 'rpm-repo'}, **kvs):
#         super(YumRepo, self).__init__(notes=notes, **kvs)
# 
#     @classmethod
#     def from_role(cls, repo):
#         importer = YumImporter.from_role(repo)
#         distributors = [YumDistributor.from_role(repo)]
#         return cls(id=repo.id, display_name=repo.get('display_name'),
#                     description=repo.get('description'), importer=importer,
#                     distributors=distributors)


# Path: tests/general_tests/test_13_cli_consumer.py
from pulp_auto.consumer import (Cli, RpmUnit, YumRepo, RpmRepo, Consumer)
from pulp_auto.task import (Task, TaskFailure)
from tests.pulp_test import (PulpTest, requires_any)
from tests.conf.roles import ROLES
from tests.conf.facade.yum import YumRepo as FacadeYumRepo


def setUpModule():
    pass

def tearDownModule():
    pass

@requires_any('consumers')

@requires_any('repos', lambda repo: repo.type == 'rpm')