コード例 #1
0
def test_other_json_type_is_parsed():
    json_attribute_name = "other_json"
    key_a = "keyA"
    key_b = "keyB"
    value_a = "valueA"
    value_b = "valueB"
    json_value = {key_a: value_a, key_b: value_b}

    encoded_json = json.dumps(json_value).encode()

    attribute_list = create_single_attribute_list(
        name=json_attribute_name,
        value=encoded_json,
        anchors=None,
        content_type=Protobuf.CT_JSON,
    )

    profile = Profile(attribute_list)

    retrieved_attribute = profile.get_attribute(json_attribute_name)

    assert retrieved_attribute.name == json_attribute_name
    assert type(retrieved_attribute.value) is collections.OrderedDict
    assert retrieved_attribute.value[key_a] == value_a
    assert retrieved_attribute.value[key_b] == value_b
コード例 #2
0
def test_get_attribute_document_images():
    attribute_list = create_single_attribute_list(
        name=config.ATTRIBUTE_DOCUMENT_IMAGES,
        value=[],
        anchors=None,
        content_type=Protobuf.CT_MULTI_VALUE,
    )

    profile = Profile(attribute_list)

    assert (profile.get_attribute(
        config.ATTRIBUTE_DOCUMENT_IMAGES) == profile.document_images)
コード例 #3
0
def test_parse_empty_string_value_returns_attribute(value):
    attribute_name = "attribute_name"

    attribute_list = create_single_attribute_list(
        name=attribute_name,
        value=value,
        anchors=None,
        content_type=Protobuf.CT_STRING)

    profile = Profile(attribute_list)

    assert profile.get_attribute(attribute_name).value == ""
コード例 #4
0
def test_try_parse_int_value(string, expected_int):
    attribute_name = "int_attribute"
    attribute_list = create_single_attribute_list(
        name=attribute_name,
        value=str.encode(string),
        anchors=None,
        content_type=Protobuf.CT_INT,
    )

    profile = Profile(attribute_list)
    int_attribute = profile.get_attribute(attribute_name)
    assert int_attribute.value == expected_int
コード例 #5
0
def test_parse_empty_values_returns_none(content_type):
    attribute_name = "attribute_name"

    attribute_list = create_single_attribute_list(name=attribute_name,
                                                  value=b"",
                                                  anchors=None,
                                                  content_type=content_type)

    # disable logging for the below call: warning logged as value is empty
    logger = logging.getLogger()
    logger.propagate = False

    profile = Profile(attribute_list)

    logger.propagate = True

    assert profile.get_attribute(attribute_name) is None
コード例 #6
0
def test_error_parsing_attribute_has_none_value():
    int_attribute_name = "int_attribute"

    attribute_list = create_single_attribute_list(
        name=int_attribute_name,
        value=str.encode("invalid_int"),
        anchors=None,
        content_type=Protobuf.CT_INT,
    )

    # disable logging for the below call: warning shown as int is invalid
    logger = logging.getLogger()
    logger.propagate = False

    profile = Profile(attribute_list)

    logger.propagate = True

    assert profile.get_attribute(int_attribute_name) is None
コード例 #7
0
def test_nested_multi_value():
    attribute_name = "nested_multi_value"
    inner_multi_value = attribute_fixture_parser.parse_multi_value()

    outer_tuple = (inner_multi_value, )

    profile = Profile(profile_attributes=None)
    profile.attributes[attribute_name] = Attribute(name=attribute_name,
                                                   value=outer_tuple,
                                                   anchors=None)

    retrieved_multi_value = profile.get_attribute(attribute_name)

    assert isinstance(retrieved_multi_value.value, tuple)

    for item in retrieved_multi_value.value:
        assert isinstance(item, tuple)

    image_helper.assert_is_expected_image(retrieved_multi_value.value[0][0],
                                          "jpeg", "vWgD//2Q==")
    image_helper.assert_is_expected_image(retrieved_multi_value.value[0][1],
                                          "jpeg", "38TVEH/9k=")
コード例 #8
0
def test_error_parsing_attribute_does_not_affect_other_attribute():
    string_attribute_name = "string_attribute"
    int_attribute_name = "int_attribute"
    string_value = "string"

    attribute_list = list()

    attribute_list.append(
        ProtobufAttribute(
            name=string_attribute_name,
            value=str.encode(string_value),
            anchors=None,
            content_type=Protobuf.CT_STRING,
        ))

    attribute_list.append(
        ProtobufAttribute(
            name=int_attribute_name,
            value=str.encode("invalid_int"),
            anchors=None,
            content_type=Protobuf.CT_INT,
        ))

    # disable logging for the below call: warning shown as int is invalid
    logger = logging.getLogger()
    logger.propagate = False

    profile = Profile(attribute_list)

    logger.propagate = True

    assert len(profile.attributes) == 1

    retrieved_string_attribute = profile.get_attribute(string_attribute_name)
    assert retrieved_string_attribute.name == string_attribute_name
    assert retrieved_string_attribute.value == string_value
コード例 #9
0
def test_get_attribute_returns_none():
    profile = Profile(None)

    assert profile.get_attribute(config.ATTRIBUTE_SELFIE) is None
コード例 #10
0
def test_get_attribute_email_address():
    profile = Profile(create_attribute_list_with_email_field())

    assert (profile.get_attribute(
        config.ATTRIBUTE_EMAIL_ADDRESS) == profile.email_address)
コード例 #11
0
def test_get_attribute_selfie():
    profile = Profile(create_attribute_list_with_selfie_field())

    assert profile.get_attribute(config.ATTRIBUTE_SELFIE) == profile.selfie