# 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
#!/usr/bin/env python




class CoreUtilFunctionsTest(T.TestCase):

    def test_pretty_date(self):
        now = datetime.datetime.now()
        five_minutes_ago = now - datetime.timedelta(minutes=5)
        seven_days_ago = now - datetime.timedelta(days=7)
        one_week_ago = now - datetime.timedelta(weeks=1)
        one_year_ago = now - datetime.timedelta(days=370)
        one_year_four_months_ago = now - datetime.timedelta(days=500)
        five_years_ago = now - datetime.timedelta(days=365 * 5)

        T.assert_equal(pretty_date(five_minutes_ago), "5 minutes ago")
        T.assert_equal(pretty_date(one_week_ago), "1 week ago")
        T.assert_equal(pretty_date(seven_days_ago), pretty_date(one_week_ago))
        T.assert_equal(pretty_date(one_year_ago), "1 year ago")
        T.assert_equal(pretty_date(one_year_four_months_ago), "1 year, 4 months ago")
        T.assert_equal(pretty_date(five_years_ago), "5 years ago")

    def test_servlet_urlspec(self):

# 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

#!/usr/bin/env python




class CoreUtilFunctionsTest(T.TestCase):

    def test_pretty_date(self):
        now = datetime.datetime.now()
        five_minutes_ago = now - datetime.timedelta(minutes=5)
        seven_days_ago = now - datetime.timedelta(days=7)
        one_week_ago = now - datetime.timedelta(weeks=1)
        one_year_ago = now - datetime.timedelta(days=370)
        one_year_four_months_ago = now - datetime.timedelta(days=500)
        five_years_ago = now - datetime.timedelta(days=365 * 5)

        T.assert_equal(pretty_date(five_minutes_ago), "5 minutes ago")
        T.assert_equal(pretty_date(one_week_ago), "1 week ago")
        T.assert_equal(pretty_date(seven_days_ago), pretty_date(one_week_ago))
        T.assert_equal(pretty_date(one_year_ago), "1 year ago")
        T.assert_equal(pretty_date(one_year_four_months_ago), "1 year, 4 months ago")
        T.assert_equal(pretty_date(five_years_ago), "5 years ago")

    def test_servlet_urlspec(self):

        T.assert_equal(get_servlet_urlspec(PushesServlet), (r"/pushes", PushesServlet))