def test_badUpdateGroup(self):
     conn = self.rootconn
     uuid = conn._sessionUuid
     
     # create group
     params = {
         "name":"webadmin_test_group_private %s" % uuid,
         "description":"test group",
         "owners": [0L],
         "permissions":0
     }
     request = fakeRequest(method="post", params=params)
     gid = _createGroup(request, conn)
     
     # create new users
     params2 = {
         "omename":"webadmin_test_user1 %s" % uuid,
         "first_name":uuid,
         "middle_name": uuid,
         "last_name":uuid,
         "email":"*****@*****.**" % uuid,
         "institution":"Laboratory",
         "active":True,
         "default_group":gid,
         "other_groups":[gid],
         "password":"******",
         "confirmation":"123" 
     }
     request = fakeRequest(method="post", params=params2)
     eid = _createExperimenter(request, conn)
     
     # check if group updated
     group = conn.getObject("ExperimenterGroup", gid)
     ownerIds = [e.id for e in group.getOwners()]
     memberIds = [e.id for e in group.getMembers()]
     self.assertEquals(params['owners'], sorted(ownerIds))
     self.assertEquals(sorted(mergeLists(params['owners'], [eid])), sorted(memberIds))
     
     # remove user from the group
     params["members"] = [0]
     request = fakeRequest(method="post", params=params)
     
     try:
         _updateGroup(request, conn, gid)
         self.fail("Can't remove user from the group members if this it's hs default group")
     except omero.ValidationException:
         pass
     
     # check if group updated
     group = conn.getObject("ExperimenterGroup", gid)
     memberIds = [e.id for e in group.getMembers()]
     if eid not in memberIds:
         self.fail("Can't remove user from the group members if this it's hs default group")
Exemple #2
0
    def test_changePassword(self):
        conn = self.rootconn
        uuid = conn._sessionUuid

        # private group
        params = {
            "name": uuid,
            "description": "password test",
            "permissions": 0
        }

        request = fakeRequest(method="post", params=params)
        gid = _createGroup(request, conn)

        # create experimenter
        params = {
            "omename": 'password%s' % uuid,
            "first_name": uuid,
            "middle_name": uuid,
            "last_name": uuid,
            "email": "*****@*****.**" % uuid,
            "institution": "Laboratory",
            "administrator": False,
            "active": True,
            "default_group": gid,
            "other_groups": [gid],
            "password": "******",
            "confirmation": "123"
        }
        request = fakeRequest(method="post", params=params)
        eid = _createExperimenter(request, conn)

        #change password as root
        params_passwd = {
            "password": "******",
            "confirmation": "abc",
            "old_password": self.root_password
        }
        request = fakeRequest(method="post", params=params_passwd)
        _changePassword(request, conn, eid)

        # login as user and change my password
        user_conn = self.loginAsUser(params['omename'],
                                     params_passwd['password'])
        params_passwd = {
            "old_password": "******",
            "password": "******",
            "confirmation": "foo"
        }
        request = fakeRequest(method="post", params=params_passwd)
        _changePassword(request, user_conn)

        self.loginAsUser(params['omename'], params_passwd['password'])
Exemple #3
0
 def test_changePassword(self):
     conn = self.rootconn
     uuid = conn._sessionUuid
     
     # private group
     params = {
         "name": uuid,
         "description":"password test",
         "permissions":0
     }
     
     request = fakeRequest(method="post", params=params)
     gid = _createGroup(request, conn)
     
     # create experimenter
     params = {
         "omename":'password%s' % uuid,
         "first_name":uuid,
         "middle_name": uuid,
         "last_name":uuid,
         "email":"*****@*****.**" % uuid,
         "institution":"Laboratory",
         "administrator": False,
         "active":True,
         "default_group":gid,
         "other_groups":[gid],
         "password":"******",
         "confirmation":"123" 
     }
     request = fakeRequest(method="post", params=params)
     eid = _createExperimenter(request, conn)
     
     #change password as root        
     params_passwd = {
         "password":"******",
         "confirmation":"abc",
         "old_password":self.root_password
     }
     request = fakeRequest(method="post", params=params_passwd)        
     _changePassword(request, conn, eid)
     
     # login as user and change my password
     user_conn = self.loginAsUser(params['omename'], params_passwd['password'])
     params_passwd = {
         "old_password":"******",
         "password":"******",
         "confirmation":"foo" 
     }
     request = fakeRequest(method="post", params=params_passwd)
     _changePassword(request, user_conn)
     
     self.loginAsUser(params['omename'], params_passwd['password'])
