Beispiel #1
0
    def test_find_all_by(self):
        line1 = self.add_line(device='deviceid', provisioningid=123456)
        line2 = self.add_line(device='deviceid', provisioningid=234567)
        result = line_dao.find_all_by(device='deviceid')

        assert_that(result, has_items(has_property('id', line1.id),
                                      has_property('id', line2.id)))
Beispiel #2
0
    def test_associate_secondary_user_with_line(self):
        main_user = self.add_user()
        secondary_user = self.add_user()
        line = self.add_line()

        self.add_user_line(user_id=main_user.id,
                           line_id=line.id,
                           extension_id=None,
                           main_user=True,
                           main_line=True)

        user_line_dao.associate(secondary_user, line)

        result = (self.session.query(UserLine)
                  .filter(UserLine.line_id == line.id)
                  .all())

        assert_that(result, contains_inanyorder(
            all_of(has_property('user_id', main_user.id),
                   has_property('line_id', line.id),
                   has_property('extension_id', None),
                   has_property('main_user', True),
                   has_property('main_line', True)),
            all_of(has_property('user_id', secondary_user.id),
                   has_property('line_id', line.id),
                   has_property('extension_id', None),
                   has_property('main_user', False),
                   has_property('main_line', True))))
    def test_it_should_sort_by_field(self):
        result = self.filter(sort('id'), (AVAILABLE_STATION, FIRST_STATION))

        assert_that(result, contains(
            has_property('idestacion', FIRST_STATION['idestacion']),
            has_property('idestacion', AVAILABLE_STATION['idestacion'])
        ))
    def test_aq_property(self):

        class IBaz(Interface):
            pass

        class IFoo(Interface):
            ob = Object(IBaz)

        @implementer(IBaz)
        class Baz(object):
            pass

        class BazAQ(Implicit, Baz):
            pass

        @implementer(IFoo)
        class Foo(Base):
            ob = AcquisitionFieldProperty(IFoo['ob'])

        assert_that(Foo, has_property('ob', is_(AcquisitionFieldProperty)))

        # pylint:disable=blacklisted-name
        foo = Foo()
        assert_that(foo, has_property('ob', none()))

        foo.ob = Baz()
        assert_that(foo, has_property('ob', is_not(aq_inContextOf(foo))))

        foo.ob = BazAQ()
        assert_that(foo, has_property('ob', aq_inContextOf(foo)))
 def test_bulk_with_report(self):
     results = self.store.bulk(
         actions=[
             ("index", self.kevin),
             ("delete", self.steph),
         ],
         batch_size=2,
     )
     assert_that(
         self.store.retrieve(self.kevin.id),
         all_of(
             has_property("id", self.kevin.id),
             has_property("first", "Kevin"),
             has_property("middle", none()),
             has_property("last", "Durant"),
         ),
     )
     result = results[0]
     # Updated items
     assert_that(result[0], is_(equal_to(1)))
     # Report on failed to delete items
     assert_that(result[1], contains(
         has_key('delete'),
     ))
     assert_that(result[1][0]['delete'], has_entry('result', 'not_found'))
Beispiel #6
0
    def test_unmarshal(self):
        event = ConcreteUserCtiProfileConfigEvent.unmarshal(self.msg)

        assert_that(event, all_of(
            has_property('user_id', USER_ID),
            has_property('cti_profile_id', CTI_PROFILE_ID),
            has_property('enabled', True)))
Beispiel #7
0
    def test_unmarshal(self):
        event = ConcreteUserVoicemailConfigEvent.unmarshal(self.msg)

        assert_that(event, all_of(
            has_property('user_id', USER_ID),
            has_property('voicemail_id', VOICEMAIL_ID),
            has_property('enabled', ENABLED)))
