Exemple #1
0
def pk_specs_cursor():
    with Mock() as cursor:
        result = [('table1', 'col1'), ('table2', 'col1'),
                  ('table2', 'col2')]
        cursor.execute(ANY_ARG)
        cursor.fetchall().returns(result)
        cursor.close()

    return cursor
Exemple #2
0
def table_spec_cursor():
    with Mock() as cursor:
        result = [('table1', 'BASE TABLE'), ('table2', 'BASE TABLE'),
                  ('view1', 'VIEW')]
        cursor.execute(ANY_ARG)
        cursor.fetchall().returns(result)
        cursor.close()

    return cursor
Exemple #3
0
    def test_account_behaviour_with_mock(self):
        with Stub(PasswordService) as password_service:
            password_service.generate().returns('some')

        with Mock(AccountStore) as store:
            store.has_user('John')
            store.save('John', 'some')
            store.has_user('Peter')
            store.save('Peter', 'some')

        service = AccountService(store, password_service)

        service.create_group('team', ['John', 'Peter'])

        assert_that(store, verify())
Exemple #4
0
def column_specs_cursor():
    with Mock() as cursor:
        result = [('table1', 1, 'col1', 'int2', 'NO'),
                  ('table1', 2, 'col2', 'float8', 'YES'),
                  ('table1', 3, 'col3', 'timestamptz', 'NO'),
                  ('table1', 4, 'col4', 'timestamp', 'NO'),
                  ('table1', 5, 'col5', 'timestamp with time zone', 'NO'),
                  ('table2', 1, 'col1', 'int4', 'NO'),
                  ('table2', 2, 'col2', 'bool', 'YES'),
                  ('view1', 1, 'col1', 'varchar', 'NO'),
                  ('view1', 2, 'col2', 'unknown', 'NO')]
        cursor.execute(ANY_ARG)
        cursor.fetchall().returns(result)
        cursor.close()

    return cursor
Exemple #5
0
from doublex import Stub

with Stub() as stub:
    stub.example('test').returns(10)

# when
result = stub.example('test')
print(result)

from doublex import Spy


class Sender:
    def send_method(self, address, force=True):
        pass


sender = Spy(Sender)
sender.send_method("*****@*****.**")

try:
    sender.send_method()
except TypeError:
    print("argument error")

from doublex import Mock

with Mock() as mock:
    mock.foo().returns(10)

print(mock.foo())
Exemple #6
0
import rx

from expects import expect, be, contain_exactly, be_a, raise_error
from doublex import Spy, Mock
from doublex_expects import have_been_called

from pysellus import integrations
from pysellus.integrations import on_failure

with description('the integrations module'):
    with context('exposes an `on_failure` decorator which'):
        with before.each:
            integrations.registered_integrations = {}

            with Mock() as some_integration_instance:
                some_integration_instance.get_subject().returns(
                    rx.subjects.Subject())

                integrations.loaded_integrations = {
                    'some_integration': some_integration_instance
                }

        with after.each:
            integrations.registered_integrations = {}
            integrations.loaded_integrations = {}

        with it('returns the decorated function as is'):
            decorated_function = Spy().decorated_function

            expect(on_failure('some_integration')(decorated_function)).to(
                be(decorated_function))
Exemple #7
0
from queue import Queue
from functools import partial

from doublex import Spy, Mock
from expects import expect, be
from doublex_expects import have_been_called

from pysellus import threader

with description('the threader module'):
    with it('should create as many threads as streams in the supplied dict'):
        a_stream = Mock()
        another_stream = Mock()

        a_tester = Spy().a_tester
        another_tester = Spy().another_tester

        stream_to_testers = {
            a_stream: [a_tester],
            another_stream: [a_tester, another_tester]
        }

        threads = threader.build_threads(stream_to_testers)

        expect(len(threads)).to(be(len(stream_to_testers)))

    with it('should initialize threads by calling the given target function'):
        a_stream = Mock()
        a_subject = Spy()
        target_function = Spy().target_function
 def query_resp(self):
     with Mock() as response:
         response.data = 'result'.encode()
         return response
Exemple #9
0
from doublex_expects import have_been_called

from pysellus import registrar
from pysellus.registrar import expect as expect_

with description('the registrar module'):
    with it('should call every function passed to it'):
        function_list = [Spy().a_function, Spy().another_function]
        registrar.register(function_list)

        for function in function_list:
            expect(function).to(have_been_called.once)

    with it('should add a function list to the dictionary of streams to functions'
            ):
        stream = Mock()
        function_list = [Spy().a_function, Spy().another_function]

        expect_(stream)(*function_list)

        for function in function_list:
            expect(function).to_not(have_been_called)

        expect(len(registrar.stream_to_testers[stream])).to(
            equal(len(function_list)))

    with it('should merge multiple function lists if applied to the same stream'
            ):
        stream = Mock()

        first_function_list = [Spy().first_function, Spy().second_function]