Exemple #4
0
    def test_badUpdateGroup(self):
        conn = self.rootconn
        uuid = conn._sessionUuid

        # create group
        params = {
            "name": "webadmin_test_group_private %s" % uuid,
            "description": "test group",
            "owners": [0L],
            "permissions": 0
        }
        request = fakeRequest(method="post", params=params)
        gid = _createGroup(request, conn)

        # create new users
        params2 = {
            "omename": "webadmin_test_user1 %s" % uuid,
            "first_name": uuid,
            "middle_name": uuid,
            "last_name": uuid,
            "email": "*****@*****.**" % uuid,
            "institution": "Laboratory",
            "active": True,
            "default_group": gid,
            "other_groups": [gid],
            "password": "******",
            "confirmation": "123"
        }
        request = fakeRequest(method="post", params=params2)
        eid = _createExperimenter(request, conn)

        # check if group updated
        group = conn.getObject("ExperimenterGroup", gid)
        ownerIds = [e.id for e in group.getOwners()]
        memberIds = [e.id for e in group.getMembers()]
        self.assertEquals(params['owners'], sorted(ownerIds))
        self.assertEquals(sorted(mergeLists(params['owners'], [eid])),
                          sorted(memberIds))

        # remove user from the group
        params["members"] = [0]
        request = fakeRequest(method="post", params=params)
        _updateGroup(request, conn, gid)

        # check if group updated
        group = conn.getObject("ExperimenterGroup", gid)
        memberIds = [e.id for e in group.getMembers()]
        if eid not in memberIds:
            self.fail(
                "Can't remove user from the group members if this is hs default group"
            )
 def test_updateGroups(self):        
     conn = self.rootconn
     uuid = conn._sessionUuid
     
     # private group
     params = {
         "name":"webadmin_test_group_private %s" % uuid,
         "description":"test group",
         "owners": [0L],
         "permissions":0
     }
     request = fakeRequest(method="post", params=params)
     gid = _createGroup(request, conn)
     
     # create new user
     params = {
         "omename":"webadmin_test_owner %s" % uuid,
         "first_name":uuid,
         "middle_name": uuid,
         "last_name":uuid,
         "email":"*****@*****.**" % uuid,
         "institution":"Laboratory",
         "active":True,
         "default_group":gid,
         "other_groups":[gid],
         "password":"******",
         "confirmation":"123" 
     }
     request = fakeRequest(method="post", params=params)
     eid = _createExperimenter(request, conn)
     
     # upgrade group to collaborative
     # read-only group and add new owner
     params = {
         "name":"webadmin_test_group_read-only %s" % uuid,
         "description":"test group changed",
         "owners": [0, eid],
         "permissions":1,
         "readonly":True
     }
     request = fakeRequest(method="post", params=params)
     _updateGroup(request, conn, gid)
     
     # check if updated
     controller = BaseGroup(conn, gid)
     perm = controller.getActualPermissions()
     self.assertEquals(params['name'], controller.group.name)
     self.assertEquals(params['description'], controller.group.description)
     self.assertEquals(sorted(params['owners']), sorted(controller.owners))
     self.assertEquals(params['permissions'], perm)
     self.assertEquals(params['readonly'], controller.isReadOnly())
Exemple #6
0
 def test_createGroups(self):        
     conn = self.rootconn
     uuid = conn._sessionUuid
     
     # private group
     params = {
         "name":"webadmin_test_group_private %s" % uuid,
         "description":"test group",
         "permissions":0
     }
     request = fakeRequest(method="post", params=params)
     gid = _createGroup(request, conn)
        
     # check if group created
     group = conn.getObject("ExperimenterGroup", gid)
     permissions = getActualPermissions(group)
     self.assertEquals(params['name'], group.name)
     self.assertEquals(params['description'], group.description)
     self.assertEquals(params['permissions'], permissions)
     
     # collaborative read-only group
     params = {
         "name":"webadmin_test_group_read-only %s" % uuid,
         "description":"test group",
         "permissions":1
     }
     request = fakeRequest(method="post", params=params)
     gid = _createGroup(request, conn)
        
     # check if group created
     group = conn.getObject("ExperimenterGroup", gid)
     permissions = getActualPermissions(group)
     self.assertEquals(params['name'], group.name)
     self.assertEquals(params['description'], group.description)
     self.assertEquals(params['permissions'], permissions)
     
     # collaborative read-annotate group
     params = {
         "name":"webadmin_test_group_read-ann %s" % uuid,
         "description":"test group",
         "permissions":2
     }
     request = fakeRequest(method="post", params=params)
     gid = _createGroup(request, conn)
        
     # check if group created
     group = conn.getObject("ExperimenterGroup", gid)
     permissions = getActualPermissions(group)
     self.assertEquals(params['name'], group.name)
     self.assertEquals(params['description'], group.description)
     self.assertEquals(params['permissions'], permissions)
