How to use delete_trust method in tempest

Best Python code snippet using tempest_python

test_trust.py

Source:test_trust.py Github

copy

Full Screen

...152 unaffiliated153 """154 pass155 @abc.abstractmethod156 def test_identity_delete_trust(self):157 """Test identity:delete_trust policy.158 This test must check159 * whether the persona can delete a trust for which they are the160 trustor161 * whether the persona can delete a trust for which they are the162 trustee163 * whether the persona can delete a trust which which they are164 unaffiliated165 """166 pass167class SystemAdminTests(IdentityV3RbacTrustTest, base.BaseIdentityTest):168 credentials = ['system_admin']169 def test_identity_create_trust(self):170 # user cannot create trust for themself171 self.do_request('create_trust',172 expected_status=exceptions.Forbidden,173 **self.trust(trustor=self.persona.credentials.user_id))174 # user cannot create trust for another user175 self.do_request('create_trust',176 expected_status=exceptions.Forbidden,177 **self.trust())178 def test_identity_get_trust(self):179 # user cannot have their own trust180 # user can get trust for other user181 trust_id = self.user_trust_client.create_trust(182 **self.trust())['trust']['id']183 self.addCleanup(self.admin_trusts_client.delete_trust,184 trust_id=trust_id)185 self.do_request('show_trust', trust_id=trust_id)186 def test_identity_list_trusts(self):187 trust_id = self.user_trust_client.create_trust(188 **self.trust())['trust']['id']189 self.addCleanup(self.admin_trusts_client.delete_trust,190 trust_id=trust_id)191 resp = self.do_request('list_trusts')192 self.assertIn(trust_id, [t['id'] for t in resp['trusts']])193 def test_identity_list_trusts_for_trustor(self):194 # user cannot have their own trust195 # user can list trusts for other user196 trust_id = self.user_trust_client.create_trust(197 **self.trust())['trust']['id']198 self.addCleanup(self.admin_trusts_client.delete_trust,199 trust_id=trust_id)200 self.do_request('list_trusts', trustor_user_id=self.trustor)201 def test_identity_list_trusts_for_trustee(self):202 # user cannot have their own trust203 # user can list trusts for other user204 trust_id = self.user_trust_client.create_trust(205 **self.trust())['trust']['id']206 self.addCleanup(self.admin_trusts_client.delete_trust,207 trust_id=trust_id)208 self.do_request('list_trusts', trustee_user_id=self.trustee)209 def test_identity_list_roles_for_trust(self):210 # user cannot have their own trust211 # user can list roles of trust for other user212 trust_id = self.user_trust_client.create_trust(213 **self.trust())['trust']['id']214 self.addCleanup(self.admin_trusts_client.delete_trust,215 trust_id=trust_id)216 resp = self.do_request('list_trust_roles', trust_id=trust_id)217 self.assertIn(self.roles[0]['id'], [r['id'] for r in resp['roles']])218 def test_identity_get_role_for_trust(self):219 # user cannot have their own trust220 # user can get role of trust for other user221 trust_id = self.user_trust_client.create_trust(222 **self.trust())['trust']['id']223 self.addCleanup(self.admin_trusts_client.delete_trust,224 trust_id=trust_id)225 self.do_request('show_trust_role',226 trust_id=trust_id, role_id=self.roles[0]['id'])227 def test_identity_delete_trust(self):228 # user cannot have their own trust229 # user can delete a user's trust230 trust_id = self.user_trust_client.create_trust(231 **self.trust())['trust']['id']232 self.do_request('delete_trust', expected_status=204, trust_id=trust_id)233class SystemMemberTests(SystemAdminTests):234 credentials = ['system_member', 'system_admin']235 def test_identity_delete_trust(self):236 # system user cannot have their own trust237 # user cannot delete another user's trust238 trust_id = self.user_trust_client.create_trust(239 **self.trust())['trust']['id']240 self.addCleanup(self.admin_trusts_client.delete_trust,241 trust_id=trust_id)242 self.do_request('delete_trust', expected_status=exceptions.Forbidden,243 trust_id=trust_id)244class SystemReaderTests(SystemMemberTests):245 credentials = ['system_reader', 'system_admin']246class DomainAdminTests(SystemReaderTests, base.BaseIdentityTest):247 # Domain admins cannot create their own trusts (trusts can only be248 # scoped to projects) and domain admins have no special privileges over the249 # trusts own by users in their domains.250 credentials = ['domain_admin', 'system_admin']251 def test_identity_get_trust(self):252 # user cannot have their own trust253 # user can get trust for other user254 trust_id = self.user_trust_client.create_trust(255 **self.trust())['trust']['id']256 self.addCleanup(self.admin_trusts_client.delete_trust,257 trust_id=trust_id)258 self.do_request('show_trust', expected_status=exceptions.Forbidden,259 trust_id=trust_id)260 def test_identity_list_trusts(self):261 trust_id = self.user_trust_client.create_trust(262 **self.trust())['trust']['id']263 self.addCleanup(self.admin_trusts_client.delete_trust,264 trust_id=trust_id)265 self.do_request('list_trusts',266 expected_status=exceptions.Forbidden)267 def test_identity_list_trusts_for_trustor(self):268 # user cannot have their own trust269 # user can list trusts for other user270 trust_id = self.user_trust_client.create_trust(271 **self.trust())['trust']['id']272 self.addCleanup(self.admin_trusts_client.delete_trust,273 trust_id=trust_id)274 self.do_request('list_trusts', expected_status=exceptions.Forbidden,275 trustor_user_id=self.trustor)276 def test_identity_list_trusts_for_trustee(self):277 # user cannot have their own trust278 # user can list trusts for other user279 trust_id = self.user_trust_client.create_trust(280 **self.trust())['trust']['id']281 self.addCleanup(self.admin_trusts_client.delete_trust,282 trust_id=trust_id)283 self.do_request('list_trusts', expected_status=exceptions.Forbidden,284 trustee_user_id=self.trustee)285 def test_identity_list_roles_for_trust(self):286 # user cannot have their own trust287 # user can list roles of trust for other user288 trust_id = self.user_trust_client.create_trust(289 **self.trust())['trust']['id']290 self.addCleanup(self.admin_trusts_client.delete_trust,291 trust_id=trust_id)292 self.do_request('list_trust_roles',293 expected_status=exceptions.Forbidden,294 trust_id=trust_id)295 def test_identity_get_role_for_trust(self):296 # user cannot have their own trust297 # user can get role of trust for other user298 trust_id = self.user_trust_client.create_trust(299 **self.trust())['trust']['id']300 self.addCleanup(self.admin_trusts_client.delete_trust,301 trust_id=trust_id)302 self.do_request('show_trust_role',303 expected_status=exceptions.Forbidden,304 trust_id=trust_id, role_id=self.roles[0]['id'])305class DomainMemberTests(DomainAdminTests):306 credentials = ['domain_member', 'system_admin']307class DomainReaderTests(DomainAdminTests):308 credentials = ['domain_reader', 'system_admin']309class ProjectAdminTests(IdentityV3RbacTrustTest, base.BaseIdentityTest):310 credentials = ['project_admin', 'system_admin']311 def setUp(self):312 super(ProjectAdminTests, self).setUp()313 self.role_id = self.admin_role_id314 def test_identity_create_trust(self):315 # user can create a trust for their own project316 trustor_user_id = self.persona.credentials.user_id317 project_id = self.persona.credentials.project_id318 resp = self.do_request(319 'create_trust',320 expected_status=201,321 **self.trust(322 trustor=trustor_user_id,323 project_id=project_id,324 roles=[{'id': self.role_id}])325 )['trust']326 self.addCleanup(self.client.delete_trust, resp['id'])327 # user cannot create trust with another user as trustor328 self.do_request(329 'create_trust',330 expected_status=exceptions.Forbidden,331 **self.trust())332 def test_identity_get_trust(self):333 # user can get a trust for which they are trustor334 trustor_user_id = self.persona.credentials.user_id335 project_id = self.persona.credentials.project_id336 trust_id = self.client.create_trust(337 **self.trust(trustor=trustor_user_id,338 project_id=project_id,339 roles=[{'id': self.role_id}]))['trust']['id']340 self.addCleanup(self.client.delete_trust, trust_id=trust_id)341 self.do_request('show_trust', trust_id=trust_id)342 # user can get a trust for which they are trustee343 trustee_user_id = self.persona.credentials.user_id344 trust_id = self.user_trust_client.create_trust(345 **self.trust(trustee=trustee_user_id))['trust']['id']346 self.addCleanup(self.user_trust_client.delete_trust, trust_id=trust_id)347 self.do_request('show_trust', trust_id=trust_id)348 # user cannot get a trust with which they are unaffiliated349 trust_id = self.user_trust_client.create_trust(350 **self.trust())['trust']['id']351 self.addCleanup(self.user_trust_client.delete_trust, trust_id=trust_id)352 self.do_request('show_trust', expected_status=exceptions.Forbidden,353 trust_id=trust_id)354 def test_identity_list_trusts(self):355 trust_id = self.user_trust_client.create_trust(356 **self.trust())['trust']['id']357 self.addCleanup(self.admin_trusts_client.delete_trust,358 trust_id=trust_id)359 self.do_request('list_trusts',360 expected_status=exceptions.Forbidden)361 def test_identity_list_trusts_for_trustor(self):362 # user can list their own trusts363 trustor_user_id = self.persona.credentials.user_id364 project_id = self.persona.credentials.project_id365 trust_id = self.client.create_trust(366 **self.trust(trustor=trustor_user_id,367 project_id=project_id,368 roles=[{'id': self.role_id}]))['trust']['id']369 self.addCleanup(self.client.delete_trust, trust_id=trust_id)370 self.do_request('list_trusts', trustor_user_id=trustor_user_id)371 # user cannot list another user's trusts372 trust_id = self.user_trust_client.create_trust(373 **self.trust())['trust']['id']374 self.addCleanup(self.user_trust_client.delete_trust, trust_id=trust_id)375 self.do_request('list_trusts', expected_status=exceptions.Forbidden,376 trustor_user_id=self.trustor)377 def test_identity_list_trusts_for_trustee(self):378 # user can list their own trusts379 trustee_user_id = self.persona.credentials.user_id380 trust_id = self.user_trust_client.create_trust(381 **self.trust(trustee=trustee_user_id))['trust']['id']382 self.addCleanup(self.user_trust_client.delete_trust, trust_id=trust_id)383 self.do_request('list_trusts', trustee_user_id=trustee_user_id)384 # user cannot list another user's trusts385 trust_id = self.user_trust_client.create_trust(386 **self.trust())['trust']['id']387 self.addCleanup(self.user_trust_client.delete_trust, trust_id=trust_id)388 self.do_request('list_trusts', expected_status=exceptions.Forbidden,389 trustee_user_id=self.trustee)390 def test_identity_list_roles_for_trust(self):391 # user can list roles for trust for which they are trustor392 trustor_user_id = self.persona.credentials.user_id393 project_id = self.persona.credentials.project_id394 trust_id = self.client.create_trust(395 **self.trust(trustor=trustor_user_id,396 project_id=project_id,397 roles=[{'id': self.role_id}]))['trust']['id']398 self.addCleanup(self.client.delete_trust, trust_id=trust_id)399 self.do_request('list_trust_roles', trust_id=trust_id)400 # user can list roles for trust for which they are trustee401 trustee_user_id = self.persona.credentials.user_id402 trust_id = self.user_trust_client.create_trust(403 **self.trust(trustee=trustee_user_id))['trust']['id']404 self.addCleanup(self.user_trust_client.delete_trust, trust_id=trust_id)405 self.do_request('list_trust_roles', trust_id=trust_id)406 # user cannot list roles for trust with which they are unaffiliated407 trust_id = self.user_trust_client.create_trust(408 **self.trust())['trust']['id']409 self.addCleanup(self.user_trust_client.delete_trust, trust_id=trust_id)410 self.do_request('list_trust_roles',411 expected_status=exceptions.Forbidden,412 trust_id=trust_id)413 def test_identity_get_role_for_trust(self):414 # user can get roles for trust for which they are trustor415 trustor_user_id = self.persona.credentials.user_id416 project_id = self.persona.credentials.project_id417 trust_id = self.client.create_trust(418 **self.trust(trustor=trustor_user_id,419 project_id=project_id,420 roles=[{'id': self.role_id}]))['trust']['id']421 self.addCleanup(self.client.delete_trust, trust_id=trust_id)422 self.do_request('show_trust_role',423 trust_id=trust_id, role_id=self.role_id)424 # user can list roles for trust for which they are trustee425 trustee_user_id = self.persona.credentials.user_id426 trust_id = self.user_trust_client.create_trust(427 **self.trust(trustee=trustee_user_id))['trust']['id']428 self.addCleanup(self.user_trust_client.delete_trust, trust_id=trust_id)429 self.do_request('show_trust_role',430 trust_id=trust_id, role_id=self.roles[0]['id'])431 # user cannot list roles for trust with which they are unaffiliated432 trust_id = self.user_trust_client.create_trust(433 **self.trust())['trust']['id']434 self.addCleanup(self.user_trust_client.delete_trust, trust_id=trust_id)435 self.do_request('show_trust_role',436 expected_status=exceptions.Forbidden,437 trust_id=trust_id, role_id=self.role_id)438 def test_identity_delete_trust(self):439 # user can delete trust for which they are the trustor440 trustor_user_id = self.persona.credentials.user_id441 project_id = self.persona.credentials.project_id442 trust_id = self.client.create_trust(443 **self.trust(trustor=trustor_user_id,444 project_id=project_id,445 roles=[{'id': self.role_id}]))['trust']['id']446 self.do_request('delete_trust', expected_status=204, trust_id=trust_id)447 # user cannot delete trust for which they are the trustee448 trustee_user_id = self.persona.credentials.user_id449 trust_id = self.user_trust_client.create_trust(450 **self.trust(trustee=trustee_user_id))['trust']['id']451 self.addCleanup(self.user_trust_client.delete_trust, trust_id=trust_id)452 self.do_request('delete_trust', expected_status=exceptions.Forbidden,...

Full Screen

Full Screen

test_cron_triggers.py

Source:test_cron_triggers.py Github

copy

Full Screen

1# Copyright 2014 - Mirantis, Inc.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14import copy15import json16import mock17from mistral.db.v2 import api as db_api18from mistral.db.v2.sqlalchemy import models19from mistral import exceptions as exc20from mistral.services import security21from mistral.tests.unit.api import base22WF = models.WorkflowDefinition(23 spec={24 'version': '2.0',25 'name': 'my_wf',26 'tasks': {27 'task1': {28 'action': 'std.noop'29 }30 }31 }32)33WF.update({'id': '123e4567-e89b-12d3-a456-426655440000', 'name': 'my_wf'})34TRIGGER = {35 'id': '123',36 'name': 'my_cron_trigger',37 'pattern': '* * * * *',38 'workflow_name': WF.name,39 'workflow_id': '123e4567-e89b-12d3-a456-426655440000',40 'workflow_input': '{}',41 'workflow_params': '{}',42 'scope': 'private',43 'remaining_executions': 4244}45trigger_values = copy.deepcopy(TRIGGER)46trigger_values['workflow_input'] = json.loads(47 trigger_values['workflow_input'])48trigger_values['workflow_params'] = json.loads(49 trigger_values['workflow_params'])50TRIGGER_DB = models.CronTrigger()51TRIGGER_DB.update(trigger_values)52MOCK_WF = mock.MagicMock(return_value=WF)53MOCK_TRIGGER = mock.MagicMock(return_value=TRIGGER_DB)54MOCK_TRIGGERS = mock.MagicMock(return_value=[TRIGGER_DB])55MOCK_DELETE = mock.MagicMock(return_value=None)56MOCK_EMPTY = mock.MagicMock(return_value=[])57MOCK_NOT_FOUND = mock.MagicMock(side_effect=exc.DBEntityNotFoundError())58MOCK_DUPLICATE = mock.MagicMock(side_effect=exc.DBDuplicateEntryError())59class TestCronTriggerController(base.APITest):60 @mock.patch.object(db_api, "get_cron_trigger", MOCK_TRIGGER)61 def test_get(self):62 resp = self.app.get('/v2/cron_triggers/my_cron_trigger')63 self.assertEqual(200, resp.status_int)64 self.assertDictEqual(TRIGGER, resp.json)65 @mock.patch.object(db_api, "get_cron_trigger", MOCK_NOT_FOUND)66 def test_get_not_found(self):67 resp = self.app.get(68 '/v2/cron_triggers/my_cron_trigger',69 expect_errors=True70 )71 self.assertEqual(404, resp.status_int)72 @mock.patch.object(db_api, "get_workflow_definition", MOCK_WF)73 @mock.patch.object(db_api, "create_cron_trigger")74 def test_post(self, mock_mtd):75 mock_mtd.return_value = TRIGGER_DB76 resp = self.app.post_json('/v2/cron_triggers', TRIGGER)77 self.assertEqual(201, resp.status_int)78 self.assertDictEqual(TRIGGER, resp.json)79 self.assertEqual(1, mock_mtd.call_count)80 values = mock_mtd.call_args[0][0]81 self.assertEqual('* * * * *', values['pattern'])82 self.assertEqual(42, values['remaining_executions'])83 @mock.patch.object(db_api, "get_workflow_definition", MOCK_WF)84 @mock.patch.object(db_api, "create_cron_trigger", MOCK_DUPLICATE)85 @mock.patch.object(security, "delete_trust")86 def test_post_dup(self, delete_trust):87 resp = self.app.post_json(88 '/v2/cron_triggers', TRIGGER, expect_errors=True89 )90 self.assertEqual(1, delete_trust.call_count)91 self.assertEqual(409, resp.status_int)92 @mock.patch.object(db_api, "get_workflow_definition", MOCK_WF)93 @mock.patch.object(db_api, "create_cron_trigger", MOCK_DUPLICATE)94 def test_post_same_wf_and_input(self):95 trig = TRIGGER.copy()96 trig['name'] = 'some_trigger_name'97 resp = self.app.post_json(98 '/v2/cron_triggers', trig, expect_errors=True99 )100 self.assertEqual(409, resp.status_int)101 @mock.patch.object(db_api, "get_cron_trigger", MOCK_TRIGGER)102 @mock.patch.object(db_api, "delete_cron_trigger", MOCK_DELETE)103 @mock.patch.object(security, "delete_trust")104 def test_delete(self, delete_trust):105 resp = self.app.delete('/v2/cron_triggers/my_cron_trigger')106 self.assertEqual(1, delete_trust.call_count)107 self.assertEqual(204, resp.status_int)108 @mock.patch.object(db_api, "delete_cron_trigger", MOCK_NOT_FOUND)109 def test_delete_not_found(self):110 resp = self.app.delete(111 '/v2/cron_triggers/my_cron_trigger',112 expect_errors=True113 )114 self.assertEqual(404, resp.status_int)115 @mock.patch.object(db_api, "get_cron_triggers", MOCK_TRIGGERS)116 def test_get_all(self):117 resp = self.app.get('/v2/cron_triggers')118 self.assertEqual(200, resp.status_int)119 self.assertEqual(1, len(resp.json['cron_triggers']))120 self.assertDictEqual(TRIGGER, resp.json['cron_triggers'][0])121 @mock.patch.object(db_api, "get_cron_triggers", MOCK_EMPTY)122 def test_get_all_empty(self):123 resp = self.app.get('/v2/cron_triggers')124 self.assertEqual(200, resp.status_int)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful