当前位置: 首页>>代码示例>>Python>>正文


Python dao.get_user_by_name函数代码示例

本文整理汇总了Python中tvb.core.entities.storage.dao.get_user_by_name函数的典型用法代码示例。如果您正苦于以下问题:Python get_user_by_name函数的具体用法?Python get_user_by_name怎么用?Python get_user_by_name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_user_by_name函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_get_users_for_project

 def test_get_users_for_project(self):
     """
     Get all members of a project except the current user.
     """
     user_1 = model.User("test_user1", "test_pass", "[email protected]", False, "user")
     dao.store_entity(user_1)
     user_2 = model.User("test_user2", "test_pass", "[email protected]", False, "user")
     dao.store_entity(user_2)
     user_3 = model.User("test_user3", "test_pass", "[email protected]", False, "user")
     dao.store_entity(user_3)
     user_4 = model.User("test_user4", "test_pass", "[email protected]", False, "user")
     dao.store_entity(user_4)
     user_5 = model.User("test_user5", "test_pass", "[email protected]", False, "user")
     dao.store_entity(user_5)
     admin = dao.get_user_by_name("test_user1")
     member1 = dao.get_user_by_name("test_user2")
     member2 = dao.get_user_by_name("test_user5")
     data = dict(name="test_proj", description="test_desc", users=[member1.id, member2.id])
     project = ProjectService().store_project(admin, True, None, **data)
     all_users, members, pag = self.user_service.get_users_for_project(admin.username, project.id)
     assert len(members) == 2, "More members than there should be."
     assert len(all_users) == 5, "Admin should not be viewed as member. " \
                                 "Neither should users that were not part of the project's users list."
     assert pag == 1, "Invalid total pages number."
     for user in all_users:
         assert user.username != admin.username, "Admin is in members!"
开发者ID:maedoc,项目名称:tvb-framework,代码行数:26,代码来源:user_service_test.py

示例2: generate_users

 def generate_users(nr_users, nr_projects):
     """
     The generate_users method will create a clean state db with
     :param nr_users: number of users to be generated (with random roles between
                             CLINICIAN and RESEARCHER and random validated state)
     :param nr_projects: maximum number of projects to be generated for each user
     """
     users = []
     
     for i in range(nr_users):
         coin_flip = random.randint(0, 1)
         role = 'CLINICIAN' if coin_flip == 1 else 'RESEARCHER'
         password = md5("test").hexdigest()
         new_user = model.User("gen" + str(i), password, "[email protected]", True, role)
         dao.store_entity(new_user)
         new_user = dao.get_user_by_name("gen" + str(i))
         ExtremeTestFactory.VALIDATION_DICT[new_user.id] = 0
         users.append(new_user)
         
     for i in range(nr_users):
         current_user = dao.get_user_by_name("gen" + str(i))
         projects_for_user = random.randint(0, nr_projects)
         for j in range(projects_for_user):         
             data = dict(name='GeneratedProject' + str(i) + '_' + str(j),
                         description='test_desc',
                         users=ExtremeTestFactory.get_users_ids(random.randint(0, nr_users - 3),
                                                                nr_users, current_user.id, users))
             ProjectService().store_project(current_user, True, None, **data)
             ExtremeTestFactory.VALIDATION_DICT[current_user.id] += 1 
开发者ID:maedoc,项目名称:tvb-framework,代码行数:29,代码来源:factory.py

示例3: test_reset_password_happy_flow

 def test_reset_password_happy_flow(self):
     """
     Test method for the reset password method. Happy flow.
     """
     data = dict(username="test_user", password=md5("test_password").hexdigest(),
                 email="[email protected]", role="user", comment="")
     self.user_service.create_user(**data)
     inserted_user = dao.get_user_by_name("test_user")
     assert inserted_user.password == md5("test_password").hexdigest(), "Incorrect password"
     reset_pass_data = dict(username="test_user", email="[email protected]")
     self.user_service.reset_password(**reset_pass_data)
     inserted_user = dao.get_user_by_name("test_user")
     assert inserted_user.password != md5("test_password"), "Password not reset for some reason!"
开发者ID:maedoc,项目名称:tvb-framework,代码行数:13,代码来源:user_service_test.py

示例4: test_edit_user_happy_flow

 def test_edit_user_happy_flow(self):
     """
     Test the method of editing a user.
     """
     data = dict(username="test_user", password=md5("test_password").hexdigest(),
                 email="[email protected]", role="user", comment="")
     self.user_service.create_user(**data)
     inserted_user = dao.get_user_by_name("test_user")
     assert inserted_user.password == md5("test_password").hexdigest(), "Incorrect password"
     inserted_user.role = "new_role"
     inserted_user.validated = 1
     self.user_service.edit_user(inserted_user)
     changed_user = dao.get_user_by_name("test_user")
     assert changed_user.role == "new_role", "role unchanged"
     assert changed_user.validated == 1, "user not validated"
开发者ID:maedoc,项目名称:tvb-framework,代码行数:15,代码来源:user_service_test.py

