コード例 #1
0
ファイル: views_test.py プロジェクト: zermelozf/h
    def test_it_inits_AnnotationJSONPresenter(self, AnnotationJSONPresenter,
                                              links_service, pyramid_request,
                                              storage):
        views.create(pyramid_request)

        AnnotationJSONPresenter.assert_called_once_with(
            storage.create_annotation.return_value, links_service)
コード例 #2
0
ファイル: views_test.py プロジェクト: zermelozf/h
    def test_it_raises_if_create_annotation_raises(self, pyramid_request,
                                                   storage):
        storage.create_annotation.side_effect = ValidationError('asplode')

        with pytest.raises(ValidationError) as exc:
            views.create(pyramid_request)

        assert exc.value.message == 'asplode'
コード例 #3
0
ファイル: views_test.py プロジェクト: nlisgo/h
    def test_it_raises_if_validate_raises(self, pyramid_request, schemas):
        schemas.CreateAnnotationSchema.return_value.validate.side_effect = (
            ValidationError('asplode'))

        with pytest.raises(ValidationError) as exc:
            views.create(pyramid_request)

        assert exc.value.message == 'asplode'
コード例 #4
0
ファイル: views_test.py プロジェクト: zermelozf/h
    def test_it_creates_the_annotation_in_storage(self, pyramid_request,
                                                  storage, schemas):
        schema = schemas.CreateAnnotationSchema.return_value

        views.create(pyramid_request)

        storage.create_annotation.assert_called_once_with(
            pyramid_request, schema.validate.return_value)
コード例 #5
0
ファイル: views_test.py プロジェクト: fangang123/h
    def test_it_raises_if_validate_raises(self, pyramid_request, schemas):
        schemas.CreateAnnotationSchema.return_value.validate.side_effect = (
            ValidationError('asplode'))

        with pytest.raises(ValidationError) as exc:
            views.create(pyramid_request)

        assert exc.value.message == 'asplode'
コード例 #6
0
ファイル: views_test.py プロジェクト: nlisgo/h
    def test_it_raises_if_create_annotation_raises(self,
                                                   pyramid_request,
                                                   storage):
        storage.create_annotation.side_effect = ValidationError('asplode')

        with pytest.raises(ValidationError) as exc:
            views.create(pyramid_request)

        assert exc.value.message == 'asplode'
コード例 #7
0
ファイル: views_test.py プロジェクト: nlisgo/h
 def test_it_raises_if_json_parsing_fails(self, pyramid_request):
     """It raises PayloadError if parsing of the request body fails."""
     # Make accessing the request.json_body property raise ValueError.
     type(pyramid_request).json_body = {}
     with mock.patch.object(type(pyramid_request),
                            'json_body',
                            new_callable=mock.PropertyMock) as json_body:
         json_body.side_effect = ValueError()
         with pytest.raises(views.PayloadError):
             views.create(pyramid_request)
コード例 #8
0
ファイル: views_test.py プロジェクト: nlisgo/h
    def test_it_inits_AnnotationJSONPresenter(self,
                                              AnnotationJSONPresenter,
                                              links_service,
                                              pyramid_request,
                                              storage):
        views.create(pyramid_request)

        AnnotationJSONPresenter.assert_called_once_with(
            storage.create_annotation.return_value,
            links_service)
コード例 #9
0
ファイル: views_test.py プロジェクト: nlisgo/h
    def test_it_creates_the_annotation_in_storage(self,
                                                  pyramid_request,
                                                  storage,
                                                  schemas):
        schema = schemas.CreateAnnotationSchema.return_value

        views.create(pyramid_request)

        storage.create_annotation.assert_called_once_with(
            pyramid_request, schema.validate.return_value)
コード例 #10
0
ファイル: views_test.py プロジェクト: fangang123/h
 def test_it_raises_if_json_parsing_fails(self, pyramid_request):
     """It raises PayloadError if parsing of the request body fails."""
     # Make accessing the request.json_body property raise ValueError.
     type(pyramid_request).json_body = {}
     with mock.patch.object(type(pyramid_request),
                            'json_body',
                            new_callable=mock.PropertyMock) as json_body:
         json_body.side_effect = ValueError()
         with pytest.raises(views.PayloadError):
             views.create(pyramid_request)
コード例 #11
0
    def test_it_publishes_annotation_event(self, AnnotationEvent,
                                           pyramid_request, storage):
        """It publishes an annotation "create" event for the annotation."""
        views.create(pyramid_request)

        annotation = storage.create_annotation.return_value

        AnnotationEvent.assert_called_once_with(pyramid_request, annotation.id,
                                                'create')
        pyramid_request.notify_after_commit.assert_called_once_with(
            AnnotationEvent.return_value)
コード例 #12
0
ファイル: views_test.py プロジェクト: nlisgo/h
    def test_it_publishes_annotation_event(self,
                                           AnnotationEvent,
                                           pyramid_request,
                                           storage):
        """It publishes an annotation "create" event for the annotation."""
        views.create(pyramid_request)

        annotation = storage.create_annotation.return_value

        AnnotationEvent.assert_called_once_with(
            pyramid_request, annotation.id, 'create', annotation_dict=None)
        pyramid_request.notify_after_commit.assert_called_once_with(
            AnnotationEvent.return_value)
コード例 #13
0
ファイル: views_test.py プロジェクト: zermelozf/h
    def test_it_returns_presented_annotation(self, AnnotationJSONPresenter,
                                             pyramid_request):
        result = views.create(pyramid_request)

        AnnotationJSONPresenter.return_value.asdict.assert_called_once_with()
        assert result == (
            AnnotationJSONPresenter.return_value.asdict.return_value)
コード例 #14
0
ファイル: views_test.py プロジェクト: nlisgo/h
    def test_it_returns_presented_annotation(self,
                                             AnnotationJSONPresenter,
                                             pyramid_request):
        result = views.create(pyramid_request)

        AnnotationJSONPresenter.return_value.asdict.assert_called_once_with()
        assert result == (
            AnnotationJSONPresenter.return_value.asdict.return_value)
コード例 #15
0
ファイル: views_test.py プロジェクト: fangang123/h
    def test_it_validates_the_posted_data(self, pyramid_request, schemas):
        """It should call validate() with a request.json_body."""
        views.create(pyramid_request)

        schemas.CreateAnnotationSchema.return_value.validate\
            .assert_called_once_with(pyramid_request.json_body)
コード例 #16
0
ファイル: views_test.py プロジェクト: fangang123/h
    def test_it_inits_CreateAnnotationSchema(self, pyramid_request, schemas):
        views.create(pyramid_request)

        schemas.CreateAnnotationSchema.assert_called_once_with(pyramid_request)
コード例 #17
0
ファイル: views_test.py プロジェクト: nlisgo/h
    def test_it_inits_CreateAnnotationSchema(self, pyramid_request, schemas):
        views.create(pyramid_request)

        schemas.CreateAnnotationSchema.assert_called_once_with(pyramid_request)
コード例 #18
0
ファイル: views_test.py プロジェクト: nlisgo/h
    def test_it_validates_the_posted_data(self, pyramid_request, schemas):
        """It should call validate() with a request.json_body."""
        views.create(pyramid_request)

        schemas.CreateAnnotationSchema.return_value.validate\
            .assert_called_once_with(pyramid_request.json_body)