Exemple #7
0
    def test_loginFromForm(self):
        params = {
            'username': '******',
            'password': self.root_password,
            'server':self.server_id,
            'ssl':'on'
        }        
        request = fakeRequest(method="post", params=params)
        
        server_id = request.REQUEST.get('server')
        form = LoginForm(data=request.REQUEST.copy())
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            server_id = form.cleaned_data['server']
            is_secure = toBoolean(form.cleaned_data['ssl'])

            connector = Connector(server_id, is_secure)
            conn = connector.create_connection('OMERO.web', username, password)
            if conn is None:
                self.fail('Cannot connect')
            
            conn.seppuku()
            if conn.isConnected() and conn.keepAlive():
                self.fail('Connection was not closed')
            
        else:
            errors = form.errors.as_text()
            self.fail(errors)
    def test_loginFailure(self):
        params = {
            'username': '******',
            'password': '******',
            'server':self.server_id
        }        
        request = fakeRequest(method="post", params=params)
        
        form = LoginForm(data=request.REQUEST.copy())        
        if form.is_valid():
            blitz = settings.SERVER_LIST.get(pk=form.cleaned_data['server']) 
            request.session['server'] = blitz.id
            request.session['host'] = blitz.host
            request.session['port'] = blitz.port
            request.session['username'] = form.cleaned_data['username'].strip()
            request.session['password'] = form.cleaned_data['password'].strip()
            request.session['ssl'] = form.cleaned_data['ssl']

            conn = webgateway_views.getBlitzConnection(request, useragent="TEST.webadmin")
            if conn is not None:
                self.fail('This user does not exist. Login failure error!')
                webgateway_views._session_logout(request, request.session.get('server'))

        else:
            errors = form.errors.as_text()
            self.fail(errors)            
Exemple #9
0
 def test_createGroupsWithNonASCII(self):        
     conn = self.rootconn
     uuid = conn._sessionUuid
     
     # private group
     params = {
         "name":u"русский_алфавит %s" % uuid,
         "description":u"Frühstück-Śniadanie. Tschüß-Cześć",
         "owners": [0L],
         "members": [0L],
         "permissions":0
     }
     request = fakeRequest(method="post", params=params)
     gid = _createGroup(request, conn)
     
     # check if group created
     group = conn.getObject("ExperimenterGroup", gid)
     ownerIds = [e.id for e in group.getOwners()]
     membersIds = [e.id for e in group.getMembers()]
     permissions = getActualPermissions(group)
     self.assertEquals(params['name'], group.name)
     self.assertEquals(params['description'], group.description)
     self.assertEquals(sorted(params['owners']), sorted(ownerIds))
     self.assertEquals(sorted(params['members']), sorted(membersIds))
     self.assertEquals(params['permissions'], permissions)
    def test_loginFromForm(self):
        params = {
            'username': '******',
            'password': self.root_password,
            'server':self.server_id,
            'ssl':'on'
        }        
        request = fakeRequest(method="post", params=params)
        
        form = LoginForm(data=request.REQUEST.copy())        
        if form.is_valid():
            
            blitz = settings.SERVER_LIST.get(pk=form.cleaned_data['server']) 
            request.session['server'] = blitz.id
            request.session['host'] = blitz.host
            request.session['port'] = blitz.port
            request.session['username'] = form.cleaned_data['username'].strip()
            request.session['password'] = form.cleaned_data['password'].strip()
            request.session['ssl'] = form.cleaned_data['ssl']

            conn = webgateway_views.getBlitzConnection(request, useragent="TEST.webadmin")
            if conn is None:
                self.fail('Cannot connect')            
            webgateway_views._session_logout(request, request.session.get('server'))
            if conn.isConnected() and conn.keepAlive():
                self.fail('Connection was not closed')
            
        else:
            errors = form.errors.as_text()
            self.fail(errors)
 def test_createGroups(self):        
     conn = self.rootconn
     uuid = conn._sessionUuid
     
     # private group
     params = {
         "name":"webadmin_test_group_private %s" % uuid,
         "description":"test group",
         "owners": [0L],
         "permissions":0
     }
     request = fakeRequest(method="post", params=params)
     gid = _createGroup(request, conn)
        
     # check if group created
     controller = BaseGroup(conn, gid)
     perm = controller.getActualPermissions()
     self.assertEquals(params['name'], controller.group.name)
     self.assertEquals(params['description'], controller.group.description)
     self.assertEquals(sorted(params['owners']), sorted(controller.owners))
     self.assertEquals(params['permissions'], perm)
     self.assertEquals(False, controller.isReadOnly())
     
     # read-only group
     params = {
         "name":"webadmin_test_group_read-only %s" % uuid,
         "description":"test group",
         "owners": [0L],
         "permissions":1,
         "readonly":True
     }
     request = fakeRequest(method="post", params=params)
     gid = _createGroup(request, conn)
           
     # check if group created
     controller = BaseGroup(conn, gid)
     perm = controller.getActualPermissions()
     self.assertEquals(params['name'], controller.group.name)
     self.assertEquals(params['description'], controller.group.description)
     self.assertEquals(sorted(params['owners']), sorted(controller.owners))
     self.assertEquals(params['permissions'], perm)
     self.assertEquals(params['readonly'], controller.isReadOnly())
