def check_page_status(unittest, user_role, url_roles):
    """
    Check if each URL set in 'url_roles' match its status_code with the
    response code status depending on the user role. Each URL can be added to
    the 'url_roles' dictionary using a predefined structure of data.

    unittest - It's a instance of a class that inherits
        txcommon.tests.base.BaseTestCase.
    user_role - One of the user roles allowed on
        txcommon.tests.base.BaseTestCase.
    url_roles - A structured dictionary containing the url to be tested.

    Structure of 'url_roles':
        url_roles = {'<REQUEST_METHOD>:<URL>':{
            '<USER_ROLE>':(<STATUS_CODE>, <DICT_OF_ARGS>,
                <EXPECTED_CONTENTS>, <UNEXPECTED_CONTENTS>, <FOLLOW_REDIRECT>),
            (...)
            },
        }

        <REQUEST_METHOD> - Might be 'GET' or 'POST'.
        <URL> - The url that must be tested.
        <USER_ROLE> - One of the user roles allowed on
            txcommon.tests.base.BaseTestCase. At least one user
            role is required.
        <STATUS_CODE> - Code of status for the HTTP response.
        <DICT_OF_ARGS> - Arguments that might be passed to the HTTP request.
            Not required.
        <EXPECTED_CONTENTS> - A string that might be found using
            assertContains on the response contents. Not required.
        <UNEXPECTED_CONTENTS> - A string that shouldn't be found. Not required.
        <FOLLOW_REDIRECT> - If it's a redirect, follow it

    Know issues:
        <EXPECTED_CONTENTS> usually does not work with the status code 302.
    """
    if not user_role in USER_ROLES:
        unittest.fail("Unknown user role: '%s'" % user_role)

    for url, date_dict in url_roles.items():
        try:
            expected_code = date_dict[user_role][0]
            args = getitem(date_dict[user_role], 1, {})
            expected_contents = getitem(date_dict[user_role], 2, None)
            unexpected_contents = getitem(date_dict[user_role], 3, None)
            follow_redirect = getitem(date_dict[user_role], 4, False)

            client = unittest.client[user_role]

            method, url = tuple(url.split(':'))
            if method == 'GET':
                response = client.get(url, args, follow=follow_redirect)
            elif method == 'POST':
                response = client.post(url, args, follow=follow_redirect)
            else:
                unittest.fail("Unknown method request: '%s'" % role)

            assert_status_code(unittest, response, expected_code, url,
                user_role)

            if expected_contents:
                unittest.assertContains(response, expected_contents,
                    status_code=expected_code)
            if unexpected_contents:
                unittest.assertNotContains(response, unexpected_contents,
                    status_code=expected_code)
        except KeyError:
            logger.info("User role '%s' not defined for the '%s' URL." % (
                user_role, url))
dataset/ETHPy150Open rvanlaar/easy-transifex/src/transifex/transifex/txcommon/tests/utils.py/check_page_status/original