How to use add_user_to_group method in lisa

Best Python code snippet using lisa_python

keycloak_util.py

Source:keycloak_util.py Github

copy

Full Screen

...74 return True75 except Exception as e:76 logger.exception("Exception caught while creating group: %s" % e)77 return False78 def add_user_to_group(self, user_name, group_name):79 """80 Creates group on keycloak side81 """82 try:83 user_id = self.k_admin.get_user_id(user_name)84 group_id = self.k_admin.get_group_by_path('/'+group_name)["id"]85 print("Found user %s" % user_id)86 print("Found group %s" % group_id)87 self.k_admin.group_user_add(user_id, group_id)88 logger.debug("Added User %s to Group: %s", user_name, group_name)89 return True90 except Exception as e:91 logger.exception("Exception caught while adding user to group: %s" % e)92 return False93if __name__ == "__main__":94 logging.basicConfig()95 keycloak_obj = KC_Wrapper('https://34.221.41.8:8443', 'admin', 'Cloudera1!')96 keycloak_obj.set_realm_on_keycloak('eastwestbank')97 assert keycloak_obj.create_user_on_keycloak('john_finance')98 assert keycloak_obj.create_user_on_keycloak('mark_bizdev')99 assert keycloak_obj.create_user_on_keycloak('jeremy_contractor')100 assert keycloak_obj.create_user_on_keycloak('diane_csr')101 assert keycloak_obj.create_user_on_keycloak('etl_user')102 assert keycloak_obj.create_user_on_keycloak('log_monitor')103 assert keycloak_obj.create_user_on_keycloak('michelle_dpo')104 assert keycloak_obj.create_user_on_keycloak('ivanna_eu_hr')105 assert keycloak_obj.create_user_on_keycloak('sasha_eu_hr')106 assert keycloak_obj.create_user_on_keycloak('kate_hr')107 assert keycloak_obj.create_user_on_keycloak('joe_analyst')108 assert keycloak_obj.create_group_on_keycloak('intern')109 assert keycloak_obj.create_group_on_keycloak('etl')110 assert keycloak_obj.create_group_on_keycloak('csr')111 assert keycloak_obj.create_group_on_keycloak('contractor')112 assert keycloak_obj.create_group_on_keycloak('finance')113 assert keycloak_obj.create_group_on_keycloak('business_dev')114 assert keycloak_obj.create_group_on_keycloak('dpo')115 assert keycloak_obj.create_group_on_keycloak('hr')116 assert keycloak_obj.create_group_on_keycloak('analyst')117 assert keycloak_obj.create_group_on_keycloak('eu_employee')118 assert keycloak_obj.create_group_on_keycloak('us_employee')119 assert keycloak_obj.add_user_to_group('joe_analyst', 'analyst')120 assert keycloak_obj.add_user_to_group('john_finance', 'finance')121 assert keycloak_obj.add_user_to_group('mark_bizdev', 'business_dev')122 assert keycloak_obj.add_user_to_group('jeremy_contractor', 'contractor')123 assert keycloak_obj.add_user_to_group('diane_csr', 'csr')124 assert keycloak_obj.add_user_to_group('etl_user', 'etl')125 assert keycloak_obj.add_user_to_group('log_monitor', 'etl')126 assert keycloak_obj.add_user_to_group('michelle_dpo', 'dpo')127 assert keycloak_obj.add_user_to_group('ivanna_eu_hr', 'hr')128 assert keycloak_obj.add_user_to_group('sasha_eu_hr', 'hr')129 assert keycloak_obj.add_user_to_group('kate_hr', 'hr')130 assert keycloak_obj.add_user_to_group('kate_hr', 'us_employee')131 assert keycloak_obj.add_user_to_group('ivanna_eu_hr', 'eu_employee')132 assert keycloak_obj.add_user_to_group('sasha_eu_hr', 'eu_employee')133 assert keycloak_obj.add_user_to_group('joe_analyst', 'us_employee')...

Full Screen

Full Screen

test_add_me.py

Source:test_add_me.py Github

copy

Full Screen

