Exemple #1
0
    def test_users_projects(self):
        # Create objects to test relationship (many-to-many)
        u1 = model.User()
        u2 = model.User()
        p1 = model.Project()
        p1.members.append(u1)
        p1.members.append(u2)
        Session.add(p1)
        Session.commit()

        # Get user objects now that they should have associated projects
        u1_ = Session.query(model.User).filter_by(id=u1.id).one()
        u2_ = Session.query(model.User).filter_by(id=u2.id).one()

        # Test that relationship to project exists
        assert u1_.projects == [p1]
        assert u2_.projects == [p1]

        # Now delete the project
        Session.delete(p1)
        Session.commit()

        # Verify that relationship no longer exists
        # (ie. users_projects_table entry has been removed)
        assert u1_.projects == []
        assert u2_.projects == []

        # Let's clean up
        Session.delete(u1)
        Session.delete(u2)
        Session.commit()
    def test_get_project_member_ids(self):
        """ Return list of member ids

        Method takes a project id and returns should returns a
        list of user ids participating in the project.

        """

        u1 = model.User()
        u2 = model.User()
        u3 = model.User()
        p1 = model.Project()

        p1.members.extend([u1, u2, u3])
        Session.add(u1)
        Session.add(u2)
        Session.add(u3)
        Session.add(p1)
        Session.commit()

        member_id_list = cg._get_project_member_ids(p1.id)
        assert member_id_list == [u1.id, u2.id, u3.id]

        # Clean up
        Session.delete(u1)
        Session.delete(u2)
        Session.delete(u3)
        Session.delete(p1)
        Session.commit()
Exemple #3
0
    def create_account_handler(self):
        '''
        Note that the verification goes on in model/form.py.
        '''
        # create the new user; post to db via sqlalchemy
        new_user = model.User()
        new_user.username = request.params['username']
        new_user.fullname = " ".join(
            [request.params['first_name'], request.params['last_name']])
        new_user.experience = request.params['experience']
        new_user._set_password(request.params['password'])
        new_user.email = request.params['email']

        # These are for citation settings,
        # initialized to True to make everything in the citation visible by default.
        new_user.show_journal = True
        new_user.show_authors = True
        new_user.show_keywords = True

        Session.add(new_user)
        Session.commit()

        # send out an email
        greeting_message = """
            Hi, %s.\n

            Thanks for signing up at abstrackr (%s). You
            should be able to sign up now with username %s (only you know your password).

            This is just a welcome email to say hello, and that we've got your email.
            Should you ever need to reset your password, we'll send you instructions
            to this email. In the meantime, happy screening!

            -- The Brown EPC.
        """ % (new_user.fullname, url('/', qualified=True), new_user.username)

        try:
            self.send_email_to_user(new_user, "welcome to abstrackr",
                                    greeting_message)
        except:
            # this almost certainly means we're on our Windows dev box :)
            pass

        ###
        # log this user in programmatically (issue #28)
        rememberer = request.environ['repoze.who.plugins']['cookie']
        identity = {'repoze.who.userid': new_user.username}
        response.headerlist = response.headerlist + \
            rememberer.remember(request.environ, identity)
        rememberer.remember(request.environ, identity)

        # if they were originally trying to join a review prior to
        # registering, then join them now. (issue #8).
        if 'then_join' in request.params and request.params['then_join'] != '':
            redirect(
                url(controller="review",
                    action="join",
                    review_code=request.params['then_join']))
        else:
            redirect(url(controller="account", action="login"))