# Path: freezer_api/api/v2/actions.py
# class ActionsCollectionResource(resource.BaseResource):
# class ActionsResource(resource.BaseResource):
#     def __init__(self, storage_driver):
#     def on_get(self, req, resp, project_id):
#     def on_post(self, req, resp, project_id):
#     def __init__(self, storage_driver):
#     def on_get(self, req, resp, project_id, action_id):
#     def on_delete(self, req, resp, project_id, action_id):
#     def on_patch(self, req, resp, project_id, action_id):
#     def on_post(self, req, resp, project_id, action_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 freezer_api.api.v2 import actions as v2_actions
from freezer_api.common import exceptions
from freezer_api.tests.unit import common




class TestActionsCollectionResource(common.FreezerBaseTestCase):
    def setUp(self):
        super(TestActionsCollectionResource, 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_action_0['user_id']
        self.mock_req.status = falcon.HTTP_200
        self.resource = v2_actions.ActionsCollectionResource(self.mock_db)
        self.mock_json_body = mock.Mock()
        self.mock_json_body.return_value = {}
        self.resource.json_body = self.mock_json_body

    def test_on_get_return_empty_list(self):
        self.mock_db.search_action.return_value = []
        expected_result = {'actions': []}
        self.resource.on_get(self.mock_req, self.mock_req,
                             common.fake_action_0['project_id'])
        result = self.mock_req.body
        self.assertEqual(expected_result, result)
        self.assertEqual(falcon.HTTP_200, self.mock_req.status)

    def test_on_get_return_correct_list(self):
        self.mock_db.search_action.return_value = [common.get_fake_action_0(),
                                                   common.get_fake_action_1()]
        expected_result = {'actions': [common.get_fake_action_0(),

# Path: freezer_api/api/v2/actions.py
# class ActionsCollectionResource(resource.BaseResource):
# class ActionsResource(resource.BaseResource):
#     def __init__(self, storage_driver):
#     def on_get(self, req, resp, project_id):
#     def on_post(self, req, resp, project_id):
#     def __init__(self, storage_driver):
#     def on_get(self, req, resp, project_id, action_id):
#     def on_delete(self, req, resp, project_id, action_id):
#     def on_patch(self, req, resp, project_id, action_id):
#     def on_post(self, req, resp, project_id, action_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/v2/test_actions.py
import random
import falcon
from unittest import mock
from freezer_api.api.v2 import actions as v2_actions
from freezer_api.common import exceptions
from freezer_api.tests.unit import common





class TestActionsCollectionResource(common.FreezerBaseTestCase):
    def setUp(self):
        super(TestActionsCollectionResource, 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_action_0['user_id']
        self.mock_req.status = falcon.HTTP_200
        self.resource = v2_actions.ActionsCollectionResource(self.mock_db)
        self.mock_json_body = mock.Mock()
        self.mock_json_body.return_value = {}
        self.resource.json_body = self.mock_json_body

    def test_on_get_return_empty_list(self):
        self.mock_db.search_action.return_value = []
        expected_result = {'actions': []}
        self.resource.on_get(self.mock_req, self.mock_req,
                             common.fake_action_0['project_id'])
        result = self.mock_req.body
        self.assertEqual(expected_result, result)
        self.assertEqual(falcon.HTTP_200, self.mock_req.status)

    def test_on_get_return_correct_list(self):
        self.mock_db.search_action.return_value = [common.get_fake_action_0(),
                                                   common.get_fake_action_1()]
        expected_result = {'actions': [common.get_fake_action_0(),

                                       common.get_fake_action_1()]}