Example #1
0
def test_set_group_if_reply_does_not_modify_non_replies():
    # This annotation is not a reply.
    annotation = _mock_annotation(group='test-group')

    logic.set_group_if_reply(annotation)

    assert annotation['group'] == 'test-group'
Example #2
0
def test_set_group_if_reply_clears_group_if_parent_has_no_group(models):
    annotation = _mock_annotation(
        group='this should be deleted',
        references=['parent_id'])

    # The parent annotation.
    models.Annotation.fetch.return_value = {}  # No 'group' key.

    logic.set_group_if_reply(annotation)

    assert 'group' not in annotation
Example #3
0
def test_set_group_if_reply_adds_group_to_replies(models):
    """If a reply has no group it gets the group of its parent annotation."""
    annotation = _mock_annotation(references=['parent_id'])
    assert 'group' not in annotation

    # The parent annotation.
    models.Annotation.fetch.return_value = {'group': "parent_group"}

    logic.set_group_if_reply(annotation)

    assert annotation['group'] == "parent_group"
Example #4
0
def test_set_group_if_reply_calls_fetch_if_reply(models):
    """If the annotation is a reply it should call Annotation.fetch() once.

    And pass the parent ID.

    """
    annotation = _mock_annotation(references=['parent_id'])

    logic.set_group_if_reply(annotation)

    models.Annotation.fetch.assert_called_once_with('parent_id')
Example #5
0
def test_set_group_if_reply_overwrites_groups_in_replies(models):
    """If a reply has a group it's overwritten with the parent's group."""
    annotation = _mock_annotation(
        group='this should be overwritten',
        references=['parent_id'])

    # The parent annotation.
    models.Annotation.fetch.return_value = {'group': "parent_group"}

    logic.set_group_if_reply(annotation)

    assert annotation['group'] == "parent_group"
Example #6
0
def test_set_group_if_reply_does_nothing_if_parent_not_found(models):
    annotation = _mock_annotation(references=['parent_id'])

    models.Annotation.fetch.return_value = None

    logic.set_group_if_reply(annotation)