How to use the asynctest.skipIf function in asynctest

To help you get started, we’ve selected a few asynctest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Gelbpunkt / aiowiki / tests / __init__.py View on Github external
    @asynctest.skipIf(small_test, "No enviroment variables for testing set up")
    async def test_page_edit(self):
        wiki = aiowiki.Wiki(AIOWIKI_TEST_URL)
        page = wiki.get_page("Spam")
        try:
            await page.edit("Eggs & Ham")
        except aiowiki.EditError as e:
            if not "action you have requested is limited to users in the group" in str(
                e
            ):
                raise
            else:
                await wiki.login(AIOWIKI_TEST_USERNAME, AIOWIKI_TEST_PASSWORD)
                await page.edit("Eggs & Ham")
        await wiki.close()
github Peter-Slump / python-keycloak-client / tests / keycloak / aio / test_realm.py View on Github external
except ImportError:
    aiohttp = None
else:
    from keycloak.admin import KeycloakAdmin
    from keycloak.aio.authz import KeycloakAuthz
    from keycloak.aio.client import KeycloakClient
    from keycloak.aio.openid_connect import KeycloakOpenidConnect
    from keycloak.aio.uma import KeycloakUMA
    from keycloak.aio.realm import KeycloakRealm


async def wraps_awaitable(return_value):
    return return_value


