import pytest

from busy_beaver.apps.call_for_proposals.cli import OpenCFPPost, post_upcoming_cfps
from tests._utilities import FakeSlackClient

MODULE_TO_TEST = "busy_beaver.apps.call_for_proposals.cli"


@pytest.fixture
def patched_slack(patcher):
    obj = FakeSlackClient()
    return patcher(MODULE_TO_TEST, namespace="SlackClient", replacement=obj)


@pytest.mark.unit
@pytest.mark.vcr
def test_post_upcoming_cfps(mocker, runner, factory, patched_slack):
    # Arrange
    config = factory.CallForProposalsConfiguration(enabled=True)

    # Act
    runner.invoke(post_upcoming_cfps)

    # Assert
    assert patched_slack.mock.call_count == 2

    slack_adapter_initalize_args = patched_slack.mock.call_args_list[0]
    args, kwargs = slack_adapter_initalize_args
    assert config.slack_installation.bot_access_token in args

    post_message_args = patched_slack.mock.call_args_list[-1]
    args, kwargs = post_message_args
    assert "blocks" in kwargs
    assert len(kwargs["blocks"]) == 5


@pytest.mark.unit
@pytest.mark.vcr
def test_post_upcoming_cfps_enabled(mocker, runner, factory, patched_slack):
    """Only post for configurations that are enabled

    Should have 2 calls:
        - when initialized
        - when post_message is called
    """
    # Arrange
    factory.CallForProposalsConfiguration(enabled=False)
    factory.CallForProposalsConfiguration(enabled=True)

    # Act
    runner.invoke(post_upcoming_cfps)

    # Assert
    assert patched_slack.mock.call_count == 2


@pytest.mark.unit
@pytest.mark.vcr
def test_post_no_open_cfps_found():
    """When there are no open CFPs, let the user know)"""
    # Act
    result = OpenCFPPost._generate_conference_text(conference_cfps=[])

    # Assert
    assert "No upcoming CFPs found" in result

6cd75f1b5c7c5aeb6147e61341320cb1a189e33b
<mask token>


@pytest.fixture
def patched_slack(patcher):
    obj = FakeSlackClient()
    return patcher(MODULE_TO_TEST, namespace='SlackClient', replacement=obj)


<mask token>


@pytest.mark.unit
@pytest.mark.vcr
def test_post_no_open_cfps_found():
    """When there are no open CFPs, let the user know)"""
    result = OpenCFPPost._generate_conference_text(conference_cfps=[])
    assert 'No upcoming CFPs found' in result

<mask token>


@pytest.fixture
def patched_slack(patcher):
    obj = FakeSlackClient()
    return patcher(MODULE_TO_TEST, namespace='SlackClient', replacement=obj)


@pytest.mark.unit
@pytest.mark.vcr
def test_post_upcoming_cfps(mocker, runner, factory, patched_slack):
    config = factory.CallForProposalsConfiguration(enabled=True)
    runner.invoke(post_upcoming_cfps)
    assert patched_slack.mock.call_count == 2
    slack_adapter_initalize_args = patched_slack.mock.call_args_list[0]
    args, kwargs = slack_adapter_initalize_args
    assert config.slack_installation.bot_access_token in args
    post_message_args = patched_slack.mock.call_args_list[-1]
    args, kwargs = post_message_args
    assert 'blocks' in kwargs
    assert len(kwargs['blocks']) == 5


@pytest.mark.unit
@pytest.mark.vcr
def test_post_upcoming_cfps_enabled(mocker, runner, factory, patched_slack):
    """Only post for configurations that are enabled

    Should have 2 calls:
        - when initialized
        - when post_message is called
    """
    factory.CallForProposalsConfiguration(enabled=False)
    factory.CallForProposalsConfiguration(enabled=True)
    runner.invoke(post_upcoming_cfps)
    assert patched_slack.mock.call_count == 2


@pytest.mark.unit
@pytest.mark.vcr
def test_post_no_open_cfps_found():
    """When there are no open CFPs, let the user know)"""
    result = OpenCFPPost._generate_conference_text(conference_cfps=[])
    assert 'No upcoming CFPs found' in result

<mask token>
MODULE_TO_TEST = 'busy_beaver.apps.call_for_proposals.cli'


@pytest.fixture
def patched_slack(patcher):
    obj = FakeSlackClient()
    return patcher(MODULE_TO_TEST, namespace='SlackClient', replacement=obj)


@pytest.mark.unit
@pytest.mark.vcr
def test_post_upcoming_cfps(mocker, runner, factory, patched_slack):
    config = factory.CallForProposalsConfiguration(enabled=True)
    runner.invoke(post_upcoming_cfps)
    assert patched_slack.mock.call_count == 2
    slack_adapter_initalize_args = patched_slack.mock.call_args_list[0]
    args, kwargs = slack_adapter_initalize_args
    assert config.slack_installation.bot_access_token in args
    post_message_args = patched_slack.mock.call_args_list[-1]
    args, kwargs = post_message_args
    assert 'blocks' in kwargs
    assert len(kwargs['blocks']) == 5


