# Path: freezer_api/api/v1/jobs.py
# class JobsBaseResource(resource.BaseResource):
# class JobsCollectionResource(JobsBaseResource):
# class JobsResource(JobsBaseResource):
# class JobsEvent(resource.BaseResource):
# class Action(object):
# class Job(object):
#     def __init__(self, storage_driver):
#     def get_action(self, user_id, action_id):
#     def update_actions_in_job(self, user_id, job_doc):
#     def on_get(self, req, resp):
#     def on_post(self, req, resp):
#     def on_get(self, req, resp, job_id):
#     def on_delete(self, req, resp, job_id):
#     def on_patch(self, req, resp, job_id):
#     def on_post(self, req, resp, job_id):
#     def __init__(self, storage_driver):
#     def on_post(self, req, resp, job_id):
#     def __init__(self, doc):
#     def action_id(self):
#     def action_id(self, value):
#     def create_new_action_id(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __init__(self, doc):
#     def execute_event(self, event, params):
#     def job_status(self):
#     def job_status(self, value):
#     def start(self, params=None):
#     def stop(self, params=None):
#     def abort(self, params=None):
#     def actions(self):
#     def expand_default_properties(self):
# 
# Path: freezer_api/common/exceptions.py
# class FreezerAPIException(falcon.HTTPError):
# class BadDataFormat(FreezerAPIException):
# class DocumentExists(FreezerAPIException):
# class StorageEngineError(FreezerAPIException):
# class DocumentNotFound(FreezerAPIException):
# class AccessForbidden(FreezerAPIException):
# class MethodNotImplemented(FreezerAPIException):
#     def __init__(self, message=''):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
# 
# Path: freezer_api/tests/unit/common.py
# CONF = cfg.CONF
# def get_fake_backup_metadata():
# def get_fake_job_0():
# def get_fake_job_1():
# def get_fake_job_2():
# def get_fake_job_3():
# def get_fake_job_id():
# def get_fake_client_0():
# def get_fake_client_1():
# def get_fake_client_id():
# def get_fake_action_0():
# def get_fake_action_1():
# def get_fake_action_2():
# def get_fake_action_id():
# def get_fake_action_3():
# def get_fake_session_0():
# def get_fake_session_1():
# def get_fake_session_2():
# def get_fake_session_3():
# def get_fake_session_id():
#     def __init__(self, method='GET', body=''):
#     def get_header(self, key):
#     def setUp(self):
#     def __init__(self, *args, **kwargs):
#     def to_dict(self):
# def get_req_items(name):
# class FakeReqResp(object):
# class FreezerBaseTestCase(testtools.TestCase):
# class FakeContext(object):


import random
import falcon
from unittest import mock
from unittest.mock import patch
from oslo_serialization import jsonutils as json
from freezer_api.api.v1 import jobs as v1_jobs
from freezer_api.common import exceptions
from freezer_api.tests.unit import common

    def test_on_post_ok(self):
        new_version = random.randint(0, 99)
        self.mock_db.replace_job.return_value = new_version
        job = common.get_fake_job_0()
        self.mock_req.stream.read.return_value = json.dumps(job)
        expected_result = {'job_id': common.fake_job_0_job_id,
                           'version': new_version}

        self.resource.on_post(self.mock_req, self.mock_req,
                              common.fake_job_0_job_id)
        self.assertEqual(falcon.HTTP_201, self.mock_req.status)
        self.assertEqual(expected_result, self.mock_req.body)

    def test_on_post_raises_when_db_replace_job_raises(self):
        self.mock_db.replace_job.side_effect = exceptions.AccessForbidden(
            'regular test failure')
        job = common.get_fake_job_0()
        self.mock_req.stream.read.return_value = json.dumps(job)
        self.assertRaises(exceptions.AccessForbidden, self.resource.on_post,
                          self.mock_req,
                          self.mock_req,
                          common.fake_job_0_job_id)


class TestJobsEvent(common.FreezerBaseTestCase):
    def setUp(self):
        super(TestJobsEvent, self).setUp()
        self.mock_db = mock.Mock()
        self.mock_req = mock.MagicMock()