示例5: test_retrieve_projects_random

    def test_retrieve_projects_random(self):
        """
        Generate a large number of users/projects, and validate the results.
        """
        ExtremeTestFactory.generate_users(NR_USERS, MAX_PROJ_PER_USER)
        for i in range(NR_USERS):
            current_user = dao.get_user_by_name("gen" + str(i))
            expected_projects = ExtremeTestFactory.VALIDATION_DICT[current_user.id]
            if expected_projects % PROJECTS_PAGE_SIZE == 0:
                expected_pages = expected_projects / PROJECTS_PAGE_SIZE
                exp_proj_per_page = PROJECTS_PAGE_SIZE
            else:
                expected_pages = expected_projects / PROJECTS_PAGE_SIZE + 1
                exp_proj_per_page = expected_projects % PROJECTS_PAGE_SIZE
            if expected_projects == 0:
                expected_pages = 0
                exp_proj_per_page = 0
            projects, pages = self.project_service.retrieve_projects_for_user(current_user.id, expected_pages)
            self.assertEqual(len(projects), exp_proj_per_page, "Projects not retrieved properly! Expected:" +
                             str(exp_proj_per_page) + "but got:" + str(len(projects)))
            self.assertEqual(pages, expected_pages, "Pages not retrieved properly!")

        for folder in os.listdir(TvbProfile.current.TVB_STORAGE):
            full_path = os.path.join(TvbProfile.current.TVB_STORAGE, folder)
            if os.path.isdir(full_path) and folder.startswith('Generated'): 
                shutil.rmtree(full_path)
开发者ID:sdiazpier,项目名称:tvb-framework,代码行数:26,代码来源:project_service_test.py

示例6: test_get_users_second_page_del

    def test_get_users_second_page_del(self):
        """
        Try to get the second page of users for a given project where only one user on last page.
        Then delete that user.
        """
        for i in range(USERS_PAGE_SIZE + 1):
            exec 'user_' + str(i) + '= model.User("test_user' + str(i) + \
                 '", "test_pass", "[email protected]", False, "user")'
            exec "dao.store_entity(user_" + str(i) + ")"
        for i in range(USERS_PAGE_SIZE + 1):
            exec 'member' + str(i) + '=dao.get_user_by_name("test_user' + str(i) + '")'

        admin = dao.get_user_by_name("test_user1")
        data = dict(name='test_proj', description='test_desc',
                    users=[eval('member' + str(i) + '.id') for i in range(USERS_PAGE_SIZE + 1)])
        project = ProjectService().store_project(admin, True, None, **data)
        page_users, all_users, pag = self.user_service.get_users_for_project(admin.username, project.id, 2)
        assert len(page_users) == 1, 'Paging not working properly'
        assert len(all_users) == USERS_PAGE_SIZE + 1, 'Not all members returned'
        assert pag == 2, 'Invalid page number returned'
        self.user_service.delete_user(member2.id)
        page_users, all_users, pag = self.user_service.get_users_for_project(admin.username, project.id, 2)
        assert len(page_users) == 0, 'Paging not working properly'
        assert len(all_users) == USERS_PAGE_SIZE, 'Not all members returned'
        assert pag == 1, 'Invalid page number returned'
        page_users, all_users, pag = self.user_service.get_users_for_project(admin.username, project.id, 1)
        assert len(page_users) == USERS_PAGE_SIZE, 'Paging not working properly'
        assert len(all_users) == USERS_PAGE_SIZE, 'Not all members returned'
        assert pag == 1, 'Invalid page number returned'
开发者ID:maedoc,项目名称:tvb-framework,代码行数:29,代码来源:user_service_test.py

示例7: test_validate_invalid

 def test_validate_invalid(self):
     """
     Pass a valid user and test that it is actually validate.
     """
     unexisting = dao.get_user_by_name("should-not-exist")
     self.assertTrue(unexisting is None, "This user should not exist")
     self._expect_redirect('/tvb', self.user_c.validate, "should-not-exist")
     self.assertTrue(cherrypy.session[common.KEY_MESSAGE_TYPE] == common.TYPE_ERROR)
开发者ID:unimauro,项目名称:tvb-framework,代码行数:8,代码来源:users_controller_test.py

示例8: test_change_password_happy_flow

 def test_change_password_happy_flow(self):
     """
     Test method for the change password method. Happy flow.
     """
     inserted_user = self._prepare_user_for_change_pwd()
     self.user_service.edit_user(inserted_user, md5("test_password").hexdigest())
     changed_user = dao.get_user_by_name("test_user")
     assert changed_user.password == md5("new_test_password").hexdigest(), "The password did not change."
开发者ID:maedoc,项目名称:tvb-framework,代码行数:8,代码来源:user_service_test.py

示例9: check_login

 def check_login(username, password):
     """
     Service layer to check if given UserName and Password are according to DB.
     """
     user = dao.get_user_by_name(username)
     if user is not None and user.password == md5(password).hexdigest() and user.validated:
         return user
     else:
         return None
开发者ID:sdiazpier,项目名称:tvb-framework,代码行数:9,代码来源:user_service.py

