コード例 #1
0
ファイル: logic_test.py プロジェクト: apurvajalit/h
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)
コード例 #2
0
ファイル: logic_test.py プロジェクト: ningyifan/h
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]
コード例 #3
0
ファイル: logic_test.py プロジェクト: bitsoffreedom/h
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]
コード例 #4
0
ファイル: logic_test.py プロジェクト: ningyifan/h
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]
コード例 #5
0
ファイル: logic_test.py プロジェクト: apurvajalit/h
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]
コード例 #6
0
ファイル: logic_test.py プロジェクト: ningyifan/h
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
コード例 #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
コード例 #8
0
ファイル: logic_test.py プロジェクト: chrber/h
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]')
コード例 #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]')
コード例 #10
0
ファイル: logic_test.py プロジェクト: apurvajalit/h
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
コード例 #11
0
ファイル: logic_test.py プロジェクト: apurvajalit/h
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
コード例 #12
0
ファイル: logic_test.py プロジェクト: apurvajalit/h
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
コード例 #13
0
ファイル: logic_test.py プロジェクト: ningyifan/h
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
コード例 #14
0
ファイル: logic_test.py プロジェクト: chrber/h
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
コード例 #15
0
ファイル: logic_test.py プロジェクト: apurvajalit/h
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
コード例 #16
0
ファイル: views.py プロジェクト: openbizgit/h
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)
コード例 #17
0
ファイル: views.py プロジェクト: openbizgit/h
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)
コード例 #18
0
ファイル: views.py プロジェクト: ningyifan/h
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)
コード例 #19
0
ファイル: views.py プロジェクト: ningyifan/h
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)
コード例 #20
0
ファイル: views.py プロジェクト: chrber/h
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)
コード例 #21
0
ファイル: views.py プロジェクト: linhua55/h
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)
コード例 #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()
コード例 #23
0
def test_create_annotation_returns_the_annotation(Annotation):
    result = logic.create_annotation({}, userid='acct:[email protected]')
    assert result == Annotation.return_value
コード例 #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]')
コード例 #25
0
ファイル: logic_test.py プロジェクト: apurvajalit/h
def test_create_annotation_calls_Annotation(Annotation):
    fields = mock.MagicMock()
    logic.create_annotation(fields, mock.Mock())

    Annotation.assert_called_once_with(fields)
コード例 #26
0
ファイル: logic_test.py プロジェクト: tilgovi/h
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())
コード例 #27
0
ファイル: logic_test.py プロジェクト: apurvajalit/h
def test_create_annotation_returns_the_annotation(Annotation):
    assert logic.create_annotation({}, mock.Mock()) == Annotation.return_value
コード例 #28
0
ファイル: logic_test.py プロジェクト: openbizgit/h
def test_create_annotation_calls_Annotation(Annotation):
    fields = mock.MagicMock()
    logic.create_annotation(fields)

    Annotation.assert_called_once_with(fields)
コード例 #29
0
ファイル: logic_test.py プロジェクト: apurvajalit/h
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)
コード例 #30
0
ファイル: logic_test.py プロジェクト: openbizgit/h
def test_create_annotation_returns_the_annotation(Annotation):
    result = logic.create_annotation({})
    assert result == Annotation.return_value
コード例 #31
0
ファイル: logic_test.py プロジェクト: ningyifan/h
def test_create_annotation_returns_the_annotation(Annotation):
    assert logic.create_annotation({}, mock.Mock()) == Annotation.return_value
コード例 #32
0
ファイル: logic_test.py プロジェクト: chrber/h
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]')
コード例 #33
0
ファイル: logic_test.py プロジェクト: chrber/h
def test_create_annotation_returns_the_annotation(Annotation):
    result = logic.create_annotation({}, userid='acct:[email protected]')
    assert result == Annotation.return_value
コード例 #34
0
ファイル: logic_test.py プロジェクト: chrber/h
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()
コード例 #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)
コード例 #36
0
ファイル: logic_test.py プロジェクト: apurvajalit/h
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()
コード例 #37
0
ファイル: logic_test.py プロジェクト: chrber/h
def test_create_annotation_calls_Annotation(Annotation):
    fields = mock.MagicMock()
    logic.create_annotation(fields, userid='acct:[email protected]')

    Annotation.assert_called_once_with(fields)
コード例 #38
0
ファイル: logic_test.py プロジェクト: openbizgit/h
def test_create_annotation_calls_save(Annotation):
    """It should call save() once."""
    logic.create_annotation({})

    Annotation.return_value.save.assert_called_once_with()
コード例 #39
0
ファイル: logic_test.py プロジェクト: openbizgit/h
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)
コード例 #40
0
ファイル: logic_test.py プロジェクト: chrber/h
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)
コード例 #41
0
ファイル: logic_test.py プロジェクト: openbizgit/h
def test_create_annotation_returns_the_annotation(Annotation):
    result = logic.create_annotation({})
    assert result == Annotation.return_value
コード例 #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)