How to use the aiounittest.AsyncTestCase function in aiounittest

To help you get started, we’ve selected a few aiounittest 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 ph4r05 / monero-agent / monero_glue_test / test_basic.py View on Github external
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Dusan Klinec, ph4r05, 2018

import unittest

import aiounittest


class Basetest(aiounittest.AsyncTestCase):
    """Simple tests"""

    def __init__(self, *args, **kwargs):
        super(Basetest, self).__init__(*args, **kwargs)


if __name__ == "__main__":
    unittest.main()  # pragma: no cover
github kwarunek / aiounittest / tests / test_futurized.py View on Github external
from aiounittest import futurized, AsyncTestCase
from unittest.mock import Mock, patch

import dummy_math

class MyAddTest(AsyncTestCase):

    async def test_add(self):
        mock_sleep = Mock(return_value=futurized('whatever'))
        patch('dummy_math.sleep', mock_sleep).start()
        ret = await dummy_math.add(5, 6)
        self.assertEqual(ret, 11)
        mock_sleep.assert_called_once_with(666)

    async def test_fail(self):
        mock_sleep = Mock(return_value=futurized(Exception('whatever')))
        patch('dummy_math.sleep', mock_sleep).start()
        with self.assertRaises(Exception) as e:
            await dummy_math.add(5, 6)
        mock_sleep.assert_called_once_with(666)
github ph4r05 / monero-agent / monero_glue_test / test_b58.py View on Github external
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Dusan Klinec, ph4r05, 2018

import binascii
import unittest

import aiounittest
from monero_glue.misc import b58