示例10: _prepare_user_for_change_pwd

 def _prepare_user_for_change_pwd(self):
     """Private method to prepare password change operation"""
     data = dict(username="test_user", password=md5("test_password").hexdigest(),
                 email="[email protected]", role="user", comment="")
     self.user_service.create_user(**data)
     self.user_service.validate_user("test_user")
     inserted_user = dao.get_user_by_name("test_user")
     assert inserted_user.password == md5("test_password").hexdigest(), "The password inserted is not correct."
     inserted_user.password = md5('new_test_password').hexdigest()
     return inserted_user
开发者ID:maedoc,项目名称:tvb-framework,代码行数:10,代码来源:user_service_test.py

示例11: test_change_password_wrong_old

 def test_change_password_wrong_old(self):
     """
     Test method for the change password method. Old password is wrong, should return false.
     """
     inserted_user = self._prepare_user_for_change_pwd()
     params = dict(edited_user=inserted_user, old_password=md5("wrong_old_pwd").hexdigest())
     with pytest.raises(UsernameException):
         self.user_service.edit_user(**params)
     user = dao.get_user_by_name("test_user")
     assert user.password == md5("test_password").hexdigest(), "The password should have not been changed!"
开发者ID:maedoc,项目名称:tvb-framework,代码行数:10,代码来源:user_service_test.py

示例12: test_reset_pass_wrong_email

 def test_reset_pass_wrong_email(self):
     """
     Test method for the reset password method. Email is not valid, 
     should raise exception
     """
     data = dict(username="test_user", password=md5("test_password").hexdigest(),
                 email="[email protected]", role="user", comment="")
     self.user_service.create_user(**data)
     inserted_user = dao.get_user_by_name("test_user")
     self.assertEqual(inserted_user.password, md5("test_password").hexdigest(), "Incorrect password")
     reset_pass_data = dict(username="test_user", email="[email protected]")
     self.assertRaises(UsernameException, self.user_service.reset_password, **reset_pass_data)
开发者ID:LauHoiYanGladys,项目名称:tvb-framework,代码行数:12,代码来源:user_service_test.py

示例13: test_usermanagement_post_valid

 def test_usermanagement_post_valid(self):
     """
     Create a valid post and check that user is created.
     """
     self.test_user.role = "ADMINISTRATOR"
     self.test_user = dao.store_entity(self.test_user)
     cherrypy.session[common.KEY_USER] = self.test_user
     TestFactory.create_user(username="to_be_deleted")
     TestFactory.create_user(username="to_validate", validated=False)
     user_before_delete = dao.get_user_by_name("to_be_deleted")
     self.assertTrue(user_before_delete is not None)
     user_before_validation = dao.get_user_by_name("to_validate")
     self.assertFalse(user_before_validation.validated)
     data = {"delete_%i" % user_before_delete.id: True,
             "role_%i" % user_before_validation.id: "ADMINISTRATOR",
             "validate_%i" % user_before_validation.id: True}
     self.user_c.usermanagement(do_persist=True, **data)
     user_after_delete = dao.get_user_by_id(user_before_delete.id)
     self.assertTrue(user_after_delete is None, "User should be deleted.")
     user_after_validation = dao.get_user_by_id(user_before_validation.id)
     self.assertTrue(user_after_validation.validated, "User should be validated now.")
     self.assertTrue(user_after_validation.role == "ADMINISTRATOR", "Role has not changed.")
开发者ID:unimauro,项目名称:tvb-framework,代码行数:22,代码来源:users_controller_test.py

示例14: test_validate_valid

 def test_validate_valid(self):
     """
     Pass a valid user and test that it is actually validate.
     """
     self.test_user.role = "ADMINISTRATOR"
     self.test_user = dao.store_entity(self.test_user)
     cherrypy.session[common.KEY_USER] = self.test_user
     TestFactory.create_user(username="to_validate", validated=False)
     user_before_validation = dao.get_user_by_name("to_validate")
     self.assertFalse(user_before_validation.validated)
     self._expect_redirect('/tvb', self.user_c.validate, user_before_validation.username)
     user_after_validation = dao.get_user_by_id(user_before_validation.id)
     self.assertTrue(user_after_validation.validated, "User should be validated.")
     self.assertTrue(cherrypy.session[common.KEY_MESSAGE_TYPE] == common.TYPE_INFO)
开发者ID:unimauro,项目名称:tvb-framework,代码行数:14,代码来源:users_controller_test.py

示例15: test_create_new_valid_post

 def test_create_new_valid_post(self):
     """
     Test that a valid create new post will actually create a new user in database.
     """
     data = dict(username="registered_user",
                 password="pass",
                 password2="pass",
                 email="[email protected]",
                 comment="This is some dummy comment",
                 role="CLINICIAN")
     cherrypy.request.method = "POST"
     self._expect_redirect('/user/usermanagement', self.user_c.create_new, **data)
     created_user = dao.get_user_by_name("registered_user")
     self.assertTrue(created_user is not None, "Should have a new user created.")
开发者ID:unimauro,项目名称:tvb-framework,代码行数:14,代码来源:users_controller_test.py


注:本文中的tvb.core.entities.storage.dao.get_user_by_name函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。