def test_multi_tenant(self): main_tenant_client = self.get_client(VALID_TOKEN_MAIN_TENANT) sub_tenant_client = self.get_client(VALID_TOKEN_SUB_TENANT) with self.source(main_tenant_client, self.valid_body) as result: assert_that(result, has_entries(uuid=uuid_(), tenant_uuid=MAIN_TENANT)) with self.source(main_tenant_client, self.valid_body, tenant_uuid=SUB_TENANT) as result: assert_that(result, has_entries(uuid=uuid_(), tenant_uuid=SUB_TENANT)) with self.source(sub_tenant_client, self.valid_body) as result: assert_that(result, has_entries(uuid=uuid_(), tenant_uuid=SUB_TENANT)) assert_that( calling( sub_tenant_client.csv_ws_source.create ).with_args(self.valid_body, tenant_uuid=MAIN_TENANT), raises(Exception).matching(has_properties(response=has_properties(status_code=401))), ) with self.source(main_tenant_client, self.valid_body): assert_that( calling(sub_tenant_client.csv_ws_source.create).with_args(self.valid_body), not_(raises(Exception)), )
def test_mute_participant_with_no_amid(self): calld = self.make_calld() conference_id = CONFERENCE1_ID self.confd.set_conferences( MockConference(id=conference_id, name='conference'), ) self.given_call_in_conference(CONFERENCE1_EXTENSION, caller_id_name='participant1') participants = calld.conferences.list_participants(conference_id) participant = participants['items'][0] with self.amid_stopped(): assert_that( calling(calld.conferences.mute_participant).with_args( conference_id, participant['id']), raises(CalldError).matching( has_properties({ 'status_code': 503, 'error_id': 'xivo-amid-error', }))) assert_that( calling(calld.conferences.unmute_participant).with_args( conference_id, participant['id']), raises(CalldError).matching( has_properties({ 'status_code': 503, 'error_id': 'xivo-amid-error', })))
def test_multi_tenant(self): main_tenant_client = self.get_client(VALID_TOKEN_MAIN_TENANT) sub_tenant_client = self.get_client(VALID_TOKEN_SUB_TENANT) with self.source(main_tenant_client, self.valid_body) as result: assert_that(result, has_entries(uuid=uuid_(), tenant_uuid=MAIN_TENANT)) with self.source(main_tenant_client, self.valid_body, tenant_uuid=SUB_TENANT) as result: assert_that(result, has_entries(uuid=uuid_(), tenant_uuid=SUB_TENANT)) with self.source(sub_tenant_client, self.valid_body) as result: assert_that(result, has_entries(uuid=uuid_(), tenant_uuid=SUB_TENANT)) assert_that( calling(sub_tenant_client.backends.create_source).with_args( 'google', self.valid_body, tenant_uuid=MAIN_TENANT, ), raises(Exception).matching(HTTP_401), ) with self.source(main_tenant_client, self.valid_body): assert_that( calling(sub_tenant_client.backends.create_source).with_args( 'google', self.valid_body, ), not_(raises(Exception)), )
def test_put(self, foobar, other): assert_that( calling(self.edit).with_args(self.client, foobar['uuid'], other), raises(Exception).matching(HTTP_409), ) assert_that( calling(self.edit).with_args(self.client, UNKNOWN_UUID, self.new_body), raises(Exception).matching(HTTP_404), ) assert_that( calling(self.edit).with_args(self.client, foobar['uuid'], {}), raises(Exception).matching(HTTP_400), ) self.edit(self.client, foobar['uuid'], self.new_body) assert_that( self.client.backends.get_source('google', foobar['uuid']), has_entries( uuid=foobar['uuid'], tenant_uuid=foobar['tenant_uuid'], name='new', ))
def test_update(self, user_uuid): new_data = {'foo': 'bar'} assert_that( calling(self._external_auth_dao.update).with_args( self.unknown_uuid, self.auth_type, new_data), raises(exceptions.UnknownUserException).matching( has_properties(status_code=404, resource='users')), ) assert_that( calling(self._external_auth_dao.update).with_args( user_uuid, 'the_unknown_service', new_data), raises(exceptions.UnknownExternalAuthTypeException).matching( has_properties(status_code=404, resource='external')), ) assert_that( calling(self._external_auth_dao.update).with_args( user_uuid, self.auth_type, new_data), raises(exceptions.UnknownExternalAuthException).matching( has_properties(status_code=404, resource=self.auth_type)), ) self._external_auth_dao.create(user_uuid, self.auth_type, self.data) result = self._external_auth_dao.update(user_uuid, self.auth_type, new_data) assert_that(result, equal_to(new_data)) assert_that(self._external_auth_dao.get(user_uuid, self.auth_type), equal_to(new_data))
def test_multi_tenant(self): main_tenant_client = self.get_client(VALID_TOKEN_MAIN_TENANT) sub_tenant_client = self.get_client(VALID_TOKEN_SUB_TENANT) assert_that( calling(self.contacts).with_args(sub_tenant_client, self.source_uuid), raises(Exception).matching(has_properties(response=has_properties(status_code=404))), ) assert_that( calling(self.contacts).with_args( sub_tenant_client, self.source_uuid, tenant_uuid=MAIN_TENANT ), raises(Exception).matching(has_properties(response=has_properties(status_code=401))), ) assert_that( calling(self.contacts).with_args( main_tenant_client, self.source_uuid, tenant_uuid=SUB_TENANT, ), raises(Exception).matching(has_properties(response=has_properties(status_code=404))), )
def test_create(self, user_uuid): assert_that( calling(self._external_auth_dao.create).with_args( self.unknown_uuid, self.auth_type, self.data), raises(exceptions.UnknownUserException).matching( has_properties(status_code=404, resource='users')), ) result = self._external_auth_dao.create(user_uuid, self.auth_type, self.data) assert_that(result, equal_to(self.data)) assert_that(self._external_auth_dao.get(user_uuid, self.auth_type), equal_to(self.data)) assert_that( calling(self._external_auth_dao.create).with_args( user_uuid, self.auth_type, self.data), raises(exceptions.ExternalAuthAlreadyExists).matching( has_properties( status_code=409, resource=self.auth_type, details=has_entries('type', self.auth_type), )), )
def test_address_field(self): params = {'emails': [ONE, SIX]} assert_that( calling(self.user_schema.load).with_args(params), raises( ValidationError, has_property( "messages", has_entries("emails", has_entry(1, has_key('address')))), ), ) params = {'emails': [ONE, TWO, TWO]} assert_that( calling(self.user_schema.load).with_args(params), raises( ValidationError, has_property( "messages", has_entries(_schema=contains( 'The same address can only be used once')), ), ), ) params = {} assert_that( calling(self.user_schema.load).with_args(params), raises(ValidationError, has_property("messages", has_key('emails'))), )
def test_main_field(self): params = {'emails': [ONE, FIVE]} assert_that( calling(self.user_schema.load).with_args(params), raises( ValidationError, has_property( "messages", has_entries( _schema=contains('Only one address should be main')), ), ), ) params = {'emails': [TWO]} assert_that( calling(self.user_schema.load).with_args(params), raises( ValidationError, has_property( "messages", has_entries(_schema=contains( 'At least one address should be main')), ), ), )
def test_user_policy_association(self, user_uuid, policy_uuid): self._user_dao.add_policy(user_uuid, policy_uuid) with self._user_dao.new_session() as s: count = (s.query(func.count(models.UserPolicy.user_uuid)).filter( and_( models.UserPolicy.user_uuid == user_uuid, models.UserPolicy.policy_uuid == policy_uuid, )).scalar()) assert_that(count, equal_to(1)) assert_that( calling(self._user_dao.add_policy).with_args( user_uuid, policy_uuid), not_(raises(Exception)), 'associating twice should not fail', ) assert_that( calling(self._user_dao.add_policy).with_args( 'unknown', policy_uuid), raises(exceptions.UnknownUserException), 'unknown user', ) assert_that( calling(self._user_dao.add_policy).with_args(user_uuid, 'unknown'), raises(exceptions.UnknownPolicyException), 'unknown policy', )
def test_put_multi_tenant(self, sub, main): main_client = self.get_client(VALID_TOKEN_MAIN_TENANT) sub_client = self.get_client(VALID_TOKEN_SUB_TENANT) assert_that( calling(self.edit).with_args(sub_client, main['uuid'], sub), not_(raises(Exception).matching(HTTP_409)), ) assert_that( calling(self.edit).with_args(sub_client, main['uuid'], self.new_body), raises(Exception).matching(HTTP_404), ) assert_that( calling(self.edit).with_args( main_client, main['uuid'], self.new_body, tenant_uuid=SUB_TENANT, ), raises(Exception).matching(HTTP_404), ) assert_that( calling(self.edit).with_args(main_client, sub['uuid'], self.new_body), not_(raises(Exception)), )
def test_delete(self, user_1_uuid, user_2_uuid): assert_that( calling(self._external_auth_dao.delete).with_args(self.unknown_uuid, self.auth_type), raises(exceptions.UnknownUserException).matching( has_properties(status_code=404, resource='users'))) assert_that( calling(self._external_auth_dao.delete).with_args(user_1_uuid, 'the_unknown_service'), raises(exceptions.UnknownExternalAuthTypeException).matching( has_properties(status_code=404, resource='external'))) # This will create the type in the db self._external_auth_dao.create(user_2_uuid, self.auth_type, self.data) assert_that( calling(self._external_auth_dao.delete).with_args(user_1_uuid, self.auth_type), raises(exceptions.UnknownExternalAuthException).matching( has_properties(status_code=404, resource=self.auth_type))) self._external_auth_dao.create(user_1_uuid, self.auth_type, self.data) base.assert_no_error(self._external_auth_dao.delete, user_1_uuid, self.auth_type) assert_that( calling(self._external_auth_dao.delete).with_args(user_1_uuid, self.auth_type), raises(exceptions.UnknownExternalAuthException).matching( has_properties(status_code=404, resource=self.auth_type)))
def test_get_multi_tenant(self, sub, main): main_client = self.get_client(VALID_TOKEN_MAIN_TENANT) sub_client = self.get_client(VALID_TOKEN_SUB_TENANT) response = main_client.conference_source.get(sub['uuid']) assert_that(response, equal_to(sub)) assert_that( calling(main_client.conference_source.get).with_args( main['uuid'], tenant_uuid=SUB_TENANT, ), raises(Exception).matching(HTTP_404), ) assert_that( calling(sub_client.conference_source.get).with_args(main['uuid']), raises(Exception).matching(HTTP_404), ) assert_that( calling(sub_client.conference_source.get).with_args( main['uuid'], tenant_uuid=MAIN_TENANT, ), raises(Exception).matching(HTTP_401), )
def test_get(self, user_1_uuid, user_2_uuid): assert_that( calling(self._external_auth_dao.get).with_args(self.unknown_uuid, self.auth_type), raises(exceptions.UnknownUserException).matching( has_properties(status_code=404, resource='users'))) assert_that( calling(self._external_auth_dao.get).with_args(user_1_uuid, 'the_unknown_service'), raises(exceptions.UnknownExternalAuthTypeException).matching( has_properties(status_code=404, resource='external'))) assert_that( calling(self._external_auth_dao.get).with_args(user_1_uuid, self.auth_type), raises(exceptions.UnknownExternalAuthException).matching( has_properties(status_code=404, resource=self.auth_type))) self._external_auth_dao.create(user_1_uuid, self.auth_type, self.data) result = self._external_auth_dao.get(user_1_uuid, self.auth_type) assert_that(result, equal_to(self.data)) assert_that( calling(self._external_auth_dao.get).with_args(user_2_uuid, self.auth_type), raises(exceptions.UnknownExternalAuthException).matching( has_properties(status_code=404, resource=self.auth_type)))
def test_delete_multi_tenant(self, sub, main): main_client = self.get_client(VALID_TOKEN_MAIN_TENANT) sub_client = self.get_client(VALID_TOKEN_SUB_TENANT) assert_that( calling(sub_client.conference_source.delete).with_args(main['uuid']), raises(Exception).matching(HTTP_404), ) assert_that( calling(sub_client.conference_source.delete).with_args( main['uuid'], tenant_uuid=MAIN_TENANT, ), raises(Exception).matching(HTTP_401), ) assert_that( calling(main_client.conference_source.delete).with_args( main['uuid'], tenant_uuid=SUB_TENANT, ), raises(Exception).matching(HTTP_404), ) assert_that( calling(main_client.conference_source.delete).with_args(sub['uuid']), not_(raises(Exception)), )
def test_record_twice(self): calld = self.make_calld() conference_id = CONFERENCE1_ID self.confd.set_conferences( MockConference(id=conference_id, name='conference'), ) self.given_call_in_conference(CONFERENCE1_EXTENSION, caller_id_name='participant1') # record twice calld.conferences.record(conference_id) assert_that( calling(calld.conferences.record).with_args(conference_id), raises(CalldError).matching( has_properties({ 'status_code': 400, 'error_id': 'conference-already-recorded', }))) # stop record twice calld.conferences.stop_record(conference_id) assert_that( calling(calld.conferences.stop_record).with_args(conference_id), raises(CalldError).matching( has_properties({ 'status_code': 400, 'error_id': 'conference-not-recorded', })))
def test_multi_tenant(self, sub, main): main_tenant_client = self.get_client(VALID_TOKEN_MAIN_TENANT) sub_tenant_client = self.get_client(VALID_TOKEN_SUB_TENANT) response = main_tenant_client.displays.get(sub['uuid']) assert_that(response, equal_to(sub)) assert_that( calling(main_tenant_client.displays.get).with_args( main['uuid'], tenant_uuid=SUB_TENANT), raises(Exception).matching( has_properties(response=has_properties(status_code=404))), ) assert_that( calling(sub_tenant_client.displays.get).with_args(main['uuid']), raises(Exception).matching( has_properties(response=has_properties(status_code=404))), ) assert_that( calling(sub_tenant_client.displays.get).with_args( main['uuid'], tenant_uuid=MAIN_TENANT), raises(Exception).matching( has_properties(response=has_properties(status_code=401))), )
def test_template_association(self, uuid): self._policy_dao.associate_policy_template(uuid, '#') assert_that(self.get_policy(uuid), has_entries(acl_templates=contains_inanyorder('#'))) with self.auto_rollback(): assert_that( calling(self._policy_dao.associate_policy_template).with_args( uuid, '#'), raises(exceptions.DuplicateTemplateException), ) self._policy_dao.dissociate_policy_template(uuid, '#') assert_that(self.get_policy(uuid), has_entries(acl_templates=empty())) with self.auto_rollback(): assert_that( calling(self._policy_dao.associate_policy_template).with_args( 'unknown', '#'), raises(exceptions.UnknownPolicyException), ) assert_that( self._policy_dao.dissociate_policy_template('unknown', '#'), equal_to(0))
def test_mobile_workflow(self, token, user, tenant): self.client.set_tenant(tenant['uuid']) self.client.external.create_config(auth_type=self.EXTERNAL_AUTH_TYPE, data=self.SECRET) response = self.client.external.get_config(self.EXTERNAL_AUTH_TYPE) assert_that(response, has_entries(self.SECRET)) self.client.set_token(token['token']) assert_that( calling(self.client.external.get).with_args( self.EXTERNAL_AUTH_TYPE, user['uuid']), raises(requests.HTTPError).matching( has_property('response', has_properties(status_code=404))), ) response = self.client.external.create( self.EXTERNAL_AUTH_TYPE, user['uuid'], { 'token': 'TOKEN', 'apns_token': 'APNS_VOIP_TOKEN', 'apns_voip_token': 'APNS_VOIP_TOKEN', 'apns_notification_token': 'APNS_NOTIFICATION_TOKEN', }, ) assert_that( response, has_entries( token='TOKEN', apns_token='APNS_VOIP_TOKEN', apns_voip_token='APNS_VOIP_TOKEN', apns_notification_token='APNS_NOTIFICATION_TOKEN', ), ) response = self.client.external.get(self.EXTERNAL_AUTH_TYPE, user['uuid']) assert_that( response, has_entries( token='TOKEN', apns_token='APNS_VOIP_TOKEN', apns_voip_token='APNS_VOIP_TOKEN', apns_notification_token='APNS_NOTIFICATION_TOKEN', ), ) response = self.get_sender_id(user) assert_that(response, has_entry('sender_id', 'fcm_sender_id')) self.client.external.delete(self.EXTERNAL_AUTH_TYPE, user['uuid']) assert_that( calling(self.client.external.get).with_args( self.EXTERNAL_AUTH_TYPE, user['uuid']), raises(requests.HTTPError).matching( has_property('response', has_properties(status_code=404))), )
def test_delete(self, source): assert_that( calling(self.client.backends.delete_source).with_args( 'google', source['uuid']), not_(raises(Exception)), ) assert_that( calling(self.client.backends.get_source).with_args( 'google', source['uuid']), raises(Exception).matching(HTTP_404))
def test_delete(self, uuid): assert_that( calling(self._policy_dao.delete).with_args(uuid, [self.top_tenant_uuid]), not_(raises(Exception)), ) assert_that( calling(self._policy_dao.delete).with_args(base.UNKNOWN_UUID, [self.top_tenant_uuid]), raises(exceptions.UnknownPolicyException), )
def test_delete(self, source): self.client.conference_source.delete(source['uuid']) assert_that( calling(self.client.conference_source.get).with_args(source['uuid']), raises(Exception).matching(HTTP_404) ) assert_that( calling(self.client.conference_source.delete).with_args(UNKNOWN_UUID), raises(Exception).matching(HTTP_404), )
def test_delete(self, display): assert_that( calling(self.client.displays.delete).with_args(display['uuid']), not_(raises(Exception)), ) assert_that( calling(self.client.displays.delete).with_args(display['uuid']), raises(Exception).matching( has_properties(response=has_properties(status_code=404))), )
def test_multi_tenant(self, sub_source, sub_display, main_source, main_display): main_tenant_client = self.get_client(VALID_TOKEN_MAIN_TENANT) sub_tenant_client = self.get_client(VALID_TOKEN_SUB_TENANT) body = { 'name': 'profile', 'display': main_display, 'services': { 'lookup': { 'sources': [main_source] } }, } with self.profile(main_tenant_client, body) as profile: assert_that( calling(sub_tenant_client.profiles.delete).with_args( profile['uuid']), raises(Exception).matching( has_properties(response=has_properties( status_code=404)), ), ) assert_that( calling(sub_tenant_client.profiles.delete).with_args( profile['uuid'], tenant_uuid=MAIN_TENANT), raises(Exception).matching( has_properties(response=has_properties( status_code=401)), ), ) assert_that( calling(main_tenant_client.profiles.delete).with_args( profile['uuid'], tenant_uuid=SUB_TENANT), raises(Exception).matching( has_properties(response=has_properties( status_code=404)), ), ) body = { 'name': 'profile', 'display': sub_display, 'services': { 'lookup': { 'sources': [sub_source] } }, } with self.profile(sub_tenant_client, body) as profile: assert_that( calling(main_tenant_client.profiles.delete).with_args( profile['uuid']), not_(raises(Exception)), )
def test_invalid_field(self): query_string = {'username': 300 * 'a'} assert_that( calling(self.password_query_parameters_schema.load).with_args(query_string), raises(ValidationError, has_property("messages", not_(equal_to(None)))), ) query_string = {'email': 'patate'} assert_that( calling(self.password_query_parameters_schema.load).with_args(query_string), raises(ValidationError, has_property("messages", not_(equal_to(None)))), )
def test_add_get_remove(self): collection = RelocateCollection() relocate = Relocate(self.factory) assert_that(calling(collection.get).with_args(relocate.uuid), raises(KeyError).matching(has_callable('__str__', "'{}'".format(relocate.uuid)))) collection.add(relocate) assert_that(collection.get(relocate.uuid), is_(relocate)) collection.remove(relocate) assert_that(calling(collection.get).with_args(relocate.uuid), raises(KeyError).matching(has_callable('__str__', "'{}'".format(relocate.uuid))))
def test_that_a_refresh_token_requires_a_client_id(self): body = {'refresh_token': 'the-token'} assert_that( calling(self.schema.load).with_args(dict(client_id='x', **body)), not_(raises(Exception)), ) assert_that( calling(self.schema.load).with_args(body), raises(ValidationError).matching( has_properties(field_names=has_item('_schema'))), )
def test_given_wrong_tenant_when_get_then_not_found(self): assert_that( calling(self.client.directories.list_sources).with_args( 'main', tenant_uuid=SUB_TENANT), raises(HTTPError).matching( has_properties(response=has_properties(status_code=404)), ), ) assert_that( calling(self.client.directories.list_sources).with_args( 'sub', tenant_uuid=SUB_TENANT), not_(raises(Exception)), )
def test_subscriptions_manipulate_with_user2(self, subscription_): webhookd = self.make_webhookd(USER_2_TOKEN) response = webhookd.subscriptions.list() assert_that( response, has_entry('items', has_item(has_entry('uuid', subscription_['uuid']))), ) response = webhookd.subscriptions.get(subscription_['uuid']) assert_that(response, has_entry('uuid', subscription_['uuid'])) updated_name = "update 1" updated_subscription = subscription_.copy() updated_subscription["name"] = updated_name del updated_subscription["uuid"] response = webhookd.subscriptions.update( subscription_['uuid'], updated_subscription ) assert_that(response, has_entry('uuid', subscription_['uuid'])) assert_that(response, has_entry('name', updated_name)) webhookd.subscriptions.delete(subscription_['uuid']) self.ensure_webhookd_not_consume_uuid(subscription_['uuid']) response = webhookd.subscriptions.list() assert_that(response, has_entry('items', equal_to([]))) webhookd = self.make_webhookd(USER_1_TOKEN) response = webhookd.subscriptions.create_as_user(subscription_) assert_that(response, has_entry('name', subscription_['name'])) subscription_["uuid"] = response["uuid"] webhookd = self.make_webhookd(USER_2_TOKEN) assert_that( calling(webhookd.subscriptions.get_as_user).with_args( subscription_['uuid'] ), raises(WebhookdError, has_property('status_code', 404)), ) assert_that( calling(webhookd.subscriptions.update_as_user).with_args( subscription_['uuid'], subscription_ ), raises(WebhookdError, has_property('status_code', 404)), ) assert_that( calling(webhookd.subscriptions.delete_as_user).with_args( subscription_['uuid'] ), raises(WebhookdError, has_property('status_code', 404)), )
def test_get_credential(self, *ignored_uuids): assert_that( calling(self._user_dao.get_credentials).with_args('not-foobar'), raises(exceptions.UnknownUsernameException), ) assert_that( calling(self._user_dao.get_credentials).with_args('foobaz'), raises(exceptions.UnknownUsernameException), ) hash_, salt = self._user_dao.get_credentials('foobar') assert_that(hash_, not_(none())) assert_that(salt, not_(none()))