Esempio n. 1
0
    def test_success(self, mocker):
        """
        Given:
            - An app client object
            - A scim argument that contains a displayName of a non-existing group in the application
        When:
            - Calling the main function with 'iam-create-group' command
        Then:
            - Ensure the resulted 'CommandResults' object holds information about the created group.
        """
        mock_result = mocker.patch('OracleIAM.CommandResults')

        args = {"scim": "{\"displayName\": \"The group name\"}"}

        with requests_mock.Mocker() as m:
            m.post('https://test.com/oauth2/v1/token', json={})
            m.post('https://test.com/admin/v1/Groups',
                   status_code=201,
                   json=APP_GROUP_OUTPUT)

            client = mock_client()
            create_group_command(client, args)

        assert mock_result.call_args.kwargs['outputs']['success'] is True
        assert mock_result.call_args.kwargs['outputs']['id'] == '1234'
        assert mock_result.call_args.kwargs['outputs'][
            'displayName'] == 'The group name'
Esempio n. 2
0
    def test_group_already_exist(self):
        """
        Given:
            - An app client object
            - A scim argument that contains a displayName of an existing group in the application
        When:
            - Calling the main function with 'iam-create-group' command
        Then:
            - Ensure that an error is raised with an expected message.
        """

        args = {"scim": "{\"displayName\": \"The group name\"}"}

        with requests_mock.Mocker() as m:
            m.post('https://test.com/oauth2/v1/token', json={})
            m.post('https://test.com/admin/v1/Groups',
                   status_code=400,
                   text="Group already exist")

            client = mock_client()

            with pytest.raises(Exception) as e:
                create_group_command(client, args)

        assert e.value.res.status_code == 400
        assert 'Group already exist' in str(e.value)
Esempio n. 3
0
    def test_group_already_exist(self):
        """
        Given:
            - An app client object
            - A scim argument that contains a displayName of an existing group in the application
        When:
            - Calling the main function with 'iam-create-group' command
        Then:
            - Ensure that an error is raised with an expected message.
        """

        args = {"scim": "{\"displayName\": \"The group name\"}"}

        with requests_mock.Mocker() as m:
            m.post('https://test.com/oauth2/v1/token', json={})
            m.post('https://test.com/admin/v1/Groups',
                   status_code=400,
                   json={
                       "detail": "Group already exist",
                       "status": 400
                   })

            client = mock_client()

            res = create_group_command(client, args)

        assert res.raw_response.get("errorCode") == 400
        assert 'Group already exist' in res.raw_response.get("errorMessage")
Esempio n. 4
0
    def test_display_name_empty(self):
        """
        Given:
            - An app client object
            - A scim argument that not contains a displayName
        When:
            - Calling the main function with 'iam-create-group' command
        Then:
            - Ensure that an error is raised with an expected message.
        """

        args = {"scim": "{}"}

        with requests_mock.Mocker() as m:
            m.post('https://test.com/oauth2/v1/token', json={})

            client = mock_client()

            with pytest.raises(Exception) as e:
                create_group_command(client, args)

        assert str(
            e.value
        ) == 'You must supply "displayName" of the group in the scim data'