# Path: pushmanager/servlets/push.py
# class PushServlet(RequestHandler):
# 
#     @tornado.web.asynchronous
#     @tornado.web.authenticated
#     @tornado.gen.engine
#     def get(self):
#         pushid = pushmanager.core.util.get_int_arg(self.request, 'id')
#         override = pushmanager.core.util.get_int_arg(self.request, 'override')
#         response = yield tornado.gen.Task(
#                         self.async_api_call,
#                         "pushdata",
#                         {"id": pushid}
#                     )
# 
#         push_info, push_requests, available_requests = self.get_api_results(response)
# 
#         if not push_info['stageenv']:
#             push_info['stageenv'] = '(to be determined)'
# 
#         push_survey_url = Settings.get('push_survey_url', None)
# 
#         self.render(
#             "push.html",
#             page_title=push_info['title'],
#             pushid=pushid,
#             push_info=push_info,
#             push_contents=push_requests,
#             push_survey_url=push_survey_url,
#             available_requests=available_requests,
#             fullrepo=_repo,
#             override=override,
#             pickme_orders=['urgent', 'no-verify', Settings['tests_tag']['tag']]
#         )


import contextlib
import json
import lxml.html
import mock
import testify as T
from pushmanager.core import util
from pushmanager.core.settings import Settings
from pushmanager.servlets.push import PushServlet
from pushmanager.testing.testdb import FakeDataMixin
from pushmanager.testing.testservlet import ServletTestMixin
            util.get_servlet_urlspec(PushServlet),
        ]

    def find_buildbot_link(self, response, buildbot_link):
        assert response.error is None
        root = lxml.html.fromstring(response.body)
        for elt in root.xpath("//li[@class='tag-buildbot']/a"):
            if elt.attrib['href'] == buildbot_link:
                return True
        return False

    @contextlib.contextmanager
    def request_fake_pushdata(self):
        first_push = self.make_push_dict(self.push_data[0])
        first_request = self.make_request_dict(self.request_data[0])
        first_request['tags'] = "buildbot"
        second_request = self.make_request_dict(self.request_data[1])

        # Prepare pushdata the way PushServlet accepts. This is the
        # format API also replies to pushdata requests.
        pushinfo = util.push_to_jsonable(first_push)
        requests = {
            first_request['state']: [util.request_to_jsonable(first_request)],
            'all': [util.request_to_jsonable(first_request)]
        }
        available_requests = [util.request_to_jsonable(second_request)]

        pushdata = [pushinfo, requests, available_requests]

        with contextlib.nested(

# Path: pushmanager/servlets/push.py
# class PushServlet(RequestHandler):
# 
#     @tornado.web.asynchronous
#     @tornado.web.authenticated
#     @tornado.gen.engine
#     def get(self):
#         pushid = pushmanager.core.util.get_int_arg(self.request, 'id')
#         override = pushmanager.core.util.get_int_arg(self.request, 'override')
#         response = yield tornado.gen.Task(
#                         self.async_api_call,
#                         "pushdata",
#                         {"id": pushid}
#                     )
# 
#         push_info, push_requests, available_requests = self.get_api_results(response)
# 
#         if not push_info['stageenv']:
#             push_info['stageenv'] = '(to be determined)'
# 
#         push_survey_url = Settings.get('push_survey_url', None)
# 
#         self.render(
#             "push.html",
#             page_title=push_info['title'],
#             pushid=pushid,
#             push_info=push_info,
#             push_contents=push_requests,
#             push_survey_url=push_survey_url,
#             available_requests=available_requests,
#             fullrepo=_repo,
#             override=override,
#             pickme_orders=['urgent', 'no-verify', Settings['tests_tag']['tag']]
#         )


# Path: pushmanager/tests/test_servlet_push.py
import contextlib
import json
import lxml.html
import mock
import testify as T
from pushmanager.core import util
from pushmanager.core.settings import Settings
from pushmanager.servlets.push import PushServlet
from pushmanager.testing.testdb import FakeDataMixin
from pushmanager.testing.testservlet import ServletTestMixin

            util.get_servlet_urlspec(PushServlet),
        ]

    def find_buildbot_link(self, response, buildbot_link):
        assert response.error is None
        root = lxml.html.fromstring(response.body)
        for elt in root.xpath("//li[@class='tag-buildbot']/a"):
            if elt.attrib['href'] == buildbot_link:
                return True
        return False

    @contextlib.contextmanager
    def request_fake_pushdata(self):
        first_push = self.make_push_dict(self.push_data[0])
        first_request = self.make_request_dict(self.request_data[0])
        first_request['tags'] = "buildbot"
        second_request = self.make_request_dict(self.request_data[1])

        # Prepare pushdata the way PushServlet accepts. This is the
        # format API also replies to pushdata requests.
        pushinfo = util.push_to_jsonable(first_push)
        requests = {
            first_request['state']: [util.request_to_jsonable(first_request)],
            'all': [util.request_to_jsonable(first_request)]
        }
        available_requests = [util.request_to_jsonable(second_request)]

        pushdata = [pushinfo, requests, available_requests]

        with contextlib.nested(

            mock.patch.object(PushServlet, "get_current_user", return_value="testuser"),