Beispiel #8
0
    def testProxyHostComps(self):
        pers_comps = BaseComponents(BASE, 'persistent', (BASE,))
        host_comps = BaseComponents(BASE, 'example.com', (BASE,))
        host_sm = HSM('example.com', 'siteman', host_comps, pers_comps)
        host_site = MockSite(host_sm)
        host_site.__name__ = host_sm.__name__
        setSite(host_site)

        new_comps = BaseComponents(BASE, 'sub_site', (pers_comps,))
        new_site = MockSite(new_comps)
        new_site.__name__ = new_comps.__name__
        interface.alsoProvides(new_site, IFoo)

        threadSiteSubscriber(new_site, None)

        cur_site = getSite()
        # It should implement the static and dynamic
        # ifaces
        assert_that(cur_site, validly_provides(IFoo))
        assert_that(cur_site, validly_provides(IMock))

        # It should have the marker property
        assert_that(cur_site.getSiteManager(),
                    has_property('host_components',
                                   host_comps))

        assert_that(ro.ro(cur_site.getSiteManager()),
                    contains(
                         # The first entry is synthesized
                         has_property('__name__', new_comps.__name__),
                         pers_comps,
                         # The host comps appear after all the bases
                         # in the ro of the new site
                         host_comps,
                         BASE))
Beispiel #9
0
    def test_find_last_unprocessed_under_limit(self):
        limit = 10
        cel_id_1, cel_id_2 = self.add_cel(linkedid='1'), self.add_cel(linkedid='2')

        result = cel_dao.find_last_unprocessed(limit)

        assert_that(result, contains(has_property('id', cel_id_1),
                                     has_property('id', cel_id_2)))
Beispiel #10
0
    def test_find_from_linked_id(self):
        linked_id = '666'
        cel_id_1, cel_id_2, cel_id_3 = self.add_cel(linkedid='666'), self.add_cel(linkedid='3'), self.add_cel(linkedid='666')

        result = cel_dao.find_from_linked_id(linked_id)

        assert_that(result, contains_inanyorder(has_property('id', cel_id_1),
                                                has_property('id', cel_id_3)))
Beispiel #11
0
def has_error(message='', trace='', status=Status.FAILED):
    return has_property('{}test-cases',
                        has_property('test-case',
                                     all_of(has_property('attrib', has_entry('status', status)),
                                            has_property('failure',
                                                         has_properties({'message': message,
                                                                         'stack-trace': has_string(trace)
                                                                         })))))
Beispiel #12
0
    def test_find_last_unprocessed_under_limit_exceeding_limit_to_complete_call(self):
        limit = 1
        cel_id_1, cel_id_2 = self.add_cel(linkedid='1'), self.add_cel(linkedid='1')

        result = cel_dao.find_last_unprocessed(limit)

        assert_that(result, contains(has_property('id', cel_id_1),
                                     has_property('id', cel_id_2)))
Beispiel #13
0
    def test_get_by_extension_id_with_line(self):
        user_line_row = self.add_user_line_with_exten()

        line_extension = dao.get_by_extension_id(user_line_row.extension_id)

        assert_that(line_extension, all_of(
            has_property('line_id', user_line_row.line_id),
            has_property('extension_id', user_line_row.extension_id)))
Beispiel #14
0
    def test_find(self):
        extension_row = self.add_extension(exten='1234', context='default')

        result = extension_dao.find(extension_row.id)

        assert_that(result, all_of(
            has_property('exten', extension_row.exten),
            has_property('context', extension_row.context)))
Beispiel #15
0
def has_error(message='', trace=''):
    return has_property('{}test-cases',
                        has_property('test-case',
                                     has_property('failure',
                                                  has_properties({
                                                                  'message': message,
                                                                  'stack-trace': has_string(trace)
                                                                  }))))
Beispiel #16
0
def has_failure(test_name, message=anything()):
    return has_property('{}test-cases',
                        has_property('test-case',
                                     has_item(
                                         has_properties({'name': equal_to(test_name),
                                                         'failure': any_of(
                                                             has_property('stack-trace', equal_to(message)),
                                                             has_property('message', equal_to(message)))}))))
Beispiel #17
0
    def test_instance_of_new_class(self):
        value1 = 'value1'
        value2 = 'value2'
        model = StubModel(field1=value1, field2=value2)

        assert_that(model, all_of(
            has_property('field1', value1),
            has_property('field2', value2)
        ))
Beispiel #18
0
    def assert_result(self, *matchers, **kwargs):
        result = kwargs.get(u'result', self.result)

        assert_that(result, all_of(
            has_property(u'exit_code', kwargs.pop(u'exit_code', 0)),
            has_property(u'output', kwargs.pop(u'output', anything())),
            has_properties(**kwargs),
            *matchers
        ))
