# Path: pushmanager/servlets/pushitems.py
# class PushItemsServlet(RequestHandler):
# 
#     @tornado.web.asynchronous
#     @tornado.gen.engine
#     def get(self):
#         pushid = pushmanager.core.util.get_int_arg(self.request, 'push', None)
# 
#         response = yield tornado.gen.Task(
#                         self.async_api_call,
#                         "pushitems",
#                         {"push_id": pushid}
#                     )
# 
#         results = self.get_api_results(response)
#         self.render("pushitems.html", requests=results)


import contextlib
import json
import mock
import testify as T
from pushmanager.core.util import get_servlet_urlspec
from pushmanager.servlets.pushitems import PushItemsServlet
from pushmanager.testing.testservlet import ServletTestMixin



class PushsItemsServletTest(T.TestCase, ServletTestMixin):

    def get_handlers(self):
        return [
            get_servlet_urlspec(PushItemsServlet),
        ]

    @T.setup
    def setup_fake_requests_response(self):
        self.fake_request_data = {
            "created": 1346458663.2721,
            "title": "One Push",
            "modified": 1346458663.2721,
            "tags": "fake_tag1,fake_tag2",
            "user": "drseuss",
            "repo": "drseuss",
            "comments": "No comment",
            "branch": "fake_branchname",
            "reviewid": 10,
            "id": 1
        }
        self.fake_requests_response = "[%s]" % json.dumps(self.fake_request_data)

    def test_pushitems(self):
        with contextlib.nested(
            mock.patch.object(PushItemsServlet, "get_current_user", return_value=self.fake_request_data["user"]),

# Path: pushmanager/servlets/pushitems.py
# class PushItemsServlet(RequestHandler):
# 
#     @tornado.web.asynchronous
#     @tornado.gen.engine
#     def get(self):
#         pushid = pushmanager.core.util.get_int_arg(self.request, 'push', None)
# 
#         response = yield tornado.gen.Task(
#                         self.async_api_call,
#                         "pushitems",
#                         {"push_id": pushid}
#                     )
# 
#         results = self.get_api_results(response)
#         self.render("pushitems.html", requests=results)


# Path: pushmanager/tests/test_servlet_pushitems.py
import contextlib
import json
import mock
import testify as T
from pushmanager.core.util import get_servlet_urlspec
from pushmanager.servlets.pushitems import PushItemsServlet
from pushmanager.testing.testservlet import ServletTestMixin




class PushsItemsServletTest(T.TestCase, ServletTestMixin):

    def get_handlers(self):
        return [
            get_servlet_urlspec(PushItemsServlet),
        ]

    @T.setup
    def setup_fake_requests_response(self):
        self.fake_request_data = {
            "created": 1346458663.2721,
            "title": "One Push",
            "modified": 1346458663.2721,
            "tags": "fake_tag1,fake_tag2",
            "user": "drseuss",
            "repo": "drseuss",
            "comments": "No comment",
            "branch": "fake_branchname",
            "reviewid": 10,
            "id": 1
        }
        self.fake_requests_response = "[%s]" % json.dumps(self.fake_request_data)

    def test_pushitems(self):
        with contextlib.nested(
            mock.patch.object(PushItemsServlet, "get_current_user", return_value=self.fake_request_data["user"]),

            mock.patch.object(PushItemsServlet, "async_api_call", side_effect=self.mocked_api_call),