Exemple #1
0
def SubmitInternal(submission_tuple, check_html):

    post_data = {}

    if isinstance(submission_tuple, (list, tuple)):
        PageClass = submission_tuple[0]
        if len(submission_tuple) == 2:
            post_data = submission_tuple[1]
    else:
        PageClass = submission_tuple

    post_data = post_data or {}

    # TODO: validate that user isn't trying to submit a WaitPage,
    # or other possible mistakes

    for key in post_data:
        if isinstance(post_data[key], Currency):
            # because must be json serializable for Huey
            post_data[key] = str(decimal.Decimal(post_data[key]))

    return {
        'page_class': PageClass,
        'page_class_dotted': get_dotted_name(PageClass),
        'post_data': post_data,
        'check_html': check_html
    }
Exemple #2
0
def SubmitInternal(submission_tuple, check_html=BOTS_CHECK_HTML):

    if check_html == BOTS_CHECK_HTML:
        check_html = settings.BOTS_CHECK_HTML

    post_data = {}

    if isinstance(submission_tuple, (list, tuple)):
        PageClass = submission_tuple[0]
        if len(submission_tuple) == 2:
            post_data = submission_tuple[1]
    else:
        PageClass = submission_tuple

    post_data = post_data or {}

    # easy way to check if it's a wait page, without any messy imports
    if hasattr(PageClass, 'wait_for_all_groups'):
        raise AssertionError(
            "Your bot yielded '{}', which is a wait page. "
            "You should delete this line, because bots handle wait pages "
            "automatically."
        )

    for key in post_data:
        if isinstance(post_data[key], Currency):
            # because must be json serializable for Huey
            post_data[key] = str(decimal.Decimal(post_data[key]))

    return {
        'page_class': PageClass,
        'page_class_dotted': get_dotted_name(PageClass),
        'post_data': post_data,
        'check_html': check_html
    }
Exemple #3
0
def _Submission(PageClass,
                post_data=None,
                *,
                check_html=BOTS_CHECK_HTML,
                must_fail=False,
                error_fields=None,
                timeout_happened=False):

    post_data = post_data or {}

    # don't mutate the input
    post_data = post_data.copy()

    if check_html == BOTS_CHECK_HTML:
        check_html = settings.BOTS_CHECK_HTML

    if must_fail:
        # must_fail needs to go in post_data rather than being a separate
        # dict key, because CLI bots and browser bots need to work the same way.
        # CLI bots can only talk to server through post data
        post_data['must_fail'] = True

    if error_fields:
        post_data['error_fields'] = error_fields

    if timeout_happened:
        post_data[constants_internal.timeout_happened] = True
        post_data[constants_internal.admin_secret_code] = ADMIN_SECRET_CODE

    # easy way to check if it's a wait page, without any messy imports
    if hasattr(PageClass, 'wait_for_all_groups'):
        raise AssertionError(
            "Your bot yielded '{}', which is a wait page. "
            "You should delete this line, because bots handle wait pages "
            "automatically.".format(PageClass))

    for key in post_data:
        if isinstance(post_data[key], Currency):
            # because must be json serializable for Huey
            post_data[key] = str(decimal.Decimal(post_data[key]))

    return {
        'page_class': PageClass,
        'page_class_dotted': get_dotted_name(PageClass),
        'post_data': post_data,
        'check_html': check_html,
    }
Exemple #4
0
def _Submission(
        PageClass, post_data=None, *, check_html=BOTS_CHECK_HTML,
        must_fail=False, error_fields=None, timeout_happened=False):

    post_data = post_data or {}

    # don't mutate the input
    post_data = post_data.copy()

    if check_html == BOTS_CHECK_HTML:
        check_html = settings.BOTS_CHECK_HTML

    if must_fail:
        # must_fail needs to go in post_data rather than being a separate
        # dict key, because CLI bots and browser bots need to work the same way.
        # CLI bots can only talk to server through post data
        post_data['must_fail'] = True

    if error_fields:
        post_data['error_fields'] = error_fields

    if timeout_happened:
        post_data[constants_internal.timeout_happened] = True
        post_data[constants_internal.admin_secret_code] = ADMIN_SECRET_CODE

    # easy way to check if it's a wait page, without any messy imports
    if hasattr(PageClass, 'wait_for_all_groups'):
        raise AssertionError(
            "Your bot yielded '{}', which is a wait page. "
            "You should delete this line, because bots handle wait pages "
            "automatically.".format(PageClass)
        )

    for key in post_data:
        if isinstance(post_data[key], Currency):
            # because must be json serializable for Huey
            post_data[key] = str(decimal.Decimal(post_data[key]))

    return {
        'page_class': PageClass,
        'page_class_dotted': get_dotted_name(PageClass),
        'post_data': post_data,
        'check_html': check_html,
    }
Exemple #5
0
 def url_name(cls):
     '''using dots seems not to work'''
     return get_dotted_name(cls).replace('.', '-')
Exemple #6
0
 def url_name(cls):
     '''using dots seems not to work'''
     return get_dotted_name(cls).replace('.', '-')