コード例 #1
0
 def test_print_response_no_data_no_extra(self):
     """Should return no data msg"""
     self.assertEqual(print_response()[0],
                      '\x1b[93mNothing to show.\x1b[0m')
コード例 #2
0
 def test_print_response_no_data(self):
     """Should return no data msg"""
     self.assertIsNone(print_response(extra='a')[0])
コード例 #3
0
 def test_print_response_table(self):
     """Should set is_pager True when data_type table is provided with no pager in kwargs"""
     self.assertEqual(
         print_response(data_type='table', data=[['1', '2']])[0],
         '1   2   ')
コード例 #4
0
 def test_print_response_401(self):
     """Should set color 'FAIL' and data when 401 code is provided"""
     self.assertEqual(
         print_response(code=401)[0], f'\x1b[91m{UNAUTHORIZED_MSG}\x1b[0m')
コード例 #5
0
 def test_print_response_404_400(self):
     """Should set color 'WARNING' when code is 404 / 400"""
     self.assertEqual(
         print_response(code=404, data='a')[0], '\x1b[93ma\x1b[0m')
     self.assertEqual(
         print_response(code=400, data='a')[0], '\x1b[93ma\x1b[0m')
コード例 #6
0
 def test_print_response_503(self):
     """Should set color 'FAIL' and data when 503 code is provided"""
     self.assertEqual(
         print_response(code=503)[0], f'\x1b[91m{SERVER_DOWN_MSG}\x1b[0m')
コード例 #7
0
def main(argv=None):
    if argv is None:
        argv = sys.argv

    try:
        parser = create_parser()
        args = parser.parse_args(argv[1:])

        username = args.login
        is_logout = args.logout
        disconnect_sessions = args.disconnect_sessions

        user = args.user
        team = args.team

        ratings = args.ratings
        country = args.country
        institution = args.institution
        institution_type = args.institution_type

        problem_code = args.problem
        submit = args.submit
        search = args.search

        contest = args.contest
        contests = args.contests
        show_past = args.show_past

        tags = args.tags

        solutions = args.solutions
        solution_code = args.solution
        language = args.language
        result = args.result

        lines = args.lines
        sort = args.sort
        order = args.order
        page = args.page

        resps = []

        if username != INVALID_USERNAME:
            resps = login(username=username,
                          disconnect_sessions=disconnect_sessions)

        elif is_logout:
            resps = logout()

        elif problem_code:
            resps = get_description(problem_code, contest or CC_PRACTICE)

        elif submit:
            resps = submit_problem(*submit)

        elif search:
            resps = search_problems(sort, order, search)

        elif contest:
            resps = get_contest_problems(sort, order, contest)

        elif contests:
            resps = get_contests(show_past)

        elif isinstance(tags, list):
            resps = get_tags(sort, order, tags)

        elif solutions:
            resps = get_solutions(sort, order, solutions, page, language,
                                  result, user)

        elif solution_code:
            resps = get_solution(solution_code)

        elif user:
            resps = get_user(user)

        elif team:
            resps = get_team(team)

        elif ratings:
            resps = get_ratings(sort, order, country, institution,
                                institution_type, page, lines)

        else:
            parser.print_help()

        if not resps:
            resps = [GENERIC_RESP]

        for resp in resps:
            print_response(**resp)
        return resps
    except KeyboardInterrupt:
        print('\nBye.')
        return [{"data": "\nBye."}]
    return [{"data": "0"}]