How to use configure_mock method in autotest

Best Python code snippet using autotest_python

test_rest_api.py

Source:test_rest_api.py Github

copy

Full Screen

...34 }35 attrs = {36 'request': request_mock37 }38 request_mock.configure_mock(**r_attr)39 mock_bundle.configure_mock(**attrs)40 groups = GroupAuthorization().read_list([], mock_bundle)41 self.assertEqual(Group.objects.exclude(name='anonymous').count(), groups.count())42 @patch('geonode.api.authorization.ApiLockdownAuthorization.read_list',43 return_value=Group.objects.exclude(name='anonymous'))44 @patch('geonode.people.models.Profile.group_list_all', return_value=[2])45 def test_regular_user_hide_private(self, super_mock, mocked_profile):46 mock_bundle = MagicMock()47 request_mock = MagicMock()48 r_attr = {49 'user': Profile(username='test')50 }51 attrs = {52 'request': request_mock53 }54 request_mock.configure_mock(**r_attr)55 mock_bundle.configure_mock(**attrs)56 groups = GroupAuthorization().read_list(['not_empty_but_fake'], mock_bundle)57 self.assertEqual(1, groups.count())58 @patch('geonode.api.authorization.ApiLockdownAuthorization.read_list',59 return_value=Group.objects.exclude(name='anonymous'))60 @patch('geonode.people.models.Profile.group_list_all', return_value=[1])61 def test_regular_user(self, super_mock, mocked_profile):62 mock_bundle = MagicMock()63 request_mock = MagicMock()64 r_attr = {65 'user': Profile(username='test')66 }67 attrs = {68 'request': request_mock69 }70 request_mock.configure_mock(**r_attr)71 mock_bundle.configure_mock(**attrs)72 groups = GroupAuthorization().read_list(['not_empty_but_fake'], mock_bundle)73 self.assertEqual(2, groups.count())74 @patch('geonode.api.authorization.ApiLockdownAuthorization.read_list',75 return_value=Group.objects.exclude(name='anonymous'))76 @patch('geonode.people.models.Profile.group_list_all', return_value=[1])77 def test_anonymous_user(self, super_mock, mocked_profile):78 mock_bundle = MagicMock()79 request_mock = MagicMock()80 r_attr = {81 'user': AnonymousUser()82 }83 attrs = {84 'request': request_mock85 }86 request_mock.configure_mock(**r_attr)87 mock_bundle.configure_mock(**attrs)88 groups = GroupAuthorization().read_list(['not_empty_but_fake'], mock_bundle)89 self.assertEqual(1, groups.count())90class TestGroupProfileResAuthorization(GeoNodeBaseTestSupport):91 # Group fixture is loaded in base class92 @patch('geonode.api.authorization.ApiLockdownAuthorization.read_list', return_value=GroupProfile.objects.all())93 def test_super_admin_user(self, super_mock):94 mock_bundle = MagicMock()95 request_mock = MagicMock()96 r_attr = {97 'user': Profile(username='test', is_staff=True, is_superuser=True)98 }99 attrs = {100 'request': request_mock101 }102 request_mock.configure_mock(**r_attr)103 mock_bundle.configure_mock(**attrs)104 groups = GroupProfileAuthorization().read_list([], mock_bundle)105 self.assertEqual(GroupProfile.objects.all().count(), groups.count())106 @patch('geonode.api.authorization.ApiLockdownAuthorization.read_list', return_value=GroupProfile.objects.all())107 @patch('geonode.people.models.Profile.group_list_all', return_value=[2])108 def test_regular_user_hide_private(self, super_mock, mocked_profile):109 mock_bundle = MagicMock()110 request_mock = MagicMock()111 r_attr = {112 'user': Profile(username='test')113 }114 attrs = {115 'request': request_mock116 }117 request_mock.configure_mock(**r_attr)118 mock_bundle.configure_mock(**attrs)119 groups = GroupProfileAuthorization().read_list(['not_empty_but_fake'], mock_bundle)120 self.assertEqual(1, groups.count())121 @patch('geonode.api.authorization.ApiLockdownAuthorization.read_list', return_value=GroupProfile.objects.all())122 @patch('geonode.people.models.Profile.group_list_all', return_value=[1])123 def test_regular_user(self, super_mock, mocked_profile):124 mock_bundle = MagicMock()125 request_mock = MagicMock()126 r_attr = {127 'user': Profile(username='test')128 }129 attrs = {130 'request': request_mock131 }132 request_mock.configure_mock(**r_attr)133 mock_bundle.configure_mock(**attrs)134 groups = GroupProfileAuthorization().read_list(['not_empty_but_fake'], mock_bundle)135 self.assertEqual(2, groups.count())136 @patch('geonode.api.authorization.ApiLockdownAuthorization.read_list', return_value=GroupProfile.objects.all())137 @patch('geonode.people.models.Profile.group_list_all', return_value=[1])138 def test_anonymous_user(self, super_mock, mocked_profile):139 mock_bundle = MagicMock()140 request_mock = MagicMock()141 r_attr = {142 'user': AnonymousUser()143 }144 attrs = {145 'request': request_mock146 }147 request_mock.configure_mock(**r_attr)148 mock_bundle.configure_mock(**attrs)149 groups = GroupProfileAuthorization().read_list(['not_empty_but_fake'], mock_bundle)...

Full Screen

Full Screen

context.py

Source:context.py Github

copy

Full Screen

...43 raise InvalidParamsException(f"{address} is not active SCORE")44 return score_mapper[address]45def get_default_context():46 mock_context = Mock(spec=IconScoreContext)47 mock_context.configure_mock(msg=Message())48 mock_context.configure_mock(tx=Transaction())49 mock_context.configure_mock(block=Block())50 mock_context.configure_mock(step_counter=None)51 mock_context.configure_mock(type=IconScoreContextType.QUERY)52 mock_context.configure_mock(func_type=IconScoreFuncType.WRITABLE)53 mock_context.configure_mock(current_address=None)54 mock_context.configure_mock(block_batch=None)55 mock_context.configure_mock(tx_batch=None)56 mock_context.configure_mock(event_logs=None)57 mock_context.configure_mock(event_log_stack=[])58 mock_context.configure_mock(traces=[])59 mock_context.configure_mock(icon_score_mapper=score_mapper)60 mock_context.configure_mock(revision=MAIN_NET_REVISION)61 mock_context.icon_score_mapper = score_mapper62 mock_context.validate_score_blacklist = Mock(return_value=True)63 mock_context.get_icon_score = get_icon_score64 mock_context.method_flag_trace = []65 return mock_context66def clear_data():67 IcxEngine.db.close()68 score_mapper.clear()69 interface_score_mapper.clear()70class Context:71 context = get_default_context()72 @classmethod73 def get_context(cls):74 return cls.context...

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