Esempio n. 1
0
    def test_call_connected(self):

        self.session.connected = True

        client = Client(self.session, self.method_map)
        client._on_error = Mock()
        deferred = client.method_1(arg1=1, arg2='2')

        assert isinstance(deferred, Deferred)
        assert not deferred.called
        assert not client._on_error.called
Esempio n. 2
0
    def test_call_not_connected(self):

        result = self.Result()
        self.session.connected = False

        client = Client(self.session, self.method_map)
        client._on_error = Mock()
        deferred = client.method_1(arg1=1, arg2='2')

        assert isinstance(deferred, Deferred)
        assert deferred.called

        deferred.addCallbacks(result.set, result.set)
        assert isinstance(result.value, Failure)
        assert not client._on_error.called
Esempio n. 3
0
    def _frontend_session_started(self, *_):
        client = Client(self.state.frontend_session, MockService.methods)
        publisher = Publisher(self.state.backend_session)

        multiply_result = yield client.multiply(2, 3)
        assert multiply_result == 6

        divide_result = yield client.divide(4)
        assert divide_result == 2

        divide_result = yield client.divide(8, 4)
        assert divide_result == 2

        assert self.state.frontend.n_hello_received == 0
        yield publisher.publish('mock.event.hello')
        yield util.sleep(0.5)
        assert self.state.frontend.n_hello_received > 0

        with self.assertRaises(ApplicationError):
            yield client.exception()

        ping_result = yield client.ping()
        assert ping_result == u'pong'

        yield self.state.router.stop()
        self.state.done = True
Esempio n. 4
0
 def on_connected(_):
     core_client = Client(self.session, CORE_METHOD_MAP)
     self.cli.register_client(core_client)
     threads.deferToThread(self.cli.execute, *args, **kwargs).addBoth(self.shutdown)
Esempio n. 5
0
 def session_ready(*_):
     core_client = Client(session, CORE_METHOD_MAP)
     reactor.callFromThread(gui_app.start, core_client)
Esempio n. 6
0
    def test_call_no_session(self):

        client = Client(None, self.method_map)
        with self.assertRaises(AttributeError):
            client.method_1(arg1=1, arg2='2')
Esempio n. 7
0
 def test_initialization(self):
     client = Client(self.session, self.method_map)
     assert hasattr(client, 'method_1')
     assert hasattr(client, 'method_2')
     assert callable(getattr(client, 'method_1'))
     assert callable(getattr(client, 'method_2'))
from golem.interface.client.account import account
from golem.interface.client.environments import Environments
from golem.interface.client.network import Network
from golem.interface.client.payments import incomes, payments
from golem.interface.client.resources import Resources
from golem.interface.client.settings import Settings, _virtual_mem, _cpu_count
from golem.interface.client.tasks import Subtasks, Tasks
from golem.interface.command import CommandResult, client_ctx
from golem.interface.exceptions import CommandException
from golem.resource.dirmanager import DirManager, DirectoryType
from golem.rpc.mapping.core import CORE_METHOD_MAP
from golem.rpc.session import Client
from golem.task.tasktester import TaskTester
from golem.testutils import TempDirFixture

reference_client = Client(Mock(), CORE_METHOD_MAP)


def assert_client_method(instance, name):
    assert hasattr(reference_client, name)
    return super(Mock, instance).__getattribute__(name)


class TestAccount(unittest.TestCase):
    def test(self):

        node = dict(node_name='node1', key='deadbeef')

        client = Mock()
        client.__getattribute__ = assert_client_method
        client.get_node.return_value = node