Ejemplo n.º 1
0
    def test_it_returns_new_group_formatted_with_presenter(
            self, pyramid_request, GroupContext, GroupJSONPresenter):
        views.create(pyramid_request)

        GroupJSONPresenter.assert_called_once_with(GroupContext.return_value)
        GroupJSONPresenter.return_value.asdict.assert_called_once_with(
            expand=['organization'])
Ejemplo n.º 2
0
    def test_it_raises_validation_error_if_missing_request_user(
            self, pyramid_request):
        pyramid_request.user = None

        with pytest.raises(ValidationError,
                           match="must have an authenticated user"):
            views.create(pyramid_request)
Ejemplo n.º 3
0
    def test_it_returns_new_group_formatted_with_presenter(self,
                                                           pyramid_request,
                                                           GroupContext,
                                                           GroupJSONPresenter):
        views.create(pyramid_request)

        GroupJSONPresenter.assert_called_once_with(GroupContext.return_value)
        GroupJSONPresenter.return_value.asdict.assert_called_once_with(expand=['organization'])
Ejemplo n.º 4
0
    def test_it_creates_group_context_from_created_group(
            self, pyramid_request, GroupContext, group_create_service):
        my_group = mock.Mock()
        group_create_service.create_private_group.return_value = my_group

        views.create(pyramid_request)

        GroupContext.assert_called_with(my_group, pyramid_request)
Ejemplo n.º 5
0
    def test_it_creates_group_context_from_created_group(
        self, pyramid_request, GroupContext, group_create_service
    ):
        my_group = mock.Mock()
        group_create_service.create_private_group.return_value = my_group

        views.create(pyramid_request)

        GroupContext.assert_called_with(my_group, pyramid_request)
Ejemplo n.º 6
0
    def test_it_sets_description_to_none_if_not_present(
        self, pyramid_request, CreateGroupAPISchema, group_create_service
    ):
        CreateGroupAPISchema.return_value.validate.return_value = {"name": "My Group"}
        views.create(pyramid_request)

        group_create_service.create_private_group.assert_called_once_with(
            "My Group", pyramid_request.user.userid, description=None, groupid=None
        )
Ejemplo n.º 7
0
    def test_it_sets_description_to_none_if_not_present(
        self, pyramid_request, CreateGroupAPISchema, group_create_service
    ):
        CreateGroupAPISchema.return_value.validate.return_value = {"name": "My Group"}
        views.create(pyramid_request)

        group_create_service.create_private_group.assert_called_once_with(
            "My Group", pyramid_request.user.userid, description=None, groupid=None
        )
Ejemplo n.º 8
0
    def test_it_raises_HTTPConflict_on_duplicate(self, pyramid_request,
                                                 group_service, factories):
        # Return a different pre-existing group when we search by id
        group_service.fetch.return_value = factories.Group(
            authority_provided_id="different_id", authority="example.com")

        with pytest.raises(HTTPConflict,
                           match="group with groupid.*already exists"):
            views.create(pyramid_request)
Ejemplo n.º 9
0
 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)
Ejemplo n.º 10
0
 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)
Ejemplo n.º 11
0
    def test_it_raises_HTTPConflict_on_duplicate(
        self, pyramid_request, CreateGroupAPISchema, group_service, factories
    ):

        group = factories.Group(
            authority_provided_id="something", authority="example.com"
        )
        group_service.fetch.return_value = group

        with pytest.raises(HTTPConflict, match="group with groupid.*already exists"):
            views.create(pyramid_request)
Ejemplo n.º 12
0
    def test_it_raises_HTTPConflict_on_duplicate(
        self, pyramid_request, CreateGroupAPISchema, group_service, factories
    ):

        group = factories.Group(
            authority_provided_id="something", authority="example.com"
        )
        group_service.fetch.return_value = group

        with pytest.raises(HTTPConflict, match="group with groupid.*already exists"):
            views.create(pyramid_request)
Ejemplo n.º 13
0
    def test_it_passes_request_params_to_group_create_service(
            self, pyramid_request, CreateGroupAPISchema, group_service):
        CreateGroupAPISchema.return_value.validate.return_value = {
            'name': 'My Group',
            'description': 'How about that?',
        }
        views.create(pyramid_request)

        group_service.create_private_group.assert_called_once_with(
            'My Group',
            pyramid_request.user.userid,
            description='How about that?')
