Exemple #1
0
def test_create_annotation_calls_nipsa(nipsa):
    """It should call has_nipsa() once with the user's id."""
    user = mock.Mock()

    logic.create_annotation({}, user)

    nipsa.has_nipsa.assert_called_once_with(user.id)
Exemple #2
0
def test_create_annotation_pops_protected_fields(Annotation):
    """It should remove any protected fields before calling Annotation."""
    logic.create_annotation(
        fields={"foo": "bar", "created": "foo", "updated": "foo", "user": "******", "consumer": "foo", "id": "foo"},
        user=mock.Mock(),
    )

    for field in ("created", "updated", "user", "consumer", "id"):
        assert field not in Annotation.call_args[0][0]
Exemple #3
0
def test_create_annotation_pops_protected_fields(Annotation):
    """It should remove any protected fields before calling Annotation."""
    logic.create_annotation(
        fields={
            'foo': 'bar',
            'created': 'foo',
            'updated': 'foo',
            'user': '******',
            'id': 'foo'
        },
        userid='acct:[email protected]')

    for field in ('created', 'updated', 'user', 'id'):
        assert field not in Annotation.call_args[0][0]
Exemple #4
0
def test_create_annotation_pops_protected_fields(Annotation):
    """It should remove any protected fields before calling Annotation."""
    logic.create_annotation(
        fields={
            'foo': 'bar',
            'created': 'foo',
            'updated': 'foo',
            'user': '******',
            'consumer': 'foo',
            'id': 'foo'
        },
        user=mock.Mock())

    for field in ('created', 'updated', 'user', 'consumer', 'id'):
        assert field not in Annotation.call_args[0][0]
Exemple #5
0
def test_create_annotation_pops_protected_fields(Annotation):
    """It should remove any protected fields before calling Annotation."""
    logic.create_annotation(
        fields={
            'foo': 'bar',
            'created': 'foo',
            'updated': 'foo',
            'user': '******',
            'consumer': 'foo',
            'id': 'foo'
        },
        user=mock.Mock())

    for field in ('created', 'updated', 'user', 'consumer', 'id'):
        assert field not in Annotation.call_args[0][0]
Exemple #6
0
def test_create_annotation_sets_consumer(Annotation):
    """It should set the annotation's 'consumer' field to the consumer key."""
    user = mock.Mock()
    Annotation.return_value = _mock_annotation()

    annotation = logic.create_annotation({}, user)

    assert annotation['consumer'] == user.consumer.key
Exemple #7
0
def test_create_annotation_sets_user(Annotation):
    """It should set the annotation's 'user' field to the userid."""
    userid = 'acct:[email protected]'
    Annotation.return_value = _mock_annotation()

    annotation = logic.create_annotation({}, userid)

    assert annotation['user'] == userid
Exemple #8
0
def test_create_annotation_does_not_crash_if_annotations_parent_has_no_group(
        Annotation):
    """It shouldn't crash if the parent annotation has no group.

    It shouldn't crash if the annotation is a reply and its parent annotation
    has no 'group' field.

    """
    # No group in the original annotation/reply itself.
    Annotation.return_value = _mock_annotation()
    assert 'group' not in Annotation.return_value
    fields = {}  # No group here either.

    # And no group in the parent annotation either.
    Annotation.fetch.return_value = {}

    logic.create_annotation(fields, userid='acct:[email protected]')
Exemple #9
0
def test_create_annotation_does_not_crash_if_annotations_parent_has_no_group(
        Annotation):
    """It shouldn't crash if the parent annotation has no group.

    It shouldn't crash if the annotation is a reply and its parent annotation
    has no 'group' field.

    """
    # No group in the original annotation/reply itself.
    Annotation.return_value = _mock_annotation()
    assert 'group' not in Annotation.return_value
    fields = {}  # No group here either.

    # And no group in the parent annotation either.
    Annotation.fetch.return_value = {}

    logic.create_annotation(fields, userid='acct:[email protected]')
Exemple #10
0
def test_create_annotation_sets_user(Annotation):
    """It should set the annotation's 'user' field to the user's id."""
    user = mock.Mock()
    Annotation.return_value = _mock_annotation()

    annotation = logic.create_annotation({}, user)

    assert annotation['user'] == user.id
Exemple #11
0
def test_create_annotation_sets_consumer(Annotation):
    """It should set the annotation's 'consumer' field to the consumer key."""
    user = mock.Mock()
    Annotation.return_value = _mock_annotation()

    annotation = logic.create_annotation({}, user)

    assert annotation['consumer'] == user.consumer.key
