# Path: freezer_api/api/v1/sessions.py
# class SessionsCollectionResource(resource.BaseResource):
# class SessionsResource(resource.BaseResource):
# class SessionsAction(resource.BaseResource):
# class Session(resource.BaseResource):
# class SessionsJob(resource.BaseResource):
#     def __init__(self, storage_driver):
#     def on_get(self, req, resp):
#     def on_post(self, req, resp):
#     def __init__(self, storage_driver):
#     def on_get(self, req, resp, session_id):
#     def on_delete(self, req, resp, session_id):
#     def on_patch(self, req, resp, session_id):
#     def on_post(self, req, resp, session_id):
#     def __init__(self, storage_driver):
#     def on_post(self, req, resp, session_id):
#     def __init__(self, doc):
#     def session_tag(self):
#     def session_tag(self, value):
#     def execute_action(self, action, params):
#     def end(self, job_id, result):
#     def start(self, job_id, job_tag):
#     def get_job_overall_result(self):
#     def set_job_end(self, job_id, result, timestamp):
#     def set_job_start(self, job_id, timestamp):
#     def __init__(self, storage_driver):
#     def on_put(self, req, resp, session_id, job_id):
#     def on_delete(self, req, resp, session_id, job_id):
# 
# 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 freezer_api.api.v1 import sessions as v1_sessions
from freezer_api.common import exceptions
from freezer_api.tests.unit import common
        session = common.get_fake_session_0()
        self.mock_json_body.return_value = session
        expected_result = {'session_id': common.fake_session_0['session_id'],
                           'version': new_version}

        self.resource.on_post(self.mock_req, self.mock_req,
                              common.fake_session_0['session_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_session_raises(self):
        self.mock_db.replace_session.side_effect = exceptions.AccessForbidden(
            'regular test failure')
        session = common.get_fake_session_0()
        self.mock_json_body.return_value = session
        self.assertRaises(exceptions.AccessForbidden, self.resource.on_post,
                          self.mock_req,
                          self.mock_req,
                          common.fake_session_0['session_id'])


class TestSessionsAction(common.FreezerBaseTestCase):
    def setUp(self):
        super(TestSessionsAction, self).setUp()
        self.mock_db = mock.Mock()
        self.mock_req = mock.MagicMock()
        self.mock_req.env.__getitem__.side_effect = common.get_req_items
        self.mock_req.get_header.return_value = common.fake_session_0[
            'user_id']
        self.mock_req.status = falcon.HTTP_200

# Path: freezer_api/api/v1/sessions.py
# class SessionsCollectionResource(resource.BaseResource):
# class SessionsResource(resource.BaseResource):
# class SessionsAction(resource.BaseResource):
# class Session(resource.BaseResource):
# class SessionsJob(resource.BaseResource):
#     def __init__(self, storage_driver):
#     def on_get(self, req, resp):
#     def on_post(self, req, resp):
#     def __init__(self, storage_driver):
#     def on_get(self, req, resp, session_id):
#     def on_delete(self, req, resp, session_id):
#     def on_patch(self, req, resp, session_id):
#     def on_post(self, req, resp, session_id):
#     def __init__(self, storage_driver):
#     def on_post(self, req, resp, session_id):
#     def __init__(self, doc):
#     def session_tag(self):
#     def session_tag(self, value):
#     def execute_action(self, action, params):
#     def end(self, job_id, result):
#     def start(self, job_id, job_tag):
#     def get_job_overall_result(self):
#     def set_job_end(self, job_id, result, timestamp):
#     def set_job_start(self, job_id, timestamp):
#     def __init__(self, storage_driver):
#     def on_put(self, req, resp, session_id, job_id):
#     def on_delete(self, req, resp, session_id, job_id):
# 
# 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_sessions.py
import random
import falcon
from unittest import mock
from unittest.mock import patch
from freezer_api.api.v1 import sessions as v1_sessions
from freezer_api.common import exceptions
from freezer_api.tests.unit import common

        session = common.get_fake_session_0()
        self.mock_json_body.return_value = session
        expected_result = {'session_id': common.fake_session_0['session_id'],
                           'version': new_version}

        self.resource.on_post(self.mock_req, self.mock_req,
                              common.fake_session_0['session_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_session_raises(self):
        self.mock_db.replace_session.side_effect = exceptions.AccessForbidden(
            'regular test failure')
        session = common.get_fake_session_0()
        self.mock_json_body.return_value = session
        self.assertRaises(exceptions.AccessForbidden, self.resource.on_post,
                          self.mock_req,
                          self.mock_req,
                          common.fake_session_0['session_id'])


class TestSessionsAction(common.FreezerBaseTestCase):
    def setUp(self):
        super(TestSessionsAction, self).setUp()
        self.mock_db = mock.Mock()
        self.mock_req = mock.MagicMock()
        self.mock_req.env.__getitem__.side_effect = common.get_req_items
        self.mock_req.get_header.return_value = common.fake_session_0[
            'user_id']
        self.mock_req.status = falcon.HTTP_200

        self.resource = v1_sessions.SessionsAction(self.mock_db)