Beispiel #19
0
    def test_it_should_search_stations_by_name(self):
        query = 'callEaVapiés'
        stations = list(self.stations.by_search(query))

        assert_that(stations, only_contains(any_of(
            has_property('nombre', contains_string('Lavapies')),
            has_property('address', contains_string('Lavapies')),
        )))
        assert_that(stations, has_length(greater_than(0)))
Beispiel #20
0
def test_collection_error(report_for):
    report = report_for(test_broken_module="""
    def test(
    """)

    assert_that(report, all_of(
        has_property('{}test-cases', has_property('test-case', contains(
            has_property('{}name', 'test_broken_module')))),
        has_property('{}title', 'Collection phase')))
Beispiel #21
0
    def test_get_by_user_id_with_voicemail(self):
        user_row, voicemail_row = self.create_user_and_voicemail(firstname='King', exten='1000', context='default')

        result = user_voicemail_dao.get_by_user_id(user_row.id)

        assert_that(result, instance_of(UserVoicemail))
        assert_that(result,
                    has_property('user_id', user_row.id),
                    has_property('voicemail_id', voicemail_row.uniqueid))
Beispiel #22
0
    def test_get_by_extension_id_with_multiple_users(self):
        main_ule = self.add_user_line_with_exten()
        secondary_ule = self.prepare_secondary_user_associated(main_ule)

        line_extension = dao.get_by_extension_id(secondary_ule.extension_id)

        assert_that(line_extension, all_of(
            has_property('line_id', main_ule.line_id),
            has_property('extension_id', main_ule.extension_id)))
Beispiel #23
0
def has_label(test_name, label_name=anything(), label_value=anything()):
    return has_property('{}test-cases',
                        has_property('test-case',
                                     has_item(
                                         has_properties({'name': equal_to(test_name),
                                                         'labels': has_property('label',
                                                                                has_item(
                                                                                    has_property('attrib', equal_to(
                                                                                        {'name': label_name,
                                                                                         'value': label_value}))))}))))
Beispiel #24
0
    def test_find_all_one_user_commented(self):
        firstname = 'Pascal'
        user = self.add_user(firstname=firstname, commented=1)

        users = user_dao.find_all()
        assert_that(users, has_length(1))

        user_found = users[0]
        assert_that(user_found, has_property('id', user.id))
        assert_that(user_found, has_property('firstname', firstname))
Beispiel #25
0
    def test_find_all_by_user_id(self):
        user_line = self.add_user_line_without_exten()

        result = user_line_dao.find_all_by_user_id(user_line.user_id)

        assert_that(result, has_items(
            all_of(
                has_property('user_id', user_line.user_id),
                has_property('line_id', user_line.line_id))
        ))
Beispiel #26
0
    def test_it_should_calculate_0_as_distance_to_same_point(self):
        """Check it actually computes distances"""
        position = AVAILABLE_STATION['latitud'], AVAILABLE_STATION['longitud']
        result = self.filter(distance(position),
                             (AVAILABLE_STATION, NO_BIKES_STATION))

        assert_that(result, contains(
            has_property('distance', 0.0),
            has_property('distance', all_of(greater_than(1401), less_than(1402)))
        ))
Beispiel #27
0
    def test_find_last_unprocessed_with_processed_and_unprocessed(self):
        limit = 10
        self._add_processed_cel(linkedid='1')
        self._add_processed_cel(linkedid='1')
        cel_id_3, cel_id_4 = self.add_cel(linkedid='2'), self.add_cel(linkedid='2')

        result = cel_dao.find_last_unprocessed(limit)

        assert_that(result, contains(has_property('id', cel_id_3),
                                     has_property('id', cel_id_4)))