Exemple #12
0
 def test_badCreateExperimenters(self):
     conn = self.rootconn
     uuid = conn._sessionUuid
     
     # empty fields
     params = {}
     request = fakeRequest(method="post", params=params)
     try:
         eid = _createExperimenter(request, conn)
     except Exception, e:
         pass
 def test_badCreateExperimenters(self):
     conn = self.rootconn
     
     # empty fields
     params = {}
     request = fakeRequest(method="post", params=params)
     try:
         _createExperimenter(request, conn)
     except Exception:
         pass
     else:
         self.fail("Can't create user with no parameters")
 def test_createGroupsWithNonASCII(self):        
     conn = self.rootconn
     uuid = conn._sessionUuid
     
     # private group
     params = {
         "name":u"русский_алфавит %s" % uuid,
         "description":u"Frühstück-Śniadanie. Tschüß-Cześć",
         "owners": [0L],
         "permissions":0
     }
     request = fakeRequest(method="post", params=params)
     gid = _createGroup(request, conn)
        
     # check if group created
     controller = BaseGroup(conn, gid)
     perm = controller.getActualPermissions()
     self.assertEquals(params['name'], controller.group.name)
     self.assertEquals(params['description'], controller.group.description)
     self.assertEquals(sorted(params['owners']), sorted(controller.owners))
     self.assertEquals(params['permissions'], perm)
     self.assertEquals(False, controller.isReadOnly())
Exemple #15
0
    def test_loginFromRequest(self):
        params = {
            'username': '******',
            'password': self.root_password,
            'server':self.server_id,
            'ssl':'on'
        }        
        request = fakeRequest(method="post", path="/webadmin/login", params=params)
        
        server_id = request.REQUEST.get('server')
        username = request.REQUEST.get('username')
        password = request.REQUEST.get('password')
        is_secure = toBoolean(request.REQUEST.get('ssl'))

        connector = Connector(server_id, is_secure)
        conn = connector.create_connection('TEST.webadmin', username, password)
        if conn is None:
            self.fail('Cannot connect')
        
        conn.seppuku()
        if conn.isConnected() and conn.keepAlive():
            self.fail('Connection was not closed')
    def test_loginFromRequest(self):
        params = {
            'username': '******',
            'password': self.root_password,
            'server':self.server_id,
            'ssl':'on'
        }        
        request = fakeRequest(method="post", path="/webadmin/login", params=params)
        
        blitz = settings.SERVER_LIST.get(pk=request.REQUEST.get('server')) 
        request.session['server'] = blitz.id
        request.session['host'] = blitz.host
        request.session['port'] = blitz.port
        request.session['username'] = request.REQUEST.get('username').encode('utf-8').strip()
        request.session['password'] = request.REQUEST.get('password').encode('utf-8').strip()
        request.session['ssl'] = (True, False)[request.REQUEST.get('ssl') is None]

        conn = webgateway_views.getBlitzConnection(request, useragent="TEST.webadmin")
        if conn is None:
            self.fail('Cannot connect')
        webgateway_views._session_logout(request, request.session.get('server'))
        if conn.isConnected() and conn.keepAlive():
            self.fail('Connection was not closed')
Exemple #17
0
    def test_loginFailure(self):
        params = {
            'username': '******',
            'password': '******',
            'server':self.server_id
        }        
        request = fakeRequest(method="post", params=params)
        
        server_id = request.REQUEST.get('server')
        form = LoginForm(data=request.REQUEST.copy())
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            server_id = form.cleaned_data['server']
            is_secure = toBoolean(form.cleaned_data['ssl'])

            connector = Connector(server_id, is_secure)
            conn = connector.create_connection('OMERO.web', username, password)
            if conn is not None:
                self.fail('This user does not exist. Login failure error!')
        
        else:
            errors = form.errors.as_text()
            self.fail(errors)            