@pytest.mark.unit
@pytest.mark.vcr
def test_post_upcoming_cfps_enabled(mocker, runner, factory, patched_slack):
    """Only post for configurations that are enabled

    Should have 2 calls:
        - when initialized
        - when post_message is called
    """
    factory.CallForProposalsConfiguration(enabled=False)
    factory.CallForProposalsConfiguration(enabled=True)
    runner.invoke(post_upcoming_cfps)
    assert patched_slack.mock.call_count == 2


@pytest.mark.unit
@pytest.mark.vcr
def test_post_no_open_cfps_found():
    """When there are no open CFPs, let the user know)"""
    result = OpenCFPPost._generate_conference_text(conference_cfps=[])
    assert 'No upcoming CFPs found' in result

import pytest
from busy_beaver.apps.call_for_proposals.cli import OpenCFPPost, post_upcoming_cfps
from tests._utilities import FakeSlackClient
MODULE_TO_TEST = 'busy_beaver.apps.call_for_proposals.cli'


@pytest.fixture
def patched_slack(patcher):
    obj = FakeSlackClient()
    return patcher(MODULE_TO_TEST, namespace='SlackClient', replacement=obj)


@pytest.mark.unit
@pytest.mark.vcr
def test_post_upcoming_cfps(mocker, runner, factory, patched_slack):
    config = factory.CallForProposalsConfiguration(enabled=True)
    runner.invoke(post_upcoming_cfps)
    assert patched_slack.mock.call_count == 2
    slack_adapter_initalize_args = patched_slack.mock.call_args_list[0]
    args, kwargs = slack_adapter_initalize_args
    assert config.slack_installation.bot_access_token in args
    post_message_args = patched_slack.mock.call_args_list[-1]
    args, kwargs = post_message_args
    assert 'blocks' in kwargs
    assert len(kwargs['blocks']) == 5


@pytest.mark.unit
@pytest.mark.vcr
def test_post_upcoming_cfps_enabled(mocker, runner, factory, patched_slack):
    """Only post for configurations that are enabled

    Should have 2 calls:
        - when initialized
        - when post_message is called
    """
    factory.CallForProposalsConfiguration(enabled=False)
    factory.CallForProposalsConfiguration(enabled=True)
    runner.invoke(post_upcoming_cfps)
    assert patched_slack.mock.call_count == 2


@pytest.mark.unit
@pytest.mark.vcr
def test_post_no_open_cfps_found():
    """When there are no open CFPs, let the user know)"""
    result = OpenCFPPost._generate_conference_text(conference_cfps=[])
    assert 'No upcoming CFPs found' in result

import pytest

from busy_beaver.apps.call_for_proposals.cli import OpenCFPPost, post_upcoming_cfps
from tests._utilities import FakeSlackClient

MODULE_TO_TEST = "busy_beaver.apps.call_for_proposals.cli"


@pytest.fixture
def patched_slack(patcher):
    obj = FakeSlackClient()
    return patcher(MODULE_TO_TEST, namespace="SlackClient", replacement=obj)


@pytest.mark.unit
@pytest.mark.vcr
def test_post_upcoming_cfps(mocker, runner, factory, patched_slack):
    # Arrange
    config = factory.CallForProposalsConfiguration(enabled=True)

    # Act
    runner.invoke(post_upcoming_cfps)

    # Assert
    assert patched_slack.mock.call_count == 2

    slack_adapter_initalize_args = patched_slack.mock.call_args_list[0]
    args, kwargs = slack_adapter_initalize_args
    assert config.slack_installation.bot_access_token in args

    post_message_args = patched_slack.mock.call_args_list[-1]
    args, kwargs = post_message_args
    assert "blocks" in kwargs
    assert len(kwargs["blocks"]) == 5


@pytest.mark.unit
@pytest.mark.vcr
def test_post_upcoming_cfps_enabled(mocker, runner, factory, patched_slack):
    """Only post for configurations that are enabled

    Should have 2 calls:
        - when initialized
        - when post_message is called
    """
    # Arrange
    factory.CallForProposalsConfiguration(enabled=False)
    factory.CallForProposalsConfiguration(enabled=True)

    # Act
    runner.invoke(post_upcoming_cfps)

    # Assert
    assert patched_slack.mock.call_count == 2


@pytest.mark.unit
@pytest.mark.vcr
def test_post_no_open_cfps_found():
    """When there are no open CFPs, let the user know)"""
    # Act
    result = OpenCFPPost._generate_conference_text(conference_cfps=[])

    # Assert
    assert "No upcoming CFPs found" in result
