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 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
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
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.serialize()))