class Base58Test(aiounittest.AsyncTestCase):
    """Simple tests"""

    def __init__(self, *args, **kwargs):
        super(Base58Test, self).__init__(*args, **kwargs)

    def test_base(self):
        """
        Simple b58 encode test
        :return:
        """
        self.assertIsNotNone(b58.b58encode(b""))
        self.assertIsNotNone(b58.b58encode(binascii.unhexlify(b"1234567890")))
        self.assertIsNotNone(b58.b58encode(binascii.unhexlify(b"1234567890" * 50)))
        self.assertEqual(
            b58.b58encode(
                binascii.unhexlify(
github DreamLab / VmShepherd / tests / test_rpc_api.py View on Github external
import time
import datetime
from aiounittest import futurized, AsyncTestCase
from unittest.mock import patch, Mock
from vmshepherd.http.rpc_api import RpcApi
from vmshepherd.iaas.vm import Vm, VmState


class TestRpcApi(AsyncTestCase):

    def tearDown(self):
        patch.stopall()
        super().tearDown()

    def setUp(self):
        super().setUp()
        mock_request = Mock()
        self.mock_preset_manager = Mock()
        mock_vm_launched_time = time.time()
        self.mock_preset_manager.get_vms.return_value = futurized([
            Vm('1243454353', 'C_DEV-app-dev',
               ['10.177.51.8'], mock_vm_launched_time, state=VmState.RUNNING),
            Vm('4535646466', 'C_DEV-app-dev',
               ['10.177.51.9'], mock_vm_launched_time, state=VmState.RUNNING),
            Vm('5465465643', 'C_DEV-app-dev',
github DreamLab / VmShepherd / tests / test_openstack_driver.py View on Github external
from aiounittest import futurized, AsyncTestCase
from bidict import bidict
from unittest.mock import patch
from vmshepherd.iaas import OpenStackDriver


class MockVM:
    def __init__(self):
        pass


class TestOpenStackDriver(AsyncTestCase):

    def setUp(self):
        self.config = {
            'auth_url': 'http://keystone.api.int.iaas:5000/v3',
            'username': 'paas-c2-int-1-api-access',
            'password': '00e91e6550bcd29cfd306280df1caf5e',
            'project_id': '7b6052ae16434e79bc6456808c9f37a6',
            'project_name': 'c2-int-1',
            'api_version': '2.26',
            'flavor_id': '9c17893c-6fc4-4a69-96c8-6e5a8af6b836',
            'image_id': 'c0d3fe3e-52f9-4a2c-aeb1-b8c977fd7d17',
            'flavor': 'm1.tiny',
            'image': 'ubuntu-xenial',
            'project_domain_name': 'grupa.onet',
            'user_domain_name': 'default',
            'image_owner_ids': [
github ph4r05 / monero-agent / monero_glue_test / test_chacha.py View on Github external
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Dusan Klinec, ph4r05, 2018

import unittest

import aiounittest
from monero_glue.xmr import crypto
from monero_glue.xmr.enc import chacha


class ChachaTest(aiounittest.AsyncTestCase):
    """Simple tests"""

    def __init__(self, *args, **kwargs):
        super(ChachaTest, self).__init__(*args, **kwargs)

    def test_encrypt_base(self):
        for i in range(10):
            key = crypto.cn_fast_hash(crypto.encodeint(crypto.random_scalar()))
            data = crypto.cn_fast_hash(crypto.encodeint(crypto.random_scalar())) * (
                i + 1
            )

            ciphertext = chacha.encrypt(key, data)
            plaintext = chacha.decrypt(key, ciphertext)
            self.assertEqual(plaintext, data)
github ph4r05 / monero-agent / monero_glue_test / test_crypto.py View on Github external
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Dusan Klinec, ph4r05, 2018

import binascii
from binascii import unhexlify
import unittest

import aiounittest
from monero_glue.xmr import common, crypto
from monero_glue.xmr.core import ec_py


class CryptoTest(aiounittest.AsyncTestCase):
    """Simple tests"""

    def __init__(self, *args, **kwargs):
        super(CryptoTest, self).__init__(*args, **kwargs)

    def test_ed_crypto(self):
        sqr = ec_py.fe_expmod(ec_py.py_fe_sqrtm1, 2)
        self.assertEqual(sqr, ec_py.fe_mod(-1))
        self.assertEqual(
            ec_py.py_fe_A, ec_py.fe_mod(2 * (1 - ec_py.d) * ec_py.inv(1 + ec_py.py_d))
        )

        self.assertEqual(
            ec_py.fe_expmod(ec_py.py_fe_fffb1, 2),
            ec_py.fe_mod(-2 * ec_py.py_fe_A * (ec_py.py_fe_A + 2)),
        )
github DreamLab / AsyncOpenStackClient / tests / test_auth.py View on Github external
import os
from aioresponses import aioresponses
from aiounittest import AsyncTestCase, futurized
from asyncopenstackclient import AuthPassword
from unittest.mock import patch


class TestAuth(AsyncTestCase):

    def setUp(self):
        self.auth_args = ('http://url', 'm_user', 'm_pass', 'm_project',
                          'm_user_domain', 'm_project_domain')
        self.auth = AuthPassword(*self.auth_args)

    def tearDown(self):
        patch.stopall()
        for name in list(os.environ.keys()):
            if name.startswith('OS_'):
                del os.environ[name]

    async def test_create_object(self):
        expected_payload = {'auth': {
            'identity': {'methods': ['password'], 'password': {'user': {
                'domain': {'name': 'm_user_domain'},
github xeroc / python-graphenelib / tests / test_message_aio.py View on Github external
# -*- coding: utf-8 -*-
import json
import aiounittest
from .fixtures_aio import fixture_data, Message, MessageV1, MessageV2
from pprint import pprint
from graphenecommon.exceptions import InvalidMessageSignature


class Testcases(aiounittest.AsyncTestCase):
    def setUp(self):
        fixture_data()

    async def test_sign_message(self):
        m = await Message("message foobar")
        p = await m.sign(account="init0")
        m2 = await Message(p)
        await m2.verify()

    async def test_verify_message(self):
        m = await Message(
            """
-----BEGIN GRAPHENE SIGNED MESSAGE-----
message foobar
-----BEGIN META-----
account=init0
github ph4r05 / monero-agent / monero_glue_test / test_agent.py View on Github external
# -*- coding: utf-8 -*-
# Author: Dusan Klinec, ph4r05, 2018

import binascii
import os
import unittest
import zlib

import aiounittest
import pkg_resources
from monero_glue.old import agent, trezor
from monero_glue.xmr import crypto, monero
from monero_serialize import xmrserialize, xmrtypes


class AgentTest(aiounittest.AsyncTestCase):
    """Simple tests"""

    def __init__(self, *args, **kwargs):
        super(AgentTest, self).__init__(*args, **kwargs)

    async def test_tx_sign_simple(self):
        """
        Testing tx signature, simple, multiple inputs
        :return:
        """
        unsigned_tx_c = pkg_resources.resource_string(
            __name__, os.path.join("data", "tsx_uns01.txt")
        )
        unsigned_tx = zlib.decompress(binascii.unhexlify(unsigned_tx_c))

        await self.tx_sign(unsigned_tx)

aiounittest

Test asyncio code more easily.

MIT
Latest version published 3 years ago

Package Health Score

52 / 100
Full package analysis

Similar packages