Exemple #18
0
 def test_urlsAsUser(self):
     conn = self.rootconn
     uuid = conn._sessionUuid
     
     # private group
     params = {
         "name":"webadmin_test_group_private %s" % uuid,
         "description":"test group",
         "owners": [0L],
         "permissions":0
     }
     request = fakeRequest(method="post", params=params)
     gid = _createGroup(request, conn)
     
     params = {
         "omename":"webadmin_test_user %s" % uuid,
         "first_name":uuid,
         "middle_name": uuid,
         "last_name":uuid,
         "email":"*****@*****.**" % uuid,
         "institution":"Laboratory",
         "active":True,
         "default_group":gid,
         "other_groups":[gid],
         "password":"******",
         "confirmation":"123" 
     }
     request = fakeRequest(method="post", params=params)
     eid = _createExperimenter(request, conn)
     
     # TODO:Create experimenter 
     self.client.login("webadmin_test_user %s" % uuid, '123')
     
     # response 200
     response = self.client.get(reverse(viewname="wamyaccount"))
     self.failUnlessEqual(response.status_code, 200)
     
     response = self.client.get(reverse(viewname="wadrivespace"))
     self.failUnlessEqual(response.status_code, 200)
     
     response = self.client.get(reverse(viewname="wamyphoto"))
     self.failUnlessEqual(response.status_code, 200)
     
     response = self.client.get(reverse(viewname="wamanagechangepasswordid", args=["4"]))
     self.failUnlessEqual(response.status_code, 200)
     
     # response 404
     response = self.client.get(reverse(viewname="waexperimenters"))
     self.failUnlessEqual(response.status_code, 404)
             
     response = self.client.get(reverse(viewname="wamanageexperimenterid", args=["new"]))
     self.failUnlessEqual(response.status_code, 404)
     
     response = self.client.get(reverse(viewname="wamanageexperimenterid", args=["create"]))
     self.failUnlessEqual(response.status_code, 404)
     
     response = self.client.get(reverse(viewname="wamanageexperimenterid", args=["edit", "1"]))
     self.failUnlessEqual(response.status_code, 404)
     
     response = self.client.get(reverse(viewname="wamanageexperimenterid", args=["save", "1"]))
     self.failUnlessEqual(response.status_code, 404)
     
     response = self.client.get(reverse(viewname="wagroups"))
     self.failUnlessEqual(response.status_code, 404)
     
     response = self.client.get(reverse(viewname="wamanagegroupid", args=["new"]))
     self.failUnlessEqual(response.status_code, 404)
     
     response = self.client.get(reverse(viewname="wamanagegroupid", args=["create"]))
     self.failUnlessEqual(response.status_code, 404)
     
     response = self.client.get(reverse(viewname="wamanagegroupid", args=["edit", "2"]))
     self.failUnlessEqual(response.status_code, 404)
     
     response = self.client.get(reverse(viewname="wamanagegroupid", args=["save", "2"]))
     self.failUnlessEqual(response.status_code, 404)