# Path: freezer_api/api/v1/jobs.py
# class JobsBaseResource(resource.BaseResource):
# class JobsCollectionResource(JobsBaseResource):
# class JobsResource(JobsBaseResource):
# class JobsEvent(resource.BaseResource):
# class Action(object):
# class Job(object):
#     def __init__(self, storage_driver):
#     def get_action(self, user_id, action_id):
#     def update_actions_in_job(self, user_id, job_doc):
#     def on_get(self, req, resp):
#     def on_post(self, req, resp):
#     def on_get(self, req, resp, job_id):
#     def on_delete(self, req, resp, job_id):
#     def on_patch(self, req, resp, job_id):
#     def on_post(self, req, resp, job_id):
#     def __init__(self, storage_driver):
#     def on_post(self, req, resp, job_id):
#     def __init__(self, doc):
#     def action_id(self):
#     def action_id(self, value):
#     def create_new_action_id(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __init__(self, doc):
#     def execute_event(self, event, params):
#     def job_status(self):
#     def job_status(self, value):
#     def start(self, params=None):
#     def stop(self, params=None):
#     def abort(self, params=None):
#     def actions(self):
#     def expand_default_properties(self):
# 
# Path: freezer_api/common/exceptions.py
# class FreezerAPIException(falcon.HTTPError):
# class BadDataFormat(FreezerAPIException):
# class DocumentExists(FreezerAPIException):
# class StorageEngineError(FreezerAPIException):
# class DocumentNotFound(FreezerAPIException):
# class AccessForbidden(FreezerAPIException):
# class MethodNotImplemented(FreezerAPIException):
#     def __init__(self, message=''):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
# 
# Path: freezer_api/tests/unit/common.py
# CONF = cfg.CONF
# def get_fake_backup_metadata():
# def get_fake_job_0():
# def get_fake_job_1():
# def get_fake_job_2():
# def get_fake_job_3():
# def get_fake_job_id():
# def get_fake_client_0():
# def get_fake_client_1():
# def get_fake_client_id():
# def get_fake_action_0():
# def get_fake_action_1():
# def get_fake_action_2():
# def get_fake_action_id():
# def get_fake_action_3():
# def get_fake_session_0():
# def get_fake_session_1():
# def get_fake_session_2():
# def get_fake_session_3():
# def get_fake_session_id():
#     def __init__(self, method='GET', body=''):
#     def get_header(self, key):
#     def setUp(self):
#     def __init__(self, *args, **kwargs):
#     def to_dict(self):
# def get_req_items(name):
# class FakeReqResp(object):
# class FreezerBaseTestCase(testtools.TestCase):
# class FakeContext(object):


# Path: freezer_api/tests/unit/v1/test_jobs.py
import random
import falcon
from unittest import mock
from unittest.mock import patch
from oslo_serialization import jsonutils as json
from freezer_api.api.v1 import jobs as v1_jobs
from freezer_api.common import exceptions
from freezer_api.tests.unit import common


    def test_on_post_ok(self):
        new_version = random.randint(0, 99)
        self.mock_db.replace_job.return_value = new_version
        job = common.get_fake_job_0()
        self.mock_req.stream.read.return_value = json.dumps(job)
        expected_result = {'job_id': common.fake_job_0_job_id,
                           'version': new_version}

        self.resource.on_post(self.mock_req, self.mock_req,
                              common.fake_job_0_job_id)
        self.assertEqual(falcon.HTTP_201, self.mock_req.status)
        self.assertEqual(expected_result, self.mock_req.body)

    def test_on_post_raises_when_db_replace_job_raises(self):
        self.mock_db.replace_job.side_effect = exceptions.AccessForbidden(
            'regular test failure')
        job = common.get_fake_job_0()
        self.mock_req.stream.read.return_value = json.dumps(job)
        self.assertRaises(exceptions.AccessForbidden, self.resource.on_post,
                          self.mock_req,
                          self.mock_req,
                          common.fake_job_0_job_id)


class TestJobsEvent(common.FreezerBaseTestCase):
    def setUp(self):
        super(TestJobsEvent, self).setUp()
        self.mock_db = mock.Mock()
        self.mock_req = mock.MagicMock()

        self.mock_req.env.__getitem__.side_effect = common.get_req_items