def test_update_members(self, mock_put): gws = GWS() members = gws.get_members('u_acadev_unittest') self.assertEquals(len(members), 2) members.remove(GroupMember(type="uwnetid", name="eight")) res = gws.update_members('u_acadev_unittest', members) mock_put.assert_called_with( '/group_sws/v3/group/u_acadev_unittest/member', {'If-Match': '*'}, {'data': [{'type': 'uwnetid', 'id': 'javerage'}]}) members.append(GroupMember(type="uwnetid", name="seven")) members.append(GroupMember(type="uwnetid", name="eight")) members.append(GroupMember(type="uwnetid", name="nine")) res = gws.update_members('u_acadev_unittest', members) mock_put.assert_called_with( '/group_sws/v3/group/u_acadev_unittest/member', {'If-Match': '*'}, {'data': [{'type': 'uwnetid', 'id': 'javerage'}, {'type': 'uwnetid', 'id': 'seven'}, {'type': 'uwnetid', 'id': 'eight'}, {'type': 'uwnetid', 'id': 'nine'}]})
def test_update_members_notfound(self): gws = GWS() members = [] members.append(GroupMember(type="uwnetid", name="_")) bad_members = gws.update_members("u_acadev_bad_members", members) self.assertEquals(len(bad_members), 1)
def update_members(group_id, file_path, act_as=None): try: use_django_backend() except ImportError: settings = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'settings.cfg') use_configparser_backend(settings, 'GWS') members = [] with open(file_path, 'r') as f: for line in f: members.append( GroupEntity(name=line.strip(), type=GroupEntity.UWNETID_TYPE)) client = GWS(act_as=act_as, log_errors=True) errors = client.update_members(group_id, members) if len(errors): print(errors)