Exemple #12
0
def test_create_annotation_sets_nipsa_if_user_is_nipsad(Annotation, nipsa):
    Annotation.return_value = _mock_annotation()
    # The user is nipsa'd.
    nipsa.has_nipsa.return_value = True

    annotation = logic.create_annotation({}, mock.Mock())

    assert annotation['nipsa'] is True
Exemple #13
0
def test_create_annotation_sets_user(Annotation):
    """It should set the annotation's 'user' field to the user's id."""
    user = mock.Mock()
    Annotation.return_value = _mock_annotation()

    annotation = logic.create_annotation({}, user)

    assert annotation['user'] == user.id
Exemple #14
0
def test_create_annotation_sets_user(Annotation):
    """It should set the annotation's 'user' field to the userid."""
    userid = 'acct:[email protected]'
    Annotation.return_value = _mock_annotation()

    annotation = logic.create_annotation({}, userid)

    assert annotation['user'] == userid
Exemple #15
0
def test_create_annotation_does_not_set_nipsa_if_user_is_not_nipsad(
        Annotation, nipsa):
    Annotation.return_value = _mock_annotation()
    # The user is not nipsa'd.
    nipsa.has_nipsa.return_value = False

    annotation = logic.create_annotation({}, mock.Mock())

    assert 'nipsa' not in annotation
Exemple #16
0
def create(request):
    """Read the POSTed JSON-encoded annotation and persist it."""
    schema = schemas.CreateAnnotationSchema(request)
    appstruct = schema.validate(_json_payload(request))

    annotation = logic.create_annotation(appstruct)

    # Notify any subscribers
    _publish_annotation_event(request, annotation, 'create')

    # Return it so the client gets to know its ID and such
    return search_lib.render(annotation)
Exemple #17
0
def create(request):
    """Read the POSTed JSON-encoded annotation and persist it."""
    schema = schemas.CreateAnnotationSchema(request)
    appstruct = schema.validate(_json_payload(request))

    annotation = logic.create_annotation(appstruct)

    # Notify any subscribers
    _publish_annotation_event(request, annotation, 'create')

    # Return it so the client gets to know its ID and such
    return search_lib.render(annotation)
Exemple #18
0
def create(request):
    """Read the POSTed JSON-encoded annotation and persist it."""
    # Read the annotation from the request payload
    try:
        fields = request.json_body
    except ValueError:
        return _api_error(request,
                          'No JSON payload sent. Annotation not created.',
                          status_code=400)  # Client Error: Bad Request

    user = get_user(request)

    # Create the annotation
    annotation = logic.create_annotation(fields, user)

    # Notify any subscribers
    _publish_annotation_event(request, annotation, 'create')

    # Return it so the client gets to know its ID and such
    return search_lib.render(annotation)
Exemple #19
0
def create(request):
    """Read the POSTed JSON-encoded annotation and persist it."""
    # Read the annotation from the request payload
    try:
        fields = request.json_body
    except ValueError:
        return _api_error(request,
                          'No JSON payload sent. Annotation not created.',
                          status_code=400)  # Client Error: Bad Request

    user = get_user(request)

    # Create the annotation
    annotation = logic.create_annotation(fields, user)

    # Notify any subscribers
    _publish_annotation_event(request, annotation, 'create')

    # Return it so the client gets to know its ID and such
    return search_lib.render(annotation)
Exemple #20
0
def create(request):
    """Read the POSTed JSON-encoded annotation and persist it."""
    # Read the annotation from the request payload
    try:
        fields = request.json_body
    except ValueError:
        return _api_error(
            request, "No JSON payload sent. Annotation not created.", status_code=400
        )  # Client Error: Bad Request

    try:
        appstruct = schemas.AnnotationSchema().validate(fields)
    except schemas.ValidationError as err:
        return _api_error(request, err.message, status_code=400)

    annotation = logic.create_annotation(appstruct, userid=request.authenticated_userid)

    # Notify any subscribers
    _publish_annotation_event(request, annotation, "create")

    # Return it so the client gets to know its ID and such
    return search_lib.render(annotation)
Exemple #21
0
def create(request):
    """Read the POSTed JSON-encoded annotation and persist it."""
    # Read the annotation from the request payload
    try:
        fields = request.json_body
    except ValueError:
        return _api_error(request,
                          'No JSON payload sent. Annotation not created.',
                          status_code=400)  # Client Error: Bad Request

    try:
        appstruct = schemas.AnnotationSchema().validate(fields)
    except schemas.ValidationError as err:
        return _api_error(request, err.message, status_code=400)

    annotation = logic.create_annotation(appstruct,
                                         userid=request.authenticated_userid)

    # Notify any subscribers
    _publish_annotation_event(request, annotation, 'create')

    # Return it so the client gets to know its ID and such
    return search_lib.render(annotation)
