Ejemplo n.º 1
0
def test_sailthru_success(test_learner, caplog):  # pylint: disable=redefined-outer-name
    with mock.patch('tubular.sailthru_api.SailthruClient'):
        sailthru_api = SailthruApi('key', 'secret')  # pylint: disable=redefined-outer-name
        mock_response = mock.Mock()
        mock_response.is_ok.return_value = True
        sailthru_api._sailthru_client.api_delete.return_value = mock_response  # pylint: disable=protected-access
        with caplog.at_level(logging.INFO):
            sailthru_api.delete_user(test_learner)
        assert 'User successfully deleted from Sailthru.' in caplog.text
Ejemplo n.º 2
0
def test_sailthru_delete_not_ok_response(test_learner):  # pylint: disable=redefined-outer-name
    with mock.patch('tubular.sailthru_api.SailthruClient'):
        sailthru_api = SailthruApi('key', 'secret')  # pylint: disable=redefined-outer-name
        mock_response = mock.Mock()
        mock_response.is_ok.return_value = False
        mock_error = mock.Mock()
        mock_error.get_message.return_value = "Random error message, doesnt matter what this is."
        mock_response.get_error.return_value = mock_error
        sailthru_api._sailthru_client.api_delete.return_value = mock_response  # pylint: disable=protected-access
        with pytest.raises(Exception) as exc:
            sailthru_api.delete_user(test_learner)
        assert 'Error attempting to delete user from Sailthru' in str(exc)
Ejemplo n.º 3
0
def test_sailthru_delete_not_found_response(test_learner, caplog):  # pylint: disable=redefined-outer-name
    """
    The user never opted into email marketing, so they never had a sailthru
    profile generated.  Sailthru will respond with a "not found" error, which
    we should treat as "no action needed".
    """
    with mock.patch('tubular.sailthru_api.SailthruClient'):
        sailthru_api = SailthruApi('key', 'secret')  # pylint: disable=redefined-outer-name
        mock_response = mock.Mock()
        mock_response.is_ok.return_value = False
        mock_error = mock.Mock()
        mock_error.get_message.return_value = 'User not found with email: [email protected]'
        mock_response.get_error.return_value = mock_error
        sailthru_api._sailthru_client.api_delete.return_value = mock_response  # pylint: disable=protected-access
        with caplog.at_level(logging.INFO):
            sailthru_api.delete_user(test_learner)
        assert 'No action taken because no user was found in Sailthru.' in caplog.text