def get_mapped_answers(schema, answer_store, location):
    """
    Maps the answers in an answer store to a dictionary of key, value answers.
    """
    result = {}

    if isinstance(location, RelationshipLocation):
        answer_id = schema.get_relationship_answer_id_for_block(
            location.block_id)
        answer = answer_store.get_answer(answer_id)
        if answer:
            relationship_store = RelationshipStore(answer.value)
            relationship = relationship_store.get_relationship(
                location.list_item_id, location.to_list_item_id)
            if relationship:
                result = {answer.answer_id: relationship.relationship}
    else:
        answer_ids = schema.get_answer_ids_for_block(location.block_id)
        answers = answer_store.get_answers_by_answer_id(
            answer_ids=answer_ids, list_item_id=location.list_item_id)
        result = {
            answer.answer_id: answer.value
            for answer in answers if answer
        }

    return OrderedDict(sorted(result.items()))
Esempio n. 2
0
def test_remove_id_in_single_relationship():
    relationship_store = RelationshipStore(relationships)
    relationship_store.remove_all_relationships_for_list_item_id("789101")
    remaining_relationship = Relationship(**relationships[1])

    assert len(relationship_store) == 1
    assert (relationship_store.get_relationship(
        remaining_relationship.list_item_id,
        remaining_relationship.to_list_item_id) == remaining_relationship)
    assert relationship_store.is_dirty
Esempio n. 3
0
def test_add_relationship():
    relationship = Relationship(**relationships[0])

    relationship_store = RelationshipStore()
    relationship_store.add_or_update(relationship)

    assert (relationship_store.get_relationship(
        relationship.list_item_id,
        relationship.to_list_item_id) == relationship)
    assert len(relationship_store) == 1
    assert relationship_store.is_dirty
Esempio n. 4
0
def test_update_existing_relationship():
    relationship_store = RelationshipStore(relationships)

    relationship = Relationship(**relationships[0])
    relationship.relationship = "test"

    relationship_store.add_or_update(relationship)

    assert len(relationship_store) == 2
    updated_relationship = relationship_store.get_relationship(
        relationship.list_item_id, relationship.to_list_item_id)
    assert updated_relationship.relationship == "test"
    assert relationship_store.is_dirty
Esempio n. 5
0
def test_get_relationship_that_doesnt_exist():
    relationship_store = RelationshipStore(relationships)
    relationship = relationship_store.get_relationship(
        list_item_id="123456", to_list_item_id="yyyyyy")
    assert not relationship
Esempio n. 6
0
def test_get_relationship():
    relationship_store = RelationshipStore(relationships)
    relationship = relationship_store.get_relationship(
        list_item_id="123456", to_list_item_id="789101")
    assert relationship