1from datetime import datetime2from unittest.mock import MagicMock, patch3from tagtrain import data4from . import fake5from tagtrain.tagtrain.tt_add_me import AddMe6@patch('tagtrain.data.by_member.add_user_to_group')7@patch('tagtrain.data.by_owner.find_group')8def test_unknown_group(find_group, add_user_to_group):9 find_group.side_effect = data.Group.DoesNotExist()10 app, reply, message, match = fake.create_all()11 AddMe(app).run(reply, message, match)12 find_group.assert_called_once_with('OwnerName', 'GroupName')13 add_user_to_group.assert_not_called()14 reply.append.assert_called_once_with('User `OwnerName` does not have a Group `GroupName`. Skipping.')15@patch('tagtrain.data.by_member.add_user_to_group')16@patch('tagtrain.data.by_owner.find_group')17def test_existing_member(find_group, add_user_to_group):18 group = fake.create_group(name='GroupName', member_count=1, locked=None)19 find_group.return_value = group20 add_user_to_group.return_value = (group, False)21 app, reply, message, match = fake.create_all()22 AddMe(app).run(reply, message, match)23 find_group.assert_called_once_with('OwnerName', 'GroupName')24 add_user_to_group.assert_called_once_with('OwnerName', 'GroupName', 'AuthorName', 'PermaLink')25 reply.append.assert_called_once_with("You are already a Member of `OwnerName`'s Group `GroupName`. Skipping.")26@patch('tagtrain.data.by_member.add_user_to_group')27@patch('tagtrain.data.by_owner.find_group')28def test_group_locked(find_group, add_user_to_group):29 group = fake.create_group(name='GroupName', member_count=1, locked=datetime.utcnow())30 find_group.return_value = group31 add_user_to_group.return_value = (group, False)32 app, reply, message, match = fake.create_all()33 AddMe(app).run(reply, message, match)34 find_group.assert_called_once_with('OwnerName', 'GroupName')35 add_user_to_group.assert_not_called()36 reply.append.assert_called_once_with("Group `GroupName` is locked. Only `OwnerName` can add you. Skipping.")37@patch('tagtrain.data.by_member.add_user_to_group')38@patch('tagtrain.data.by_owner.find_group')39def test_good(find_group, add_user_to_group):40 group = fake.create_group(name='GroupName', member_count=1, locked=None)41 find_group.return_value = group42 add_user_to_group.return_value = (group, True)43 app, reply, message, match = fake.create_all()44 AddMe(app).run(reply, message, match)45 find_group.assert_called_once_with('OwnerName', 'GroupName')46 add_user_to_group.assert_called_once_with('OwnerName', 'GroupName', 'AuthorName', 'PermaLink')47 reply.append.assert_called_once_with("You were added to `OwnerName`'s Group `GroupName`, 1 total Members.")48@patch('tagtrain.data.by_member.add_user_to_group')49@patch('tagtrain.data.by_owner.find_group')50def test_blacklisted(find_group, add_user_to_group):51 group = fake.create_group(name='GroupName', member_count=1, locked=None)52 find_group.return_value = group53 add_user_to_group.side_effect = data.by_member.Blacklisted()54 app, reply, message, match = fake.create_all()55 AddMe(app).run(reply, message, match)56 find_group.assert_called_once_with('OwnerName', 'GroupName')57 add_user_to_group.assert_called_once_with('OwnerName', 'GroupName', 'AuthorName', 'PermaLink')...

Full Screen

Full Screen

disabled_add.py

Source:disabled_add.py Github

copy

Full Screen

1from unittest.mock import MagicMock, patch2from . import fake3from tagtrain.tagtrain.disabled_add import Add4@patch('tagtrain.data.by_owner.add_user_to_group')5def test_existing_member(add_user_to_group):6 add_user_to_group.return_value = (fake.create_group(name='GroupName'), False)7 app, reply, message, match = fake.create_all()8 Add(app).run(reply, message, match)9 add_user_to_group.assert_called_once_with('AuthorName', 'GroupName', 'MemberName')10 reply.append.assert_called_once_with('`MemberName` already Member of Group `GroupName`. Skipping.')11@patch('tagtrain.data.by_owner.add_user_to_group')12def test_good_new_group(add_user_to_group):13 add_user_to_group.return_value = (fake.create_group(name='GroupName', member_count=1), True)14 app, reply, message, match = fake.create_all()15 Add(app).run(reply, message, match)16 add_user_to_group.assert_called_once_with('AuthorName', 'GroupName', 'MemberName')17 reply.append.assert_called_once_with('Group `GroupName` created with `MemberName` as the first Member.')18@patch('tagtrain.data.by_owner.add_user_to_group')19def test_good_existing_group(add_user_to_group):20 add_user_to_group.return_value = (fake.create_group(name='GroupName', member_count=2), True)21 app, reply, message, match = fake.create_all()22 Add(app).run(reply, message, match)23 add_user_to_group.assert_called_once_with('AuthorName', 'GroupName', 'MemberName')...

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