Esempio n. 1
0
def test_add_relationship_that_already_exists():
    relationship = relationships[0]
    relationship_store = RelationshipStore([relationship])
    relationship_store.add_or_update(Relationship(**relationship))

    assert len(relationship_store) == 1
    assert not relationship_store.is_dirty
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. 3
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. 4
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. 5
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. 6
0
    def _create_relationship_store_and_update_answer(
        self, relationship_answer_id, answer, form_data, list_item_id, to_list_item_id
    ):
        try:
            relationship_store = RelationshipStore(answer.value)
        except AttributeError:
            relationship_store = RelationshipStore()

        relationship_answer = form_data.get(relationship_answer_id)
        relationship = Relationship(list_item_id, to_list_item_id, relationship_answer)
        relationship_store.add_or_update(relationship)
        self._answer_store.add_or_update(
            Answer(relationship_answer_id, relationship_store.serialise())
        )
Esempio n. 7
0
def test_remove_id_in_multiple_relationships():
    relationship_store = RelationshipStore(relationships)
    relationship_store.remove_all_relationships_for_list_item_id("123456")

    assert not relationship_store
    assert relationship_store.is_dirty
Esempio n. 8
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. 9
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
Esempio n. 10
0
def test_clear():  # pylint: disable=redefined-outer-name
    relationship_store = RelationshipStore(relationships)
    relationship_store.clear()

    assert not relationship_store
    assert relationship_store.is_dirty
Esempio n. 11
0
def test_deserialisation():
    relationship_store = RelationshipStore(relationships)

    assert Relationship(**relationships[0]) in relationship_store
    assert len(relationship_store) == 2
Esempio n. 12
0
def test_serialisation():
    relationship_store = RelationshipStore(relationships)

    assert relationship_store.serialise() == relationships