Пример #1
0
    def test_create_user_with_invalid_password(self, LOGGER_error_mock,
                                               resquests_post_mock,
                                               COLAB_APPS_mock):
        resquests_post_mock.return_value = Mock(
            status_code=500,
            json=lambda: {'message': {'password': '******'}}
        )

        COLAB_APPS_mock.return_value = {
            'colab_gitlab': {
                'private_token': "TestToken",
                'upstream': "https://testeurl.com/",
                'verify_ssl': True,
            },
        }

        user = Mock(
            email="*****@*****.**",
            username="******",
            get_full_name=lambda: "Full Name Test"
        )

        create_gitlab_user(None, user=user, password="******")

        error_msg = (u'Error trying to update "{}" password on Gitlab.' +
                     ' Reason: {}')
        error_msg = error_msg.format(user.username, 'test password')
        LOGGER_error_mock.assert_called_with(error_msg)
Пример #2
0
    def test_create_user_with_invalid_request(self, LOGGER_error_mock,
                                              resquests_post_mock,
                                              COLAB_APPS_mock):
        resquests_post_mock.side_effect = Exception()

        COLAB_APPS_mock.return_value = {
            'colab_gitlab': {
                'private_token': "TestToken",
                'upstream': "https://testeurl.com/",
                'verify_ssl': True,
            },
        }

        user = Mock(
            email="*****@*****.**",
            username="******",
            get_full_name=lambda: "Full Name Test"
        )

        create_gitlab_user(None, user=user, password="******")

        reason = 'Request to API failed ({})'.format(Exception())
        error_msg = (u'Error trying to update "{}" password on Gitlab.' +
                     ' Reason: {}')
        error_msg = error_msg.format(user.username, reason)
        LOGGER_error_mock.assert_called_with(error_msg)
Пример #3
0
    def test_create_user_with_valid_token(self, LOGGER_info_mock,
                                          resquests_post_mock,
                                          COLAB_APPS_mock):
        resquests_post_mock.return_value = Mock(
            status_code=201,
            json=lambda: {'message': 'Unauthorized'}
        )

        COLAB_APPS_mock.return_value = {
            'colab_gitlab': {
                'private_token': "TestToken",
                'upstream': "https://testeurl.com/",
                'verify_ssl': True,
            },
        }

        user = Mock(
            email="*****@*****.**",
            username="******",
            get_full_name=lambda: "Full Name Test"
        )

        create_gitlab_user(None, user=user, password="******")

        msg = ('Gitlab user "%s" created')
        LOGGER_info_mock.assert_called_with(msg, user.username)
Пример #4
0
    def test_create_user_with_valid_token(self, LOGGER_info_mock, resquests_post_mock, COLAB_APPS_mock):
        resquests_post_mock.return_value = Mock(status_code=201, json=lambda: {"message": "Unauthorized"})

        COLAB_APPS_mock.return_value = {
            "colab_gitlab": {"private_token": "TestToken", "upstream": "https://testeurl.com/", "verify_ssl": True}
        }

        user = Mock(email="*****@*****.**", username="******", get_full_name=lambda: "Full Name Test")

        create_gitlab_user(None, user=user, password="******")

        msg = 'Gitlab user "%s" created'
        LOGGER_info_mock.assert_called_with(msg, user.username)
Пример #5
0
    def test_create_user_with_invalid_token(self, LOGGER_error_mock, resquests_post_mock, COLAB_APPS_mock):
        resquests_post_mock.return_value = Mock(status_code=500, json=lambda: {"message": "Unauthorized"})

        COLAB_APPS_mock.return_value = {
            "colab_gitlab": {"private_token": "TestToken", "upstream": "https://testeurl.com/", "verify_ssl": True}
        }

        user = Mock(email="*****@*****.**", username="******", get_full_name=lambda: "Full Name Test")

        create_gitlab_user(None, user=user, password="******")

        error_msg = u'Error trying to update "{}" password on Gitlab.' + " Reason: {}"
        error_msg = error_msg.format(user.username, "Unknown.")
        LOGGER_error_mock.assert_called_with(error_msg)
Пример #6
0
    def test_create_user_with_invalid_request(self, LOGGER_error_mock, resquests_post_mock, COLAB_APPS_mock):
        resquests_post_mock.side_effect = Exception()

        COLAB_APPS_mock.return_value = {
            "colab_gitlab": {"private_token": "TestToken", "upstream": "https://testeurl.com/", "verify_ssl": True}
        }

        user = Mock(email="*****@*****.**", username="******", get_full_name=lambda: "Full Name Test")

        create_gitlab_user(None, user=user, password="******")

        reason = "Request to API failed ({})".format(Exception())
        error_msg = u'Error trying to update "{}" password on Gitlab.' + " Reason: {}"
        error_msg = error_msg.format(user.username, reason)
        LOGGER_error_mock.assert_called_with(error_msg)