How to use test_expected_exceptions method in assertpy

Best Python code snippet using assertpy_python

test_keystone_client.py

Source:test_keystone_client.py Github

copy

Full Screen

...17from heat.engine.clients.os import keystone18from heat.engine.clients.os.keystone import keystone_constraints as ks_constr19from heat.tests import common20class KeystoneRoleConstraintTest(common.HeatTestCase):21 def test_expected_exceptions(self):22 self.assertEqual(23 (exception.EntityNotFound,),24 ks_constr.KeystoneRoleConstraint.expected_exceptions,25 "KeystoneRoleConstraint expected exceptions error")26 def test_constraint(self):27 constraint = ks_constr.KeystoneRoleConstraint()28 client_mock = mock.MagicMock()29 client_plugin_mock = mock.MagicMock()30 client_plugin_mock.get_role_id.return_value = None31 client_mock.client_plugin.return_value = client_plugin_mock32 self.assertIsNone(constraint.validate_with_client(client_mock,33 'role_1'))34 self.assertRaises(exception.EntityNotFound,35 constraint.validate_with_client, client_mock, '')36 client_plugin_mock.get_role_id.assert_called_once_with('role_1')37class KeystoneProjectConstraintTest(common.HeatTestCase):38 def test_expected_exceptions(self):39 self.assertEqual(40 (exception.EntityNotFound,),41 ks_constr.KeystoneProjectConstraint.expected_exceptions,42 "KeystoneProjectConstraint expected exceptions error")43 def test_constraint(self):44 constraint = ks_constr.KeystoneProjectConstraint()45 client_mock = mock.MagicMock()46 client_plugin_mock = mock.MagicMock()47 client_plugin_mock.get_project_id.return_value = None48 client_mock.client_plugin.return_value = client_plugin_mock49 self.assertIsNone(constraint.validate_with_client(client_mock,50 'project_1'))51 self.assertRaises(exception.EntityNotFound,52 constraint.validate_with_client, client_mock, '')53 client_plugin_mock.get_project_id.assert_called_once_with('project_1')54class KeystoneGroupConstraintTest(common.HeatTestCase):55 def test_expected_exceptions(self):56 self.assertEqual(57 (exception.EntityNotFound,),58 ks_constr.KeystoneGroupConstraint.expected_exceptions,59 "KeystoneGroupConstraint expected exceptions error")60 def test_constraint(self):61 constraint = ks_constr.KeystoneGroupConstraint()62 client_mock = mock.MagicMock()63 client_plugin_mock = mock.MagicMock()64 client_plugin_mock.get_group_id.return_value = None65 client_mock.client_plugin.return_value = client_plugin_mock66 self.assertIsNone(constraint.validate_with_client(client_mock,67 'group_1'))68 self.assertRaises(exception.EntityNotFound,69 constraint.validate_with_client, client_mock, '')70 client_plugin_mock.get_group_id.assert_called_once_with('group_1')71class KeystoneDomainConstraintTest(common.HeatTestCase):72 def test_expected_exceptions(self):73 self.assertEqual(74 (exception.EntityNotFound,),75 ks_constr.KeystoneDomainConstraint.expected_exceptions,76 "KeystoneDomainConstraint expected exceptions error")77 def test_constraint(self):78 constraint = ks_constr.KeystoneDomainConstraint()79 client_mock = mock.MagicMock()80 client_plugin_mock = mock.MagicMock()81 client_plugin_mock.get_domain_id.return_value = None82 client_mock.client_plugin.return_value = client_plugin_mock83 self.assertIsNone(constraint.validate_with_client(client_mock,84 'domain_1'))85 self.assertRaises(exception.EntityNotFound,86 constraint.validate_with_client, client_mock, '')87 client_plugin_mock.get_domain_id.assert_called_once_with('domain_1')88class KeystoneServiceConstraintTest(common.HeatTestCase):89 sample_uuid = '477e8273-60a7-4c41-b683-fdb0bc7cd151'90 def test_expected_exceptions(self):91 self.assertEqual(92 (exception.EntityNotFound, exception.KeystoneServiceNameConflict,),93 ks_constr.KeystoneServiceConstraint.expected_exceptions,94 "KeystoneServiceConstraint expected exceptions error")95 def test_constraint(self):96 constraint = ks_constr.KeystoneServiceConstraint()97 client_mock = mock.MagicMock()98 client_plugin_mock = mock.MagicMock()99 client_plugin_mock.get_service_id.return_value = self.sample_uuid100 client_mock.client_plugin.return_value = client_plugin_mock101 self.assertIsNone(constraint.validate_with_client(client_mock,102 self.sample_uuid))103 self.assertRaises(exception.EntityNotFound,104 constraint.validate_with_client, client_mock, '')105 client_plugin_mock.get_service_id.assert_called_once_with(106 self.sample_uuid)107class KeystoneUserConstraintTest(common.HeatTestCase):108 def test_expected_exceptions(self):109 self.assertEqual(110 (exception.EntityNotFound,),111 ks_constr.KeystoneUserConstraint.expected_exceptions,112 "KeystoneUserConstraint expected exceptions error")113 def test_constraint(self):114 constraint = ks_constr.KeystoneUserConstraint()115 client_mock = mock.MagicMock()116 client_plugin_mock = mock.MagicMock()117 client_plugin_mock.get_user_id.return_value = None118 client_mock.client_plugin.return_value = client_plugin_mock119 self.assertIsNone(constraint.validate_with_client(client_mock,120 'admin'))121 self.assertRaises(exception.EntityNotFound,122 constraint.validate_with_client, client_mock, '')123 client_plugin_mock.get_user_id.assert_called_once_with('admin')124class KeystoneRegionConstraintTest(common.HeatTestCase):125 sample_uuid = '477e8273-60a7-4c41-b683-fdb0bc7cd151'126 def test_expected_exceptions(self):127 self.assertEqual(128 (exception.EntityNotFound,),129 ks_constr.KeystoneRegionConstraint.expected_exceptions,130 "KeystoneRegionConstraint expected exceptions error")131 def test_constraint(self):132 constraint = ks_constr.KeystoneRegionConstraint()133 client_mock = mock.MagicMock()134 client_plugin_mock = mock.MagicMock()135 client_plugin_mock.get_region_id.return_value = self.sample_uuid136 client_mock.client_plugin.return_value = client_plugin_mock137 self.assertIsNone(constraint.validate_with_client(client_mock,138 self.sample_uuid))139 self.assertRaises(exception.EntityNotFound,140 constraint.validate_with_client, client_mock, '')...

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 assertpy 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