Beispiel #28
0
    def test_find_last_unprocessed_under_limit_exceeding_limit_to_reprocess_partially_processed_call(self):
        limit = 2
        cel_id_1, cel_id_2 = self._add_processed_cel(linkedid='1'), self.add_cel(linkedid='1')
        cel_id_3, cel_id_4 = self._add_processed_cel(linkedid='2'), self.add_cel(linkedid='2')

        result = cel_dao.find_last_unprocessed(limit)

        assert_that(result, contains(has_property('id', cel_id_1),
                                     has_property('id', cel_id_2),
                                     has_property('id', cel_id_3),
                                     has_property('id', cel_id_4)))
Beispiel #29
0
    def test_find_by_voicemail_id_when_voicemail_associated_to_user(self):
        user_row, voicemail_row = self.create_user_and_voicemail(firstname='Dolly',
                                                                 exten='1000',
                                                                 context='default')

        result = user_voicemail_dao.find_by_voicemail_id(voicemail_row.uniqueid)

        assert_that(result, instance_of(UserVoicemail))
        assert_that(result,
                    has_property('user_id', user_row.id),
                    has_property('voicemail_id', voicemail_row.uniqueid))
Beispiel #30
0
    def test_update_from_data_with_only_one_changes(self):
        data = {
            'field1': 'new_value1',
        }
        model = StubModel(field1='value1', field2='value2')

        model.update_from_data(data)

        assert_that(model, all_of(
            has_property('field1', 'new_value1'),
            has_property('field2', 'value2')))
Beispiel #31
0
def _assert_that_raises_http_error(status_code, fn, *args, **kwargs):
    assert_that(
        calling(fn).with_args(*args, **kwargs),
        raises(requests.HTTPError).matching(
            has_property('response', has_properties('status_code', status_code))
        ),
    )
def ExtraConfStore_ModuleForSourceFile_NoConfirmation_test( app ):
  filename = PathToTestFile( 'extra_conf', 'project', 'some_file' )
  module = extra_conf_store.ModuleForSourceFile( filename )
  assert_that( inspect.ismodule( module ) )
  assert_that( inspect.getfile( module ), equal_to( PROJECT_EXTRA_CONF ) )
  assert_that( module, has_property( 'is_global_ycm_extra_conf' ) )
  assert_that( module.is_global_ycm_extra_conf, equal_to( False ) )
def ExtraConfStore_ModuleForSourceFile_GlobalExtraConf_WinEnvVar_test( app ):
  filename = PathToTestFile( 'extra_conf', 'some_file' )
  module = extra_conf_store.ModuleForSourceFile( filename )
  assert_that( inspect.ismodule( module ) )
  assert_that( inspect.getfile( module ), equal_to( GLOBAL_EXTRA_CONF ) )
  assert_that( module, has_property( 'is_global_ycm_extra_conf' ) )
  assert_that( module.is_global_ycm_extra_conf, equal_to( True ) )
 def testBackfillCommands(self, mock_add):
   command_1, command_2, command_3 = command_manager.CreateCommands(
       request_id=self.request.key.id(),
       command_infos=[
           datastore_entities.CommandInfo(
               command_line='long command line',
               shard_count=3,
               run_target='foo',
               run_count=1,
               cluster='foobar'),
           datastore_entities.CommandInfo(
               command_line='longer_command_line',
               shard_count=3,
               run_target='foo',
               run_count=1,
               cluster='foobar'),
           datastore_entities.CommandInfo(
               command_line='short_cmd',
               shard_count=3,
               run_target='foo',
               run_count=1,
               cluster='foobar'),
       ],
       shard_indexes=list(range(3)),
       request_plugin_data={
           'ants_invocation_id': 'i123',
           'ants_work_unit_id': 'w123'
       })
   command_1.state = common.CommandState.QUEUED
   command_1.put()
   command_2.state = common.CommandState.QUEUED
   command_2.put()
   command_3.state = common.CommandState.RUNNING
   command_3.put()
   response = self.testapp.post_json(
       '/_ah/api/CoordinatorApi.BackfillCommands', {})
   self.assertEqual('200 OK', response.status)
   mock_add.assert_has_calls(
       [
           mock.call(
               hamcrest.match_equality(
                   hamcrest.has_property('key', command_1.key))),
           mock.call(
               hamcrest.match_equality(
                   hamcrest.has_property('key', command_2.key))),
       ], any_order=True)
   self.assertEqual(2, mock_add.call_count)