Exemple #19
0
 def test_updateExperimenter(self):
     conn = self.rootconn
     uuid = conn._sessionUuid
     
     # private group
     params = {
         "name":"webadmin_test_group_private %s" % uuid,
         "description":"test group",
         "permissions":0
     }
     
     request = fakeRequest(method="post", params=params)
     gid = _createGroup(request, conn)
     
     # default group - helper
     params = {
         "name":"webadmin_test_default %s" % uuid,
         "description":"test group default",
         "permissions":0
     }
     request = fakeRequest(method="post", params=params)
     default_gid = _createGroup(request, conn)
     
     # create experimenter
     params = {
         "omename":"webadmin_test_user %s" % uuid,
         "first_name":uuid,
         "middle_name": uuid,
         "last_name":uuid,
         "email":"*****@*****.**" % uuid,
         "institution":"Laboratory",
         "active":True,
         "administrator":False,
         "default_group":gid,
         "other_groups":[gid],
         "password":"******",
         "confirmation":"123" 
     }
     request = fakeRequest(method="post", params=params)
     eid = _createExperimenter(request, conn)
     
     # add admin privilages and change default group
     params = {
         "omename":"webadmin_test_admin %s" % uuid,
         "first_name":uuid,
         "middle_name": uuid,
         "last_name":uuid,
         "email":"*****@*****.**" % uuid,
         "institution":"Laboratory",
         "administrator": True,
         "active":True,
         "default_group":default_gid,
         "other_groups":[0,gid,default_gid],
         "password":"******",
         "confirmation":"123" 
     }
     request = fakeRequest(method="post", params=params)
     _updateExperimenter(request, conn, eid)
     
     # check if experimenter updated
     experimenter = conn.getObject("Experimenter", eid)
     otherGroupIds = [g.id for g in experimenter.getOtherGroups()]
     self.assertEquals(params['omename'], experimenter.omeName)
     self.assertEquals(params['first_name'], experimenter.firstName)
     self.assertEquals(params['middle_name'], experimenter.middleName)
     self.assertEquals(params['last_name'], experimenter.lastName)
     self.assertEquals(params['email'], experimenter.email)
     self.assertEquals(params['institution'], experimenter.institution)
     self.assert_(experimenter.isAdmin())
     self.assert_(experimenter.isActive())
     self.assertEquals(params['default_group'], experimenter.getDefaultGroup().id)
     self.assertEquals(sorted(params['other_groups']), sorted(otherGroupIds))
     
     # remove admin privilages and deactivate account 
     params = {
         "omename":"webadmin_test_admin %s" % uuid,
         "first_name":uuid,
         "middle_name": uuid,
         "last_name":uuid,
         "email":"*****@*****.**" % uuid,
         "institution":"Laboratory",
         "administrator": False,
         "active":False,
         "default_group":default_gid,
         "other_groups":[gid,default_gid],
         "password":"******",
         "confirmation":"123" 
     }
     request = fakeRequest(method="post", params=params)
     _updateExperimenter(request, conn, eid)
     
     # check if experimenter updated
     experimenter = conn.getObject("Experimenter", eid)
     otherGroupIds = [g.id for g in experimenter.getOtherGroups()]
     self.assertEquals(params['omename'], experimenter.omeName)
     self.assertEquals(params['first_name'], experimenter.firstName)
     self.assertEquals(params['middle_name'], experimenter.middleName)
     self.assertEquals(params['last_name'], experimenter.lastName)
     self.assertEquals(params['email'], experimenter.email)
     self.assertEquals(params['institution'], experimenter.institution)
     self.assert_(not experimenter.isAdmin())
     self.assert_(not experimenter.isActive())
     self.assertEquals(params['default_group'], experimenter.getDefaultGroup().id)
     self.assertEquals(sorted(params['other_groups']), sorted(otherGroupIds))
     
     
     try:
        self.loginAsUser(params['omename'], params['password'])
        self.fail('This user was deactivated. Login failure error!')
     except:
         pass