@asynctest.skipIf(aiohttp is None, "aiohttp is not installed")
class KeycloakRealmTestCase(asynctest.TestCase):
    async def setUp(self):
        self.mocked_client_patcher = asynctest.patch(
            "keycloak.aio.realm.KeycloakClient", autospec=True
        )

        self.mocked_client = self.mocked_client_patcher.start()

        self.mocked_client.return_value = asynctest.CoroutineMock(
            return_value=wraps_awaitable(return_value=self.mocked_client.return_value)
        )()

        self.realm = await KeycloakRealm(
            "https://example.com",
            "some-realm",
            headers={"some": "header"},
github Peter-Slump / python-keycloak-client / tests / keycloak / aio / admin / test_roles.py View on Github external
import asynctest

try:
    import aiohttp
except ImportError:
    aiohttp = None
else:
    from keycloak.admin import KeycloakAdmin
    from keycloak.aio.realm import KeycloakRealm
    from keycloak.client import KeycloakClient


@asynctest.skipIf(aiohttp is None, 'aiohttp is not installed')
class KeycloakAdminRolesTestCase(asynctest.TestCase):
    def setUp(self):
        self.realm = asynctest.MagicMock(spec_set=KeycloakRealm)
        self.realm.client = asynctest.MagicMock(spec_set=KeycloakClient)()
        self.realm.client.get = asynctest.CoroutineMock()
        self.realm.client.post = asynctest.CoroutineMock()
        self.realm.client.put = asynctest.CoroutineMock()
        self.realm.client.delete = asynctest.CoroutineMock()
        self.realm.realm_name = 'realm-name'
        self.client_id = 'client-id'
        self.admin = KeycloakAdmin(realm=self.realm)
        self.admin.set_token('some-token')

    async def tearDown(self):
        await self.realm.close()
github pnuckowski / aioresponses / tests / test_aioresponses.py View on Github external
    @skipIf(condition=AIOHTTP_VERSION < '3.4.0',
            reason='aiohttp<3.4.0 does not support raise_for_status '
                   'arguments for requests')
    def test_do_not_raise_for_status(self, m):
        m.get(self.url, status=400)
        response = yield from self.session.get(self.url,
                                               raise_for_status=False)

        self.assertEqual(response.status, 400)
github Peter-Slump / python-keycloak-client / tests / keycloak / aio / test_admin.py View on Github external
import asynctest

try:
    import aiohttp  # noqa: F401
except ImportError:
    aiohttp = None
else:
    from keycloak.admin import KeycloakAdmin
    from keycloak.admin.realm import Realms
    from keycloak.aio.realm import KeycloakRealm


@asynctest.skipIf(aiohttp is None, "aiohttp is not installed")
class KeycloakAdminTestCase(asynctest.TestCase):
    def setUp(self):
        self.realm = asynctest.MagicMock(spec_set=KeycloakRealm)
        self.admin = KeycloakAdmin(realm=self.realm)

    def test_realm(self):
        realm = self.admin.realms
        self.assertIsInstance(realm, Realms)
github Peter-Slump / python-keycloak-client / tests / keycloak / aio / admin / test_users.py View on Github external
import asynctest

try:
    import aiohttp
except ImportError:
    aiohttp = None
else:
    from keycloak.admin import KeycloakAdmin
    from keycloak.client import KeycloakClient
    from keycloak.realm import KeycloakRealm


@asynctest.skipIf(aiohttp is None, 'aiohttp is not installed')
class KeycloakAdminUsersTestCase(asynctest.TestCase):

    def setUp(self):
        self.realm = asynctest.MagicMock(spec_set=KeycloakRealm)
        self.realm.client = asynctest.MagicMock(spec_set=KeycloakClient)()
        self.realm.client.get = asynctest.CoroutineMock()
        self.realm.client.post = asynctest.CoroutineMock()
        self.realm.client.put = asynctest.CoroutineMock()
        self.realm.client.delete = asynctest.CoroutineMock()
        self.admin = KeycloakAdmin(realm=self.realm)
        self.admin.set_token('some-token')

    async def test_create(self):
        await self.admin.realms.by_name('realm-name').users.create(
            username='my-username',
            credentials={'some': 'value'},
github Peter-Slump / python-keycloak-client / tests / keycloak / aio / test_uma.py View on Github external
import asynctest

try:
    import aiohttp  # noqa: F401
except ImportError:
    aiohttp = None
else:
    from keycloak.aio.uma import KeycloakUMA
    from keycloak.aio.realm import KeycloakRealm
    from keycloak.aio.well_known import KeycloakWellKnown


@asynctest.skipIf(aiohttp is None, "aiohttp is not installed")
class KeycloakOpenidConnectTestCase(asynctest.TestCase):
    async def setUp(self):
        self.realm = asynctest.MagicMock(spec_set=KeycloakRealm)
        self.realm.client.get = asynctest.CoroutineMock()
        self.realm.client.post = asynctest.CoroutineMock()
        self.realm.client.put = asynctest.CoroutineMock()
        self.realm.client.delete = asynctest.CoroutineMock()

        self.uma_client = await KeycloakUMA(realm=self.realm)
        self.uma_client.well_known.contents = {
            "resource_registration_endpoint": "https://resource_registration",
            "permission_endpoint": "https://permission",
            "policy_endpoint": "https://policy",
        }

    async def tearDown(self):
github Peter-Slump / python-keycloak-client / tests / keycloak / aio / test_authz.py View on Github external
import asynctest

try:
    import aiohttp  # noqa: F401
except ImportError:
    aiohttp = None
else:
    from keycloak.aio.authz import KeycloakAuthz
    from keycloak.aio.client import KeycloakClient
    from keycloak.aio.realm import KeycloakRealm


@asynctest.skipIf(aiohttp is None, 'aiohttp is not installed')
class KeycloakAuthzTestCase(asynctest.TestCase):
    async def setUp(self):
        self.realm = asynctest.MagicMock(spec_set=KeycloakRealm)
        self.realm.client = asynctest.MagicMock(spec_set=KeycloakClient)
        self.realm.client.get = asynctest.CoroutineMock()
        self.realm.realm_name = 'realm-name'
        self.client_id = 'client-id'
        self.authz = await KeycloakAuthz(realm=self.realm,
                                         client_id=self.client_id)

    async def tearDown(self):
        await self.realm.close()

    def test_well_known_loaded(self):
        assert self.realm.client.get_full_url.call_count == 1
        assert self.realm.client.get.await_count == 1