Beispiel #35
0
def has_only_n_test_cases(name, num, *matchers):
    return has_property(
        'test_cases',
        ContainsExactly(
            num,
            all_of(
                any_of(has_entry('fullName', ends_with(name)),
                       has_entry('name', ends_with(name))), *matchers)))
Beispiel #36
0
def test_signals_when_user_signs_in(listener):
    session = make_anonymous_session()

    listener.should_receive("user_signed_in").with_args(
            matching(has_property("email", equal_to("*****@*****.**")))).once()
    session.user_signed_in.subscribe(listener.user_signed_in)

    session.login_as("*****@*****.**", "api-key", ())
Beispiel #37
0
def test_attribute_access():
    """
    Configuration can be accessed by attribute and key.

    """
    config = Configuration(
        key="value",
        nested=dict(
            nested_key="nested_value",
            other_key=range(10),
        )
    )
    assert_that(config, has_entry("key", "value"))
    assert_that(config, has_property("key", "value"))
    assert_that(config["nested"], is_(instance_of(Configuration)))
    assert_that(config["nested"], has_entry("nested_key", "nested_value"))
    assert_that(config.nested, has_property("nested_key", "nested_value"))
 def test_when_delete_then_raises(self):
     assert_that(
         calling(self.client.backends.delete_source).with_args(
             backend=self.BACKEND,
             source_uuid='a-non-existing-source-uuid',
         ),
         raises(requests.HTTPError).matching(
             has_property('response', has_properties('status_code', 404))))
Beispiel #39
0
    def test_find_factories_sets_name(self):
        class AP(AutoPackage):
            @classmethod
            def _ap_enumerate_module_names(cls):
                return ()

        reg = AP._ap_find_factories('nti.externalization.tests')
        assert_that(reg, has_property('__name__', 'nti.externalization.tests'))
Beispiel #40
0
    def test_load_end_before_start_different_length(self):
        context_range = dict(start='02', end='001')

        assert_that(
            calling(self.schema.load).with_args(context_range),
            raises(ValidationError, has_property('messages',
                                                 has_key('_schema'))),
        )
Beispiel #41
0
    def test_update_persistent_object(self):
        from persistent import Persistent
        external = {}

        class Obj(Persistent):
            updated = False

            def updateFromExternalObject(self, ext):
                self.updated = True

        contained = Obj()
        self._callFUT(contained, external)
        assert_that(contained, has_property('updated', True))
        assert_that(
            contained,
            has_property('_v_updated_from_external_source',
                         is_(same_instance(external))))
Beispiel #42
0
    def test_it_should_find_by_field(self):
        """Should return a station with given spec"""
        result = self.filter(find('id', int(AVAILABLE_STATION['idestacion'])),
                             (AVAILABLE_STATION, NO_BIKES_STATION))

        assert_that(
            result,
            is_(has_property('idestacion', AVAILABLE_STATION['idestacion'])))
Beispiel #43
0
    def test_delegate_properties(self):
        class Base(object):
            b = 1

        base = Base()
        mon = ActivityMonitor(base)

        assert_that(mon, has_property('b', 1))
    def test_scan_no_name(self):
        class O(object):
            __external_can_create__ = True

        self._addFactory(O)
        xmlconfig.string(self.SCAN_THIS_MODULE.replace('PLACEHOLDER', ''))
        factory = component.getUtility(IClassObjectFactory, 'O')
        assert_that(factory, has_property('_callable', equal_to(O)))
Beispiel #45
0
    def test_validate_auth_username(self):
        body = {'auth_username': '******', 'remote_host': 'remote_host'}

        assert_that(
            calling(self.schema.load).with_args(body),
            raises(ValidationError,
                   has_property('messages', has_key('auth_username'))),
        )
Beispiel #46
0
    def test_given_non_user_subscription_when_user_delete_http_subscription_then_404(self, subscription_):
        token = 'my-token'
        auth = self.make_auth()
        auth.set_token(MockUserToken(token, USER_1_UUID))
        webhookd = self.make_webhookd(token)

        assert_that(calling(webhookd.subscriptions.delete_as_user).with_args(subscription_['uuid']),
                    raises(WebhookdError, has_property('status_code', 404)))