Exemple #20
0
 def test_createExperimenters(self):
     conn = self.rootconn
     uuid = conn._sessionUuid
     
     # private group
     params = {
         "name":"webadmin_test_group_private %s" % uuid,
         "description":"test group",
         "permissions":0
     }
     request = fakeRequest(method="post", params=params)
     gid = _createGroup(request, conn)
     
     params = {
         "omename":"webadmin_test_user %s" % uuid,
         "first_name":uuid,
         "middle_name": uuid,
         "last_name":uuid,
         "email":"*****@*****.**" % uuid,
         "institution":"Laboratory",
         "active":True,
         "default_group":gid,
         "other_groups":[gid],
         "password":"******",
         "confirmation":"123" 
     }
     request = fakeRequest(method="post", params=params)
     eid = _createExperimenter(request, conn)
     
     # check if experimenter created
     experimenter = conn.getObject("Experimenter", eid)
     otherGroupIds = [g.id for g in experimenter.getOtherGroups()]
     self.assertEquals(params['omename'], experimenter.omeName)
     self.assertEquals(params['first_name'], experimenter.firstName)
     self.assertEquals(params['middle_name'], experimenter.middleName)
     self.assertEquals(params['last_name'], experimenter.lastName)
     self.assertEquals(params['email'], experimenter.email)
     self.assertEquals(params['institution'], experimenter.institution)
     self.assert_(not experimenter.isAdmin())
     self.assertEquals(params['active'], experimenter.isActive())
     self.assertEquals(params['default_group'], experimenter.getDefaultGroup().id)
     self.assertEquals(sorted(params['other_groups']), sorted(otherGroupIds))
     
     params = {
         "omename":"webadmin_test_admin %s" % uuid,
         "first_name":uuid,
         "middle_name": uuid,
         "last_name":uuid,
         "email":"*****@*****.**" % uuid,
         "institution":"Laboratory",
         "administrator": True,
         "active":True,
         "default_group":gid,
         "other_groups":[0,gid],
         "password":"******",
         "confirmation":"123" 
     }
     request = fakeRequest(method="post", params=params)
     eid = _createExperimenter(request, conn)
     
     # check if experimenter created
     experimenter = conn.getObject("Experimenter", eid)
     otherGroupIds = [g.id for g in experimenter.getOtherGroups()]
     self.assertEquals(params['omename'], experimenter.omeName)
     self.assertEquals(params['first_name'], experimenter.firstName)
     self.assertEquals(params['middle_name'], experimenter.middleName)
     self.assertEquals(params['last_name'], experimenter.lastName)
     self.assertEquals(params['email'], experimenter.email)
     self.assertEquals(params['institution'], experimenter.institution)
     self.assertEquals(params['administrator'], experimenter.isAdmin())
     self.assertEquals(params['active'], experimenter.isActive())
     self.assertEquals(params['default_group'], experimenter.getDefaultGroup().id)
     self.assertEquals(sorted(params['other_groups']), sorted(otherGroupIds))
     
     params = {
         "omename":"webadmin_test_off %s" % uuid,
         "first_name":uuid,
         "middle_name": uuid,
         "last_name":uuid,
         "email":"*****@*****.**" % uuid,
         "institution":"Laboratory",
         "default_group":gid,
         "other_groups":[gid],
         "password":"******",
         "confirmation":"123" 
     }
     request = fakeRequest(method="post", params=params)
     eid = _createExperimenter(request, conn)
     
     # check if experimenter created
     experimenter = conn.getObject("Experimenter", eid)
     otherGroupIds = [g.id for g in experimenter.getOtherGroups()]
     self.assertEquals(params['omename'], experimenter.omeName)
     self.assertEquals(params['first_name'], experimenter.firstName)
     self.assertEquals(params['middle_name'], experimenter.middleName)
     self.assertEquals(params['last_name'], experimenter.lastName)
     self.assertEquals(params['email'], experimenter.email)
     self.assertEquals(params['institution'], experimenter.institution)
     self.assert_(not experimenter.isAdmin())
     self.assert_(not experimenter.isActive())
     self.assertEquals(params['default_group'], experimenter.getDefaultGroup().id)
     self.assertEquals(sorted(params['other_groups']), sorted(otherGroupIds))
