# Path: tests/pulp_test.py
# def requires(*things):
# def requires_any(thing, condition=lambda item: True):
#     def wrapped():
#     def setUpClass(cls):
#     def assertPulpOK(self):
#     def assertPulp(self, code=200, data={}):
#     def assertEqual(self, a, b, msg=None):
#     def tearDownClass(cls):
# def agent_test(catching=False, frequency=1):
#     def decorator_maker(method):
#         def decorated_method(self):
#     def setUpClass(cls):
#     def tearDownClass(cls):
# def stacked_ctx(ctxmanager):
#     def stacked(*things):
# def calling_method(thing, method, *args, **kvs):
# def deleting(pulp, *things):
#     def wrapper_ctx(thing):
# class PulpTest(unittest.TestCase):
# class ConsumerAgentPulpTest(PulpTest):
# class InventoryInducedSkip(unittest.SkipTest):
# 
# Path: pulp_auto/repo.py
# class RepoAppl(object):
#     path = '/repositories/'
# 
#     @staticmethod
#     def applicability(
#         pulp,
#         data,
#         path='/actions/content/regenerate_applicability/'
#     ):
#         path = path_join(RepoAppl.path, path)
#         return pulp.send(Request('POST', path=path, data=data))
# 
# 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)


import json, unittest
from tests import pulp_test
from pulp_auto.repo import RepoAppl
from pulp_auto.task import Task


def setUpModule():
    pass


class RepoApplicabilty(pulp_test.PulpTest):

    def test_01_repo_content_applicability(self):
        response = RepoAppl.applicability(self.pulp, data={
                                         "repo_criteria": {"filters": {"id":{"$in":["test-repo", "test-errata"]}}}
                                                     }
                                    )
        self.assertPulp(code=202)
        Task.wait_for_report(self.pulp, response)
        # TODO: assert applicability tags in task response
        # TODO: assert the applicability applies OK :) or is sane

    def test_02_repo_content_applicability_invalid_param(self):
        #response_code: 400,if one or more of the parameters is invalid

# Path: tests/pulp_test.py
# def requires(*things):
# def requires_any(thing, condition=lambda item: True):
#     def wrapped():
#     def setUpClass(cls):
#     def assertPulpOK(self):
#     def assertPulp(self, code=200, data={}):
#     def assertEqual(self, a, b, msg=None):
#     def tearDownClass(cls):
# def agent_test(catching=False, frequency=1):
#     def decorator_maker(method):
#         def decorated_method(self):
#     def setUpClass(cls):
#     def tearDownClass(cls):
# def stacked_ctx(ctxmanager):
#     def stacked(*things):
# def calling_method(thing, method, *args, **kvs):
# def deleting(pulp, *things):
#     def wrapper_ctx(thing):
# class PulpTest(unittest.TestCase):
# class ConsumerAgentPulpTest(PulpTest):
# class InventoryInducedSkip(unittest.SkipTest):
# 
# Path: pulp_auto/repo.py
# class RepoAppl(object):
#     path = '/repositories/'
# 
#     @staticmethod
#     def applicability(
#         pulp,
#         data,
#         path='/actions/content/regenerate_applicability/'
#     ):
#         path = path_join(RepoAppl.path, path)
#         return pulp.send(Request('POST', path=path, data=data))
# 
# 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)


# Path: tests/general_tests/test_02_repo_applicability.py
import json, unittest
from tests import pulp_test
from pulp_auto.repo import RepoAppl
from pulp_auto.task import Task



def setUpModule():
    pass


class RepoApplicabilty(pulp_test.PulpTest):

    def test_01_repo_content_applicability(self):
        response = RepoAppl.applicability(self.pulp, data={
                                         "repo_criteria": {"filters": {"id":{"$in":["test-repo", "test-errata"]}}}
                                                     }
                                    )
        self.assertPulp(code=202)
        Task.wait_for_report(self.pulp, response)
        # TODO: assert applicability tags in task response
        # TODO: assert the applicability applies OK :) or is sane

    def test_02_repo_content_applicability_invalid_param(self):
        #response_code: 400,if one or more of the parameters is invalid

        RepoAppl.applicability(self.pulp, data={