示例#1
0
def test_extract_and_callback_response_data(random_string):
    a_response = jgt_common.ResponseInfo(
        response=random_string,
        response_callback=arbitrary_callback,
        response_data_extract=str.swapcase,
    )
    assert a_response.response_data == ARBITRARY_CALLBACK_VALUE.swapcase()
示例#2
0
def test_callback_response_data(random_string):
    a_response = jgt_common.ResponseInfo(response=random_string,
                                         response_callback=arbitrary_callback)
    assert a_response.response_data == ARBITRARY_CALLBACK_VALUE

    # Now make sure .response has been changed:
    assert a_response.response == ARBITRARY_CALLBACK_VALUE
示例#3
0
def test_response_list_run_response_callbacks():
    arbitrary_list_len = random.randint(1, 10)  # Anything > 0 is fine.
    response_list = jgt_common.ResponseList()

    response_list.extend(
        jgt_common.ResponseInfo(response_callback=arbitrary_callback)
        for x in range(arbitrary_list_len))
    arbitrary_callback_counter[0] = 0
    response_list.run_response_callbacks()
    assert arbitrary_callback_counter[0] == arbitrary_list_len
示例#4
0
def test_callback_response_data_callback_only_called_once():
    a_response = jgt_common.ResponseInfo(response_callback=arbitrary_callback)

    arbitrary_callback_counter[0] = 0
    a_response.run_response_callback()

    assert a_response.response == ARBITRARY_CALLBACK_VALUE
    assert arbitrary_callback_counter[0] == 1

    a_response.run_response_callback()
    assert a_response.response == ARBITRARY_CALLBACK_VALUE
    assert arbitrary_callback_counter[0] == 1
示例#5
0
def test_simple_responseinfo_data():
    response = jgt_common.generate_random_string()
    description = jgt_common.generate_random_string()
    extra_field = jgt_common.generate_random_string()
    a_response = jgt_common.ResponseInfo(response=response,
                                         description=description,
                                         extra_field=extra_field)
    assert a_response.response == response
    assert a_response.description == description
    assert a_response.extra_field == extra_field
    # No callbacks, so the response data should just be the response
    assert a_response.response_data == response
示例#6
0
def test_commonattributelist_attr_set(random_string):
    arbitrary_list_len = random.randint(1, 10)  # Anything > 0 is fine.
    my_list = jgt_common.CommonAttributeList()

    # First set up different data for each item
    for x in range(arbitrary_list_len):
        my_list.append(jgt_common.ResponseInfo(data=x))

    # overwrite data with the same value.
    my_list.data = random_string

    # make sure new value is consisten across each element.
    assert my_list.data == [random_string] * arbitrary_list_len
示例#7
0
def test_commonattributelist_update_all(random_string):
    arbitrary_list_len = random.randint(1, 10)  # Anything > 0 is fine.
    my_list = jgt_common.CommonAttributeList()

    # First set up different data for each item
    for x in range(arbitrary_list_len):
        my_list.append(jgt_common.ResponseInfo(data=x))

    my_list.update_all(data=random_string, data2=random_string + random_string)

    # make sure new values are consisten across each element.
    assert my_list.data == [random_string] * arbitrary_list_len
    assert my_list.data2 == [random_string + random_string
                             ] * arbitrary_list_len
示例#8
0
def test_commonattributelist_attr_access():
    arbitrary_list_len = random.randint(1, 10)  # Anything > 0 is fine.
    my_list = jgt_common.CommonAttributeList()
    for x in range(arbitrary_list_len):
        my_list.append(jgt_common.ResponseInfo(data=x))
    assert my_list.data == list(range(arbitrary_list_len))
示例#9
0
def test_extract_response_data():
    arbitrary_string = "arbitrary_string".lower()
    a_response = jgt_common.ResponseInfo(response=arbitrary_string,
                                         response_data_extract=str.swapcase)
    assert a_response.response_data == arbitrary_string.swapcase()