# Path: pushmanager/servlets/pushes.py
# class PushesServlet(RequestHandler):
# 
#     @tornado.web.authenticated
#     @tornado.web.asynchronous
#     @tornado.gen.engine
#     def get(self):
#         pushes_per_page = pushmanager.core.util.get_int_arg(self.request, 'rpp', 50)
#         offset = pushmanager.core.util.get_int_arg(self.request, 'offset', 0)
#         state = pushmanager.core.util.get_str_arg(self.request, 'state', '')
#         push_user = pushmanager.core.util.get_str_arg(self.request, 'user', '')
#         response = yield tornado.gen.Task(
#             self.async_api_call,
#             'pushes',
#             {
#                 'rpp': pushes_per_page,
#                 'offset': offset,
#                 'state': state,
#                 'user': push_user,
#             }
#         )
# 
#         results = self.get_api_results(response)
#         if not results:
#             self.finish()
# 
#         pushes, pushes_count = results
#         self.render(
#             "pushes.html",
#             page_title="Pushes",
#             pushes=pushes,
#             offset=offset,
#             rpp=pushes_per_page,
#             state=state,
#             push_user=push_user,
#             pushes_count=pushes_count,
#         )


import copy
import datetime
import subprocess
import mock
import contextlib
import testify as T
from pushmanager.core.util import add_to_tags_str
from pushmanager.core.util import del_from_tags_str
from pushmanager.core.util import dict_copy_keys
from pushmanager.core.util import EscapedDict
from pushmanager.core.util import get_servlet_urlspec
from pushmanager.core.util import pretty_date
from pushmanager.core.util import tags_contain
from pushmanager.core.util import tags_str_as_set
from pushmanager.core.util import send_people_msg_in_groups
from pushmanager.servlets.pushes import PushesServlet
    def test_send_people_msg_in_groups_split(self):
        people = ['111', '222', '333', '444', '555', '666']
        msg = 'Hello World!'
        irc_nick = 'Goku'
        irc_channel = 'dragon_ball'
        person_per_group = 5
        prefix_msg = '[fake_prefix_msg]'

        with contextlib.nested(
            mock.patch.object(subprocess, 'call', mock.Mock())
        ):
            send_people_msg_in_groups(people, msg, irc_nick, irc_channel, person_per_group, prefix_msg)

            T.assert_equal(subprocess.call.call_count, 2)
            subprocess.call.assert_any_call([
                '/nail/sys/bin/nodebot',
                '-i',
                'Goku',
                'dragon_ball',
                '[fake_prefix_msg] 111, 222, 333, 444, 555'
            ])

            subprocess.call.assert_any_call([
                '/nail/sys/bin/nodebot',
                '-i',
                'Goku',
                'dragon_ball',
                ' 666: Hello World!'
            ])


# Path: pushmanager/servlets/pushes.py
# class PushesServlet(RequestHandler):
# 
#     @tornado.web.authenticated
#     @tornado.web.asynchronous
#     @tornado.gen.engine
#     def get(self):
#         pushes_per_page = pushmanager.core.util.get_int_arg(self.request, 'rpp', 50)
#         offset = pushmanager.core.util.get_int_arg(self.request, 'offset', 0)
#         state = pushmanager.core.util.get_str_arg(self.request, 'state', '')
#         push_user = pushmanager.core.util.get_str_arg(self.request, 'user', '')
#         response = yield tornado.gen.Task(
#             self.async_api_call,
#             'pushes',
#             {
#                 'rpp': pushes_per_page,
#                 'offset': offset,
#                 'state': state,
#                 'user': push_user,
#             }
#         )
# 
#         results = self.get_api_results(response)
#         if not results:
#             self.finish()
# 
#         pushes, pushes_count = results
#         self.render(
#             "pushes.html",
#             page_title="Pushes",
#             pushes=pushes,
#             offset=offset,
#             rpp=pushes_per_page,
#             state=state,
#             push_user=push_user,
#             pushes_count=pushes_count,
#         )


# Path: pushmanager/tests/test_core_util.py
import copy
import datetime
import subprocess
import mock
import contextlib
import testify as T
from pushmanager.core.util import add_to_tags_str
from pushmanager.core.util import del_from_tags_str
from pushmanager.core.util import dict_copy_keys
from pushmanager.core.util import EscapedDict
from pushmanager.core.util import get_servlet_urlspec
from pushmanager.core.util import pretty_date
from pushmanager.core.util import tags_contain
from pushmanager.core.util import tags_str_as_set
from pushmanager.core.util import send_people_msg_in_groups
from pushmanager.servlets.pushes import PushesServlet

    def test_send_people_msg_in_groups_split(self):
        people = ['111', '222', '333', '444', '555', '666']
        msg = 'Hello World!'
        irc_nick = 'Goku'
        irc_channel = 'dragon_ball'
        person_per_group = 5
        prefix_msg = '[fake_prefix_msg]'

        with contextlib.nested(
            mock.patch.object(subprocess, 'call', mock.Mock())
        ):
            send_people_msg_in_groups(people, msg, irc_nick, irc_channel, person_per_group, prefix_msg)

            T.assert_equal(subprocess.call.call_count, 2)
            subprocess.call.assert_any_call([
                '/nail/sys/bin/nodebot',
                '-i',
                'Goku',
                'dragon_ball',
                '[fake_prefix_msg] 111, 222, 333, 444, 555'
            ])

            subprocess.call.assert_any_call([
                '/nail/sys/bin/nodebot',
                '-i',
                'Goku',
                'dragon_ball',
                ' 666: Hello World!'
            ])


    def test_send_people_msg_in_groups_no_split(self):