Exemple #22
0
def test_create_annotation_calls_save(Annotation):
    """It should call save() once."""
    logic.create_annotation({}, userid='acct:[email protected]')

    Annotation.return_value.save.assert_called_once_with()
Exemple #23
0
def test_create_annotation_returns_the_annotation(Annotation):
    result = logic.create_annotation({}, userid='acct:[email protected]')
    assert result == Annotation.return_value
Exemple #24
0
def test_create_annotation_does_not_crash_if_annotation_has_no_group(
        Annotation):
    assert 'group' not in Annotation.return_value
    fields = {}  # No group here either.

    logic.create_annotation(fields, userid='acct:[email protected]')
Exemple #25
0
def test_create_annotation_calls_Annotation(Annotation):
    fields = mock.MagicMock()
    logic.create_annotation(fields, mock.Mock())

    Annotation.assert_called_once_with(fields)
Exemple #26
0
def test_create_annotation_does_not_crash_if_annotation_has_no_group(
        Annotation):
    assert 'group' not in Annotation.return_value
    fields = {}  # No group here either.

    logic.create_annotation(fields, mock.Mock())
Exemple #27
0
def test_create_annotation_returns_the_annotation(Annotation):
    assert logic.create_annotation({}, mock.Mock()) == Annotation.return_value
Exemple #28
0
def test_create_annotation_calls_Annotation(Annotation):
    fields = mock.MagicMock()
    logic.create_annotation(fields)

    Annotation.assert_called_once_with(fields)
Exemple #29
0
def test_create_annotation_calls_prepare(Annotation, search_lib):
    """It should call prepare() once with the annotation."""
    logic.create_annotation({}, mock.Mock())

    search_lib.prepare.assert_called_once_with(Annotation.return_value)
Exemple #30
0
def test_create_annotation_returns_the_annotation(Annotation):
    result = logic.create_annotation({})
    assert result == Annotation.return_value
Exemple #31
0
def test_create_annotation_returns_the_annotation(Annotation):
    assert logic.create_annotation({}, mock.Mock()) == Annotation.return_value
Exemple #32
0
def test_create_annotation_does_not_crash_if_annotation_has_no_group(
        Annotation):
    assert 'group' not in Annotation.return_value
    fields = {}  # No group here either.

    logic.create_annotation(fields, userid='acct:[email protected]')
Exemple #33
0
def test_create_annotation_returns_the_annotation(Annotation):
    result = logic.create_annotation({}, userid='acct:[email protected]')
    assert result == Annotation.return_value
Exemple #34
0
def test_create_annotation_calls_save(Annotation):
    """It should call save() once."""
    logic.create_annotation({}, userid='acct:[email protected]')

    Annotation.return_value.save.assert_called_once_with()
Exemple #35
0
def test_create_annotation_calls_prepare(Annotation, search_lib):
    """It should call prepare() once with the annotation."""
    logic.create_annotation({}, userid='acct:[email protected]')

    search_lib.prepare.assert_called_once_with(Annotation.return_value)
Exemple #36
0
def test_create_annotation_calls_save(Annotation):
    """It should call save() once."""
    logic.create_annotation({}, mock.Mock())

    Annotation.return_value.save.assert_called_once_with()
Exemple #37
0
def test_create_annotation_calls_Annotation(Annotation):
    fields = mock.MagicMock()
    logic.create_annotation(fields, userid='acct:[email protected]')

    Annotation.assert_called_once_with(fields)
Exemple #38
0
def test_create_annotation_calls_save(Annotation):
    """It should call save() once."""
    logic.create_annotation({})

    Annotation.return_value.save.assert_called_once_with()
Exemple #39
0
def test_create_annotation_calls_prepare(Annotation, search_lib):
    """It should call prepare() once with the annotation."""
    logic.create_annotation({})

    search_lib.prepare.assert_called_once_with(Annotation.return_value)
Exemple #40
0
def test_create_annotation_calls_prepare(Annotation, search_lib):
    """It should call prepare() once with the annotation."""
    logic.create_annotation({}, userid='acct:[email protected]')

    search_lib.prepare.assert_called_once_with(Annotation.return_value)
Exemple #41
0
def test_create_annotation_returns_the_annotation(Annotation):
    result = logic.create_annotation({})
    assert result == Annotation.return_value
Exemple #42
0
def test_create_annotation_calls_Annotation(Annotation):
    fields = mock.MagicMock()
    logic.create_annotation(fields, userid='acct:[email protected]')

    Annotation.assert_called_once_with(fields)