Ejemplo n.º 14
0
    def test_it_passes_request_params_to_group_create_service(self,
                                                              pyramid_request,
                                                              CreateGroupAPISchema,
                                                              group_service):
        CreateGroupAPISchema.return_value.validate.return_value = {
          'name': 'My Group',
          'description': 'How about that?',
         }
        views.create(pyramid_request)

        group_service.create_private_group.assert_called_once_with('My Group',
                                                                   pyramid_request.user.userid,
                                                                   description='How about that?')
Ejemplo n.º 15
0
    def test_it_passes_request_params_to_group_create_service(
            self, pyramid_request, CreateGroupAPISchema, group_create_service):
        CreateGroupAPISchema.return_value.validate.return_value = {
            "name": "My Group",
            "description": "How about that?",
        }
        views.create(pyramid_request)

        group_create_service.create_private_group.assert_called_once_with(
            "My Group",
            pyramid_request.user.userid,
            description="How about that?",
            groupid=None,
        )
Ejemplo n.º 16
0
    def test_it_passes_request_params_to_group_create_service(
        self, pyramid_request, CreateGroupAPISchema, group_create_service
    ):
        CreateGroupAPISchema.return_value.validate.return_value = {
            "name": "My Group",
            "description": "How about that?",
        }
        views.create(pyramid_request)

        group_create_service.create_private_group.assert_called_once_with(
            "My Group",
            pyramid_request.user.userid,
            description="How about that?",
            groupid=None,
        )
Ejemplo n.º 17
0
    def test_it_passes_groupid_to_group_create_as_authority_provided_id(
            self, pyramid_request, CreateGroupAPISchema, group_create_service):
        # Note that CreateGroupAPISchema and its methods are mocked here, so
        # ``groupid`` passes validation even though the request is not third party
        # Tests for that are handled directly in the CreateGroupAPISchema unit tests
        # and through functional tests
        CreateGroupAPISchema.return_value.validate.return_value = {
            'name': 'My Group',
            'description': 'How about that?',
            'groupid': 'group:[email protected]',
        }
        views.create(pyramid_request)

        group_create_service.create_private_group.assert_called_once_with(
            'My Group',
            pyramid_request.user.userid,
            description='How about that?',
            groupid='group:[email protected]')
Ejemplo n.º 18
0
    def test_it_passes_groupid_to_group_create_as_authority_provided_id(
        self, pyramid_request, CreateGroupAPISchema, group_create_service
    ):
        # Note that CreateGroupAPISchema and its methods are mocked here, so
        # ``groupid`` passes validation even though the request is not third party
        # Tests for that are handled directly in the CreateGroupAPISchema unit tests
        # and through functional tests
        CreateGroupAPISchema.return_value.validate.return_value = {
            "name": "My Group",
            "description": "How about that?",
            "groupid": "group:[email protected]",
        }
        views.create(pyramid_request)

        group_create_service.create_private_group.assert_called_once_with(
            "My Group",
            pyramid_request.user.userid,
            description="How about that?",
            groupid="group:[email protected]",
        )
Ejemplo n.º 19
0
    def test_it_creates_group_context_from_created_group(
            self, pyramid_request, factories, group_create_service,
            GroupJSONPresenter):
        group = factories.Group()
        group_create_service.create_private_group.return_value = group

        result = views.create(pyramid_request)

        GroupJSONPresenter.assert_called_once_with(group, pyramid_request)
        GroupJSONPresenter.return_value.asdict.assert_called_once_with(
            expand=["organization", "scopes"])
        assert result == GroupJSONPresenter.return_value.asdict.return_value
Ejemplo n.º 20
0
    def test_it_returns_400_if_user_has_non_default_authority(
            self, pyramid_request, factories):
        pyramid_request.user = factories.User(authority='other.com')

        with pytest.raises(HTTPBadRequest):
            views.create(pyramid_request)
Ejemplo n.º 21
0
    def test_it_inits_group_create_schema(self, pyramid_request, CreateGroupAPISchema):
        views.create(pyramid_request)

        CreateGroupAPISchema.return_value.validate.assert_called_once_with({})
Ejemplo n.º 22
0
    def test_it_inits_group_create_schema(self, pyramid_request, CreateGroupAPISchema):
        views.create(pyramid_request)

        CreateGroupAPISchema.return_value.validate.assert_called_once_with({})