from unittest.mock import patch, MagicMock

from pdchaosazure.webapp.actions import stop, restart, delete
from tests.data import config_provider, secrets_provider, webapp_provider


@patch('pdchaosazure.webapp.actions.fetch_webapps', autospec=True)
@patch('pdchaosazure.webapp.actions.client.init', autospec=True)
def test_happily_stop_webapp(init, fetch):
    config = config_provider.provide_default_config()
    secrets = secrets_provider.provide_secrets_public()
    webapp = webapp_provider.default()

    client = MagicMock()
    init.return_value = client
    resource_list = [webapp]
    fetch.return_value = resource_list

    f = "where resourceGroup=~'rg'"
    stop(f, config, secrets)

    fetch.assert_called_with(f, config, secrets)
    client.web_apps.stop.assert_called_with(webapp['resourceGroup'], webapp['name'])


@patch('pdchaosazure.webapp.actions.fetch_webapps', autospec=True)
@patch('pdchaosazure.webapp.actions.client.init', autospec=True)
def test_happily_restart_webapp(init, fetch):
    config = config_provider.provide_default_config()
    secrets = secrets_provider.provide_secrets_public()
    webapp = webapp_provider.default()

    client = MagicMock()
    init.return_value = client
    resource_list = [webapp]
    fetch.return_value = resource_list

    f = "where resourceGroup=~'rg'"
    restart(f, config, secrets)

    fetch.assert_called_with(f, config, secrets)
    client.web_apps.restart.assert_called_with(webapp['resourceGroup'], webapp['name'])


@patch('pdchaosazure.webapp.actions.fetch_webapps', autospec=True)
@patch('pdchaosazure.webapp.actions.client.init', autospec=True)
def test_happily_delete_webapp(init, fetch):
    webapp = webapp_provider.default()
    config = config_provider.provide_default_config()
    secrets = secrets_provider.provide_secrets_public()

    client = MagicMock()
    init.return_value = client
    resource_list = [webapp]
    fetch.return_value = resource_list

    f = "where resourceGroup=~'rg'"
    delete(f, config, secrets)

    fetch.assert_called_with(f, config, secrets)
    client.web_apps.delete.assert_called_with(webapp['resourceGroup'], webapp['name'])

[((183, 248), 'unittest.mock.patch', 'patch', (['"""pdchaosazure.webapp.actions.fetch_webapps"""'], {'autospec': '(True)'}), "('pdchaosazure.webapp.actions.fetch_webapps', autospec=True)\n", (188, 248), False, 'from unittest.mock import patch, MagicMock\n'), ((250, 313), 'unittest.mock.patch', 'patch', (['"""pdchaosazure.webapp.actions.client.init"""'], {'autospec': '(True)'}), "('pdchaosazure.webapp.actions.client.init', autospec=True)\n", (255, 313), False, 'from unittest.mock import patch, MagicMock\n'), ((835, 900), 'unittest.mock.patch', 'patch', (['"""pdchaosazure.webapp.actions.fetch_webapps"""'], {'autospec': '(True)'}), "('pdchaosazure.webapp.actions.fetch_webapps', autospec=True)\n", (840, 900), False, 'from unittest.mock import patch, MagicMock\n'), ((902, 965), 'unittest.mock.patch', 'patch', (['"""pdchaosazure.webapp.actions.client.init"""'], {'autospec': '(True)'}), "('pdchaosazure.webapp.actions.client.init', autospec=True)\n", (907, 965), False, 'from unittest.mock import patch, MagicMock\n'), ((1496, 1561), 'unittest.mock.patch', 'patch', (['"""pdchaosazure.webapp.actions.fetch_webapps"""'], {'autospec': '(True)'}), "('pdchaosazure.webapp.actions.fetch_webapps', autospec=True)\n", (1501, 1561), False, 'from unittest.mock import patch, MagicMock\n'), ((1563, 1626), 'unittest.mock.patch', 'patch', (['"""pdchaosazure.webapp.actions.client.init"""'], {'autospec': '(True)'}), "('pdchaosazure.webapp.actions.client.init', autospec=True)\n", (1568, 1626), False, 'from unittest.mock import patch, MagicMock\n'), ((370, 410), 'tests.data.config_provider.provide_default_config', 'config_provider.provide_default_config', ([], {}), '()\n', (408, 410), False, 'from tests.data import config_provider, secrets_provider, webapp_provider\n'), ((425, 466), 'tests.data.secrets_provider.provide_secrets_public', 'secrets_provider.provide_secrets_public', ([], {}), '()\n', (464, 466), False, 'from tests.data import config_provider, secrets_provider, webapp_provider\n'), ((480, 505), 'tests.data.webapp_provider.default', 'webapp_provider.default', ([], {}), '()\n', (503, 505), False, 'from tests.data import config_provider, secrets_provider, webapp_provider\n'), ((520, 531), 'unittest.mock.MagicMock', 'MagicMock', ([], {}), '()\n', (529, 531), False, 'from unittest.mock import patch, MagicMock\n'), ((672, 696), 'pdchaosazure.webapp.actions.stop', 'stop', (['f', 'config', 'secrets'], {}), '(f, config, secrets)\n', (676, 696), False, 'from pdchaosazure.webapp.actions import stop, restart, delete\n'), ((1025, 1065), 'tests.data.config_provider.provide_default_config', 'config_provider.provide_default_config', ([], {}), '()\n', (1063, 1065), False, 'from tests.data import config_provider, secrets_provider, webapp_provider\n'), ((1080, 1121), 'tests.data.secrets_provider.provide_secrets_public', 'secrets_provider.provide_secrets_public', ([], {}), '()\n', (1119, 1121), False, 'from tests.data import config_provider, secrets_provider, webapp_provider\n'), ((1135, 1160), 'tests.data.webapp_provider.default', 'webapp_provider.default', ([], {}), '()\n', (1158, 1160), False, 'from tests.data import config_provider, secrets_provider, webapp_provider\n'), ((1175, 1186), 'unittest.mock.MagicMock', 'MagicMock', ([], {}), '()\n', (1184, 1186), False, 'from unittest.mock import patch, MagicMock\n'), ((1327, 1354), 'pdchaosazure.webapp.actions.restart', 'restart', (['f', 'config', 'secrets'], {}), '(f, config, secrets)\n', (1334, 1354), False, 'from pdchaosazure.webapp.actions import stop, restart, delete\n'), ((1685, 1710), 'tests.data.webapp_provider.default', 'webapp_provider.default', ([], {}), '()\n', (1708, 1710), False, 'from tests.data import config_provider, secrets_provider, webapp_provider\n'), ((1724, 1764), 'tests.data.config_provider.provide_default_config', 'config_provider.provide_default_config', ([], {}), '()\n', (1762, 1764), False, 'from tests.data import config_provider, secrets_provider, webapp_provider\n'), ((1779, 1820), 'tests.data.secrets_provider.provide_secrets_public', 'secrets_provider.provide_secrets_public', ([], {}), '()\n', (1818, 1820), False, 'from tests.data import config_provider, secrets_provider, webapp_provider\n'), ((1835, 1846), 'unittest.mock.MagicMock', 'MagicMock', ([], {}), '()\n', (1844, 1846), False, 'from unittest.mock import patch, MagicMock\n'), ((1987, 2013), 'pdchaosazure.webapp.actions.delete', 'delete', (['f', 'config', 'secrets'], {}), '(f, config, secrets)\n', (1993, 2013), False, 'from pdchaosazure.webapp.actions import stop, restart, delete\n')]