Exemple #21
0
 def test_updateGroups(self):
     conn = self.rootconn
     uuid = conn._sessionUuid
     
     # default group - helper
     params = {
         "name":"webadmin_test_default %s" % uuid,
         "description":"test group default",
         "owners": [0L],
         "permissions":0
     }
     request = fakeRequest(method="post", params=params)
     default_gid = _createGroup(request, conn)
     
     # create new user
     params = {
         "omename":"webadmin_test_owner %s" % uuid,
         "first_name":uuid,
         "middle_name": uuid,
         "last_name":uuid,
         "email":"*****@*****.**" % uuid,
         "institution":"Laboratory",
         "active":True,
         "default_group":default_gid,
         "other_groups":[default_gid],
         "password":"******",
         "confirmation":"123" 
     }
     request = fakeRequest(method="post", params=params)
     eid = _createExperimenter(request, conn)
     
     # create new user2
     params = {
         "omename":"webadmin_test_member %s" % uuid,
         "first_name":uuid,
         "middle_name": uuid,
         "last_name":uuid,
         "email":"*****@*****.**" % uuid,
         "institution":"Laboratory",
         "active":True,
         "default_group":default_gid,
         "other_groups":[default_gid],
         "password":"******",
         "confirmation":"123" 
     }
     request = fakeRequest(method="post", params=params)
     eid2 = _createExperimenter(request, conn)
     
     # create private group
     params = {
         "name":"webadmin_test_group_private %s" % uuid,
         "description":"test group",
         "permissions":0
     }
     request = fakeRequest(method="post", params=params)
     gid = _createGroup(request, conn)
     
     # check if group created
     group = conn.getObject("ExperimenterGroup", gid)
     permissions = getActualPermissions(group)
     self.assertEquals(params['name'], group.name)
     self.assertEquals(params['description'], group.description)
     self.assertEquals(params['permissions'], permissions)
     
     # upgrade group to collaborative
     # read-only group and add new owner and members
     params = {
         "name":"webadmin_test_group_read-only %s" % uuid,
         "description":"test group changed",
         "owners": [eid],
         "members": [eid2],
         "permissions":1
     }
     request = fakeRequest(method="post", params=params)
     _updateGroup(request, conn, gid)
     
     # check if group updated
     group = conn.getObject("ExperimenterGroup", gid)
     ownerIds = [e.id for e in group.getOwners()]
     memberIds = [e.id for e in group.getMembers()]
     permissions = getActualPermissions(group)
     self.assertEquals(params['name'], group.name)
     self.assertEquals(params['description'], group.description)
     self.assertEquals(params['owners'], sorted(ownerIds))
     self.assertEquals(sorted(mergeLists(params['owners'], params['members'])), sorted(memberIds))
     self.assertEquals(params['permissions'], permissions)
     
     # upgrade group to collaborative
     # read-ann group and change owners and members
     params = {
         "name":"webadmin_test_group_read-only %s" % uuid,
         "description":"test group changed",
         "owners": [eid2],
         "members": [0,eid],
         "permissions":1
     }
     request = fakeRequest(method="post", params=params)
     _updateGroup(request, conn, gid)
     
     # check if group updated
     group = conn.getObject("ExperimenterGroup", gid)
     ownerIds = [e.id for e in group.getOwners()]
     memberIds = [e.id for e in group.getMembers()]
     permissions = getActualPermissions(group)
     self.assertEquals(params['name'], group.name)
     self.assertEquals(params['description'], group.description)
     self.assertEquals(params['owners'], sorted(ownerIds))
     self.assertEquals(sorted(mergeLists(params['owners'], params['members'])), sorted(memberIds))
     self.assertEquals(params['permissions'], permissions)
    def test_updateMembersOfGroup(self):
        conn = self.rootconn
        uuid = conn._sessionUuid
        
        # create group
        params = {
            "name":"webadmin_test_group_private %s" % uuid,
            "description":"test group",
            "owners": [0L],
            "permissions":0
        }
        request = fakeRequest(method="post", params=params)
        gid = _createGroup(request, conn)
        
        ######################################
        # default group - helper
        params = {
            "name":"webadmin_test_default %s" % uuid,
            "description":"test group default",
            "owners": [0L],
            "permissions":0
        }
        request = fakeRequest(method="post", params=params)
        default_gid = _createGroup(request, conn)
        
        # create two new users
        params = {
            "omename":"webadmin_test_user1 %s" % uuid,
            "first_name":uuid,
            "middle_name": uuid,
            "last_name":uuid,
            "email":"*****@*****.**" % uuid,
            "institution":"Laboratory",
            "active":True,
            "default_group":default_gid,
            "other_groups":[default_gid],
            "password":"******",
            "confirmation":"123" 
        }
        request = fakeRequest(method="post", params=params)
        eid1 = _createExperimenter(request, conn)
        
        # create few new users
        params = {
            "omename":"webadmin_test_user2 %s" % uuid,
            "first_name":uuid,
            "middle_name": uuid,
            "last_name":uuid,
            "email":"*****@*****.**" % uuid,
            "institution":"Laboratory",
            "active":True,
            "default_group":default_gid,
            "other_groups":[default_gid],
            "password":"******",
            "confirmation":"123" 
        }
        request = fakeRequest(method="post", params=params)
        eid2 = _createExperimenter(request, conn)
        # make other users a member of the group
        
        # add them to group
        params = {
            'available':[],
            'members':[0,eid1,eid2]
        }
        request = fakeRequest(method="post", params=params)
        
        controller = BaseGroup(conn, gid)
        controller.containedExperimenters()
        form = ContainedExperimentersForm(initial={'members':controller.members, 'available':controller.available})
        if not form.is_valid():
            #available = form.cleaned_data['available']
            available = request.POST.getlist('available')
            #members = form.cleaned_data['members']
            members = request.POST.getlist('members')
            controller.setMembersOfGroup(available, members)        
            
        # check if updated
        controller = BaseGroup(conn, gid)
        controller.containedExperimenters()        
        self.assertEquals(sorted(params['members']), sorted([e.id for e in controller.members]))

        # remove them from the group
        params = {
            'available':[eid1,eid2],
            'members':[0]
        }
        request = fakeRequest(method="post", params=params)
        
        controller = BaseGroup(conn, gid)
        controller.containedExperimenters()
        form = ContainedExperimentersForm(initial={'members':controller.members, 'available':controller.available})
        if not form.is_valid():
            #available = form.cleaned_data['available']
            available = request.POST.getlist('available')
            #members = form.cleaned_data['members']
            members = request.POST.getlist('members')
            controller.setMembersOfGroup(available, members)
            
        # check if updated
        controller = BaseGroup(conn, gid)
        controller.containedExperimenters()
        self.assertEquals(sorted(params['members']), sorted([e.id for e in controller.members]))