Beispiel #47
0
 def test_given_microsoft_when_fetch_all_contacts_with_error_endpoint(
         self, office365_api):
     assert_that(
         calling(self.client.backends.list_contacts_from_source).with_args(
             backend=self.BACKEND, source_uuid=self.source['uuid']),
         raises(requests.HTTPError).matching(
             has_property('response', has_properties('status_code', 503))),
     )
    def test_search_paging(self):
        with self.store.flushing():
            self.store.create(self.kevin)
            with patch.object(self.store, "new_timestamp") as mocked:
                # ensure we have >= 1s created at delta
                mocked.return_value = self.kevin.created_at + timedelta(
                    seconds=1).seconds * 1000
                self.store.create(self.steph)

        assert_that(
            self.store.search(offset=1, limit=1),
            contains(has_property("id", self.kevin.id), ),
        )
        assert_that(
            self.store.search(offset=0, limit=1),
            contains(has_property("id", self.steph.id), ),
        )
Beispiel #49
0
    def test_update_mapping_with_kwargs_context(self):
        class ContainedObject(object):
            updated = False
            args = None
            context = None

            def updateFromExternalObject(self, ext, context=None, **kwargs):
                self.updated = True
                self.args = kwargs
                self.context = context
                return True

        contained = ContainedObject()
        self._callFUT(contained, {}, context=42)
        assert_that(contained, has_property('updated', True))
        assert_that(contained, has_property('args', {}))
        assert_that(contained, has_property('context', 42))
    def test_interpret_chan_start(self):
        line_identity = 'sip/asldfj'
        cel = Mock(channame=line_identity + '-0000001')
        call = Mock(RawCallLog)

        result = self.callee_cel_interpretor.interpret_chan_start(cel, call)

        assert_that(result, has_property('destination_line_identity', line_identity))
Beispiel #51
0
def test_smoke_simple(report_for, statement):
    report = report_for("""
    import pytest
    def test():
        %s
    """ % statement)

    assert_that(report.findall('.//test-case'), contains(has_property('name')))
Beispiel #52
0
    def test_it_should_filter_stations_with_no_spaces(self):
        result = self.filter(with_spaces,
                             (AVAILABLE_STATION, NO_SPACES_STATION))

        assert_that(
            result,
            only_contains(
                has_property('idestacion', AVAILABLE_STATION['idestacion'])))
Beispiel #53
0
def test_smoke_decorated_success(report_for, test):
    report = report_for("""
    import pytest
    %s:
        assert 0
    """ % test)

    assert_that(report.findall('.//test-case'), contains(has_property('name')))
Beispiel #54
0
    def test_shouldRemoveTheHookingWhenWorkflowObjectIsDeleted(self):
        workflow_object = BasicTestModelObjectFactory().model

        hooking_hash = '%s.%s_object%s_field_name%s' % (PostTransitionHooking.__module__, PostTransitionHooking.__name__, workflow_object.pk, self.field_name)

        assert_that(self.handler_backend.callbacks, is_not(has_key(hooking_hash)))
        assert_that(self.handler_backend.callbacks, is_not(has_value(has_property("__name__", test_callback.__name__))))

        self.handler_backend.register(PostTransitionHooking, test_callback, workflow_object, self.field_name)

        assert_that(self.handler_backend.callbacks, has_key(hooking_hash))
        assert_that(self.handler_backend.callbacks, has_value(has_property("__name__", test_callback.__name__)))

        workflow_object.delete()

        assert_that(self.handler_backend.callbacks, is_not(has_key(hooking_hash)))
        assert_that(self.handler_backend.callbacks, is_not(has_value(has_property("__name__", test_callback.__name__))))
Beispiel #55
0
    def test_shouldReturnTheRegisteredHooking(self):
        workflow_object = BasicTestModelObjectFactory().model

        self.handler_backend.register(PostTransitionHooking, test_callback, workflow_object, self.field_name)
        callbacks = self.handler_backend.get_callbacks(PostTransitionHooking, workflow_object, self.field_name)

        assert_that(callbacks, has_length(1))
        assert_that(callbacks, has_item(has_property("__name__", test_callback.__name__)))