예제 #1
0
def fixture_add_user(username=u'chris',
                     password=u'toast',
                     privileges=[],
                     wants_comment_notification=True):
    # Reuse existing user or create a new one
    test_user = User.query.filter_by(username=username).first()
    if test_user is None:
        test_user = User()
    test_user.username = username
    test_user.email = username + u'@example.com'
    if password is not None:
        test_user.pw_hash = gen_password_hash(password)
    test_user.wants_comment_notification = wants_comment_notification
    for privilege in privileges:
        query = Privilege.query.filter(Privilege.privilege_name == privilege)
        if query.count():
            test_user.all_privileges.append(query.one())

    test_user.save()
    # Reload
    test_user = User.query.filter_by(username=username).first()

    # ... and detach from session:
    Session.expunge(test_user)

    return test_user
def fixture_add_comment_report(comment=None, reported_user=None,
        reporter=None, created=None, report_content=None):
    if comment is None:
        comment = fixture_add_comment()

    if reported_user is None:
        reported_user = fixture_add_user()

    if reporter is None:
        reporter = fixture_add_user()

    if created is None:
        created=datetime.now()

    if report_content is None:
        report_content = \
            'Auto-generated test report'

    comment_report = CommentReport(comment=comment,
        reported_user = reported_user,
        reporter = reporter,
        created = created,
        report_content=report_content)

    comment_report.save()

    Session.expunge(comment_report)

    return comment_report
예제 #3
0
def fixture_add_user(username=u'chris',
                     password=u'toast',
                     active_user=True,
                     wants_comment_notification=True):
    # Reuse existing user or create a new one
    test_user = User.query.filter_by(username=username).first()
    if test_user is None:
        test_user = User()
    test_user.username = username
    test_user.email = username + u'@example.com'
    if password is not None:
        test_user.pw_hash = gen_password_hash(password)
    if active_user:
        test_user.email_verified = True
        test_user.status = u'active'

    test_user.wants_comment_notification = wants_comment_notification

    test_user.save()

    # Reload
    test_user = User.query.filter_by(username=username).first()

    # ... and detach from session:
    Session.expunge(test_user)

    return test_user
예제 #4
0
def fixture_add_comment_report(comment=None,
                               reported_user=None,
                               reporter=None,
                               created=None,
                               report_content=None):
    if comment is None:
        comment = fixture_add_comment()

    if reported_user is None:
        reported_user = fixture_add_user()

    if reporter is None:
        reporter = fixture_add_user()

    if created is None:
        created = datetime.now()

    if report_content is None:
        report_content = \
            'Auto-generated test report'

    comment_report = CommentReport(comment=comment,
                                   reported_user=reported_user,
                                   reporter=reporter,
                                   created=created,
                                   report_content=report_content)

    comment_report.save()

    Session.expunge(comment_report)

    return comment_report
예제 #5
0
def fixture_add_user(username=u'chris', password=u'toast',
                     active_user=True, wants_comment_notification=True):
    # Reuse existing user or create a new one
    test_user = User.query.filter_by(username=username).first()
    if test_user is None:
        test_user = User()
    test_user.username = username
    test_user.email = username + u'@example.com'
    if password is not None:
        test_user.pw_hash = gen_password_hash(password)
    if active_user:
        test_user.email_verified = True
        test_user.status = u'active'

    test_user.wants_comment_notification = wants_comment_notification

    test_user.save()

    # Reload
    test_user = User.query.filter_by(username=username).first()

    # ... and detach from session:
    Session.expunge(test_user)

    return test_user
예제 #6
0
파일: tools.py 프로젝트: ausbin/mediagoblin
def fixture_add_comment(author=None, media_entry=None, comment=None):
    if author is None:
        author = fixture_add_user().id

    if media_entry is None:
        media_entry = fixture_media_entry()

    if comment is None:
        comment = \
            'Auto-generated test comment by user #{0} on media #{0}'.format(
                author, media_entry)

    text_comment = TextComment(
        actor=author,
        content=comment
    )
    text_comment.save()

    comment_link = Comment()
    comment_link.target = media_entry
    comment_link.comment = text_comment
    comment_link.save()

    Session.expunge(comment_link)

    return text_comment
예제 #7
0
파일: tools.py 프로젝트: ausbin/mediagoblin
def fixture_add_collection(name=u"My first Collection", user=None,
                           collection_type=Collection.USER_DEFINED_TYPE):
    if user is None:
        user = fixture_add_user()
    coll = Collection.query.filter_by(
        actor=user.id,
        title=name,
        type=collection_type
    ).first()
    if coll is not None:
        return coll
    coll = Collection()
    coll.actor = user.id
    coll.title = name
    coll.type = collection_type
    coll.generate_slug()
    coll.save()

    # Reload
    Session.refresh(coll)

    # ... and detach from session:
    Session.expunge(coll)

    return coll
예제 #8
0
파일: tools.py 프로젝트: ausbin/mediagoblin
def fixture_add_user(username=u'chris', password=u'toast',
                     privileges=[], wants_comment_notification=True):
    # Reuse existing user or create a new one
    test_user = LocalUser.query.filter(LocalUser.username==username).first()
    if test_user is None:
        test_user = LocalUser()
    test_user.username = username
    test_user.email = username + u'@example.com'
    if password is not None:
        test_user.pw_hash = gen_password_hash(password)
    test_user.wants_comment_notification = wants_comment_notification
    for privilege in privileges:
        query = Privilege.query.filter(Privilege.privilege_name==privilege)
        if query.count():
            test_user.all_privileges.append(query.one())

    test_user.save()

    # Reload - The `with_polymorphic` needs to be there to eagerly load
    # the attributes on the LocalUser as this can't be done post detachment.
    user_query = LocalUser.query.with_polymorphic(LocalUser)
    test_user = user_query.filter(LocalUser.username==username).first()

    # ... and detach from session:
    Session.expunge(test_user)

    return test_user
예제 #9
0
def fixture_add_user(username=u'chris',
                     password=u'toast',
                     privileges=[],
                     wants_comment_notification=True):
    # Reuse existing user or create a new one
    test_user = LocalUser.query.filter(LocalUser.username == username).first()
    if test_user is None:
        test_user = LocalUser()
    test_user.username = username
    test_user.email = username + u'@example.com'
    if password is not None:
        test_user.pw_hash = gen_password_hash(password)
    test_user.wants_comment_notification = wants_comment_notification
    for privilege in privileges:
        query = Privilege.query.filter(Privilege.privilege_name == privilege)
        if query.count():
            test_user.all_privileges.append(query.one())

    test_user.save()

    # Reload - The `with_polymorphic` needs to be there to eagerly load
    # the attributes on the LocalUser as this can't be done post detachment.
    user_query = LocalUser.query.with_polymorphic(LocalUser)
    test_user = user_query.filter(LocalUser.username == username).first()

    # ... and detach from session:
    Session.expunge(test_user)

    return test_user
예제 #10
0
    def _test_authentication():
        template.clear_test_template_context()
        res = ldap_plugin_app.post(
            '/auth/ldap/login/',
            {'username': u'chris',
             'password': u'toast'})

        context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
        register_form = context['register_form']

        assert register_form.username.data == u'chris'
        assert register_form.email.data == u'*****@*****.**'

        template.clear_test_template_context()
        res = ldap_plugin_app.post(
            '/auth/ldap/register/',
            {'username': u'chris',
             'email': u'*****@*****.**'})
        res.follow()

        assert urlparse.urlsplit(res.location)[2] == '/u/chris/'
        assert 'mediagoblin/user_pages/user.html' in template.TEMPLATE_TEST_CONTEXT

        # Try to register with same email and username
        template.clear_test_template_context()
        res = ldap_plugin_app.post(
            '/auth/ldap/register/',
            {'username': u'chris',
             'email': u'*****@*****.**'})

        context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
        register_form = context['register_form']

        assert register_form.email.errors == [u'Sorry, a user with that email address already exists.']
        assert register_form.username.errors == [u'Sorry, a user with that name already exists.']

        # Log out
        ldap_plugin_app.get('/auth/logout/')

        # Get user and detach from session
        test_user = mg_globals.database.User.query.filter_by(
            username=u'chris').first()
        Session.expunge(test_user)

        # Log back in
        template.clear_test_template_context()
        res = ldap_plugin_app.post(
            '/auth/ldap/login/',
            {'username': u'chris',
             'password': u'toast'})
        res.follow()

        assert urlparse.urlsplit(res.location)[2] == '/'
        assert 'mediagoblin/root.html' in template.TEMPLATE_TEST_CONTEXT

        # Make sure user is in the session
        context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
        session = context['request'].session
        assert session['user_id'] == unicode(test_user.id)
예제 #11
0
    def _test_authentication():
        template.clear_test_template_context()
        res = ldap_plugin_app.post(
            '/auth/ldap/login/',
            {'username': u'chris',
             'password': u'toast'})

        context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
        register_form = context['register_form']

        assert register_form.username.data == u'chris'
        assert register_form.email.data == u'*****@*****.**'

        template.clear_test_template_context()
        res = ldap_plugin_app.post(
            '/auth/ldap/register/',
            {'username': u'chris',
             'email': u'*****@*****.**'})
        res.follow()

        assert urlparse.urlsplit(res.location)[2] == '/u/chris/'
        assert 'mediagoblin/user_pages/user_nonactive.html' in template.TEMPLATE_TEST_CONTEXT

        # Try to register with same email and username
        template.clear_test_template_context()
        res = ldap_plugin_app.post(
            '/auth/ldap/register/',
            {'username': u'chris',
             'email': u'*****@*****.**'})

        context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
        register_form = context['register_form']

        assert register_form.email.errors == [u'Sorry, a user with that email address already exists.']
        assert register_form.username.errors == [u'Sorry, a user with that name already exists.']

        # Log out
        ldap_plugin_app.get('/auth/logout/')

        # Get user and detach from session
        test_user = mg_globals.database.User.query.filter_by(
            username=u'chris').first()
        Session.expunge(test_user)

        # Log back in
        template.clear_test_template_context()
        res = ldap_plugin_app.post(
            '/auth/ldap/login/',
            {'username': u'chris',
             'password': u'toast'})
        res.follow()

        assert urlparse.urlsplit(res.location)[2] == '/'
        assert 'mediagoblin/root.html' in template.TEMPLATE_TEST_CONTEXT

        # Make sure user is in the session
        context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
        session = context['request'].session
        assert session['user_id'] == unicode(test_user.id)
예제 #12
0
    def user_upload_limits(self, uploaded=None, upload_limit=None):
        our_user = self.our_user()

        if uploaded:
            our_user.uploaded = uploaded
        if upload_limit:
            our_user.upload_limit = upload_limit

        our_user.save()
        Session.expunge(our_user)
예제 #13
0
    def user_upload_limits(self, uploaded=None, upload_limit=None):
        our_user = self.our_user()

        if uploaded:
            our_user.uploaded = uploaded
        if upload_limit:
            our_user.upload_limit = upload_limit

        our_user.save()
        Session.expunge(our_user)
예제 #14
0
def fixture_add_comment_notification(entry_id, subject_id, user_id,
                                     seen=False):
    cn = CommentNotification(user_id=user_id,
                             seen=seen,
                             subject_id=subject_id)
    cn.save()

    cn = CommentNotification.query.filter_by(id=cn.id).first()

    Session.expunge(cn)

    return cn
예제 #15
0
def fixture_add_comment_notification(entry_id,
                                     subject_id,
                                     user_id,
                                     seen=False):
    cn = CommentNotification(user_id=user_id, seen=seen, subject_id=subject_id)
    cn.save()

    cn = CommentNotification.query.filter_by(id=cn.id).first()

    Session.expunge(cn)

    return cn
예제 #16
0
        def _test_new_user():
            openid_plugin_app.post('/auth/openid/login/',
                                   {'openid': u'http://real.myopenid.com'})

            # Right place?
            assert 'mediagoblin/auth/register.html' in template.TEMPLATE_TEST_CONTEXT
            context = template.TEMPLATE_TEST_CONTEXT[
                'mediagoblin/auth/register.html']
            register_form = context['register_form']

            # Register User
            res = openid_plugin_app.post(
                '/auth/openid/register/', {
                    'openid': register_form.openid.data,
                    'username': u'chris',
                    'email': u'*****@*****.**'
                })
            res.follow()

            # Correct place?
            assert urlparse.urlsplit(res.location)[2] == '/u/chris/'
            assert 'mediagoblin/user_pages/user_nonactive.html' in template.TEMPLATE_TEST_CONTEXT

            # No need to test if user is in logged in and verification email
            # awaits, since openid uses the register_user function which is
            # tested in test_auth

            # Logout User
            openid_plugin_app.get('/auth/logout')

            # Get user and detach from session
            test_user = mg_globals.database.LocalUser.query.filter(
                LocalUser.username == u'chris').first()
            Session.expunge(test_user)

            # Log back in
            # Could not get it to work by 'POST'ing to /auth/openid/login/
            template.clear_test_template_context()
            res = openid_plugin_app.post(
                '/auth/openid/login/finish/',
                {'openid': u'http://real.myopenid.com'})
            res.follow()

            assert urlparse.urlsplit(res.location)[2] == '/'
            assert 'mediagoblin/root.html' in template.TEMPLATE_TEST_CONTEXT

            # Make sure user is in the session
            context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
            session = context['request'].session
            assert session['user_id'] == six.text_type(test_user.id)
예제 #17
0
        def _test_new_user():
            openid_plugin_app.post(
                '/auth/openid/login/', {
                    'openid': u'http://real.myopenid.com'})

            # Right place?
            assert 'mediagoblin/auth/register.html' in template.TEMPLATE_TEST_CONTEXT
            context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
            register_form = context['register_form']

            # Register User
            res = openid_plugin_app.post(
                '/auth/openid/register/', {
                    'openid': register_form.openid.data,
                    'username': u'chris',
                    'email': u'*****@*****.**'})
            res.follow()

            # Correct place?
            assert urlparse.urlsplit(res.location)[2] == '/u/chris/'
            assert 'mediagoblin/user_pages/user_nonactive.html' in template.TEMPLATE_TEST_CONTEXT

            # No need to test if user is in logged in and verification email
            # awaits, since openid uses the register_user function which is
            # tested in test_auth

            # Logout User
            openid_plugin_app.get('/auth/logout')

            # Get user and detach from session
            test_user = mg_globals.database.LocalUser.query.filter(
                LocalUser.username==u'chris'
            ).first()
            Session.expunge(test_user)

            # Log back in
            # Could not get it to work by 'POST'ing to /auth/openid/login/
            template.clear_test_template_context()
            res = openid_plugin_app.post(
                '/auth/openid/login/finish/', {
                    'openid': u'http://real.myopenid.com'})
            res.follow()

            assert urlparse.urlsplit(res.location)[2] == '/'
            assert 'mediagoblin/root.html' in template.TEMPLATE_TEST_CONTEXT

            # Make sure user is in the session
            context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
            session = context['request'].session
            assert session['user_id'] == six.text_type(test_user.id)
    def user_upload_limits(self, uploaded=None, upload_limit=None):
        if uploaded:
            self.test_user.uploaded = uploaded
        if upload_limit:
            self.test_user.upload_limit = upload_limit

        self.test_user.save()

        # Reload
        self.test_user = User.query.filter_by(
            username=self.test_user.username
        ).first()

        # ... and detach from session:
        Session.expunge(self.test_user)
예제 #19
0
def fixture_media_entry(title=u"Some title",
                        slug=None,
                        uploader=None,
                        save=True,
                        gen_slug=True,
                        state=u'unprocessed',
                        fake_upload=True,
                        expunge=True):
    """
    Add a media entry for testing purposes.

    Caution: if you're adding multiple entries with fake_upload=True,
    make sure you save between them... otherwise you'll hit an
    IntegrityError from multiple newly-added-MediaEntries adding
    FileKeynames at once.  :)
    """
    if uploader is None:
        uploader = fixture_add_user().id

    entry = MediaEntry()
    entry.title = title
    entry.slug = slug
    entry.uploader = uploader
    entry.media_type = u'image'
    entry.state = state

    if fake_upload:
        entry.media_files = {
            'thumb': ['a', 'b', 'c.jpg'],
            'medium': ['d', 'e', 'f.png'],
            'original': ['g', 'h', 'i.png']
        }
        entry.media_type = u'mediagoblin.media_types.image'

    if gen_slug:
        entry.generate_slug()

    if save:
        entry.save()

    if expunge:
        entry = MediaEntry.query.filter_by(id=entry.id).first()

        Session.expunge(entry)

    return entry
예제 #20
0
def fixture_comment_subscription(entry, notify=True, send_email=None):
    if send_email is None:
        uploader = User.query.filter_by(id=entry.uploader).first()
        send_email = uploader.wants_comment_notification

    cs = CommentSubscription(media_entry_id=entry.id,
                             user_id=entry.uploader,
                             notify=notify,
                             send_email=send_email)

    cs.save()

    cs = CommentSubscription.query.filter_by(id=cs.id).first()

    Session.expunge(cs)

    return cs
예제 #21
0
def fixture_comment_subscription(entry, notify=True, send_email=None):
    if send_email is None:
        uploader = User.query.filter_by(id=entry.uploader).first()
        send_email = uploader.wants_comment_notification

    cs = CommentSubscription(
        media_entry_id=entry.id,
        user_id=entry.uploader,
        notify=notify,
        send_email=send_email)

    cs.save()

    cs = CommentSubscription.query.filter_by(id=cs.id).first()

    Session.expunge(cs)

    return cs
예제 #22
0
        def _test_new_user():
            openid_plugin_app.post("/auth/openid/login/", {"openid": u"http://real.myopenid.com"})

            # Right place?
            assert "mediagoblin/auth/register.html" in template.TEMPLATE_TEST_CONTEXT
            context = template.TEMPLATE_TEST_CONTEXT["mediagoblin/auth/register.html"]
            register_form = context["register_form"]

            # Register User
            res = openid_plugin_app.post(
                "/auth/openid/register/",
                {"openid": register_form.openid.data, "username": u"chris", "email": u"*****@*****.**"},
            )
            res.follow()

            # Correct place?
            assert urlparse.urlsplit(res.location)[2] == "/u/chris/"
            assert "mediagoblin/user_pages/user.html" in template.TEMPLATE_TEST_CONTEXT

            # No need to test if user is in logged in and verification email
            # awaits, since openid uses the register_user function which is
            # tested in test_auth

            # Logout User
            openid_plugin_app.get("/auth/logout")

            # Get user and detach from session
            test_user = mg_globals.database.User.query.filter_by(username=u"chris").first()
            Session.expunge(test_user)

            # Log back in
            # Could not get it to work by 'POST'ing to /auth/openid/login/
            template.clear_test_template_context()
            res = openid_plugin_app.post("/auth/openid/login/finish/", {"openid": u"http://real.myopenid.com"})
            res.follow()

            assert urlparse.urlsplit(res.location)[2] == "/"
            assert "mediagoblin/root.html" in template.TEMPLATE_TEST_CONTEXT

            # Make sure user is in the session
            context = template.TEMPLATE_TEST_CONTEXT["mediagoblin/root.html"]
            session = context["request"].session
            assert session["user_id"] == unicode(test_user.id)
예제 #23
0
def fixture_add_user(username=u"chris", password="******", active_user=True):
    test_user = mg_globals.database.User()
    test_user.username = username
    test_user.email = username + u"@example.com"
    if password is not None:
        test_user.pw_hash = bcrypt_gen_password_hash(password)
    if active_user:
        test_user.email_verified = True
        test_user.status = u"active"

    test_user.save()

    # Reload
    test_user = mg_globals.database.User.find_one({"username": username})

    # ... and detach from session:
    Session.expunge(test_user)

    return test_user
예제 #24
0
def fixture_add_collection(name=u"My first Collection", user=None):
    if user is None:
        user = fixture_add_user()
    coll = Collection.query.filter_by(creator=user.id, title=name).first()
    if coll is not None:
        return coll
    coll = Collection()
    coll.creator = user.id
    coll.title = name
    coll.generate_slug()
    coll.save()

    # Reload
    Session.refresh(coll)

    # ... and detach from session:
    Session.expunge(coll)

    return coll
예제 #25
0
def fixture_add_comment(author=None, media_entry=None, comment=None):
    if author is None:
        author = fixture_add_user().id

    if media_entry is None:
        media_entry = fixture_media_entry().id

    if comment is None:
        comment = \
            'Auto-generated test comment by user #{0} on media #{0}'.format(
                author, media_entry)

    comment = MediaComment(author=author,
                      media_entry=media_entry,
                      content=comment)

    comment.save()

    Session.expunge(comment)

    return comment
예제 #26
0
def fixture_add_comment(author=None, media_entry=None, comment=None):
    if author is None:
        author = fixture_add_user().id

    if media_entry is None:
        media_entry = fixture_media_entry().id

    if comment is None:
        comment = \
            'Auto-generated test comment by user #{0} on media #{0}'.format(
                author, media_entry)

    comment = MediaComment(author=author,
                           media_entry=media_entry,
                           content=comment)

    comment.save()

    Session.expunge(comment)

    return comment
예제 #27
0
def fixture_media_entry(title=u"Some title", slug=None,
                        uploader=None, save=True, gen_slug=True,
                        state=u'unprocessed', fake_upload=True,
                        expunge=True):
    """
    Add a media entry for testing purposes.

    Caution: if you're adding multiple entries with fake_upload=True,
    make sure you save between them... otherwise you'll hit an
    IntegrityError from multiple newly-added-MediaEntries adding
    FileKeynames at once.  :)
    """
    if uploader is None:
        uploader = fixture_add_user().id

    entry = MediaEntry()
    entry.title = title
    entry.slug = slug
    entry.uploader = uploader
    entry.media_type = u'image'
    entry.state = state

    if fake_upload:
        entry.media_files = {'thumb': ['a', 'b', 'c.jpg'],
                             'medium': ['d', 'e', 'f.png'],
                             'original': ['g', 'h', 'i.png']}
        entry.media_type = u'mediagoblin.media_types.image'

    if gen_slug:
        entry.generate_slug()

    if save:
        entry.save()

    if expunge:
        entry = MediaEntry.query.filter_by(id=entry.id).first()

        Session.expunge(entry)

    return entry
예제 #28
0
def fixture_add_comment(author=None, media_entry=None, comment=None):
    if author is None:
        author = fixture_add_user().id

    if media_entry is None:
        media_entry = fixture_media_entry()

    if comment is None:
        comment = \
            'Auto-generated test comment by user #{0} on media #{0}'.format(
                author, media_entry)

    text_comment = TextComment(actor=author, content=comment)
    text_comment.save()

    comment_link = Comment()
    comment_link.target = media_entry
    comment_link.comment = text_comment
    comment_link.save()

    Session.expunge(comment_link)

    return text_comment
예제 #29
0
def fixture_add_collection(name="My first Collection",
                           user=None,
                           collection_type=Collection.USER_DEFINED_TYPE):
    if user is None:
        user = fixture_add_user()
    coll = Collection.query.filter_by(actor=user.id,
                                      title=name,
                                      type=collection_type).first()
    if coll is not None:
        return coll
    coll = Collection()
    coll.actor = user.id
    coll.title = name
    coll.type = collection_type
    coll.generate_slug()
    coll.save()

    # Reload
    Session.refresh(coll)

    # ... and detach from session:
    Session.expunge(coll)

    return coll
예제 #30
0
def fixture_add_user(username=u'chris', password=u'toast',
                     privileges=[], wants_comment_notification=True):
    # Reuse existing user or create a new one
    test_user = User.query.filter_by(username=username).first()
    if test_user is None:
        test_user = User()
    test_user.username = username
    test_user.email = username + u'@example.com'
    if password is not None:
        test_user.pw_hash = gen_password_hash(password)
    test_user.wants_comment_notification = wants_comment_notification
    for privilege in privileges:
        query = Privilege.query.filter(Privilege.privilege_name==privilege)
        if query.count():
            test_user.all_privileges.append(query.one())

    test_user.save()
    # Reload
    test_user = User.query.filter_by(username=username).first()

    # ... and detach from session:
    Session.expunge(test_user)

    return test_user
예제 #31
0
        def _test_registration():
            # No register users
            template.clear_test_template_context()
            res = persona_plugin_app.post(
                '/auth/persona/login/', {})

            assert 'mediagoblin/auth/register.html' in template.TEMPLATE_TEST_CONTEXT
            context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
            register_form = context['register_form']

            assert register_form.email.data == u'*****@*****.**'
            assert register_form.persona_email.data == u'*****@*****.**'

            template.clear_test_template_context()
            res = persona_plugin_app.post(
                '/auth/persona/register/', {})

            assert 'mediagoblin/auth/register.html' in template.TEMPLATE_TEST_CONTEXT
            context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
            register_form = context['register_form']

            assert register_form.username.errors == [u'This field is required.']
            assert register_form.email.errors == [u'This field is required.']
            assert register_form.persona_email.errors == [u'This field is required.']

            # Successful register
            template.clear_test_template_context()
            res = persona_plugin_app.post(
                '/auth/persona/register/',
                {'username': '******',
                 'email': '*****@*****.**',
                 'persona_email': '*****@*****.**'})
            res.follow()

            assert urlparse.urlsplit(res.location)[2] == '/u/chris/'
            assert 'mediagoblin/user_pages/user_nonactive.html' in template.TEMPLATE_TEST_CONTEXT

            # Try to register same Persona email address
            template.clear_test_template_context()
            res = persona_plugin_app.post(
                '/auth/persona/register/',
                {'username': '******',
                 'email': '*****@*****.**',
                 'persona_email': '*****@*****.**'})

            assert 'mediagoblin/auth/register.html' in template.TEMPLATE_TEST_CONTEXT
            context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
            register_form = context['register_form']

            assert register_form.persona_email.errors == [u'Sorry, an account is already registered to that Persona email.']

            # Logout
            persona_plugin_app.get('/auth/logout/')

            # Get user and detach from session
            test_user = mg_globals.database.LocalUser.query.filter(
                LocalUser.username==u'chris'
            ).first()
            active_privilege = Privilege.query.filter(
                Privilege.privilege_name==u'active').first()
            test_user.all_privileges.append(active_privilege)
            test_user.save()
            test_user = mg_globals.database.LocalUser.query.filter(
                LocalUser.username==u'chris'
            ).first()
            Session.expunge(test_user)

            # Add another user for _test_edit_persona
            persona_plugin_app.post(
                '/auth/persona/register/',
                {'username': '******',
                 'email': '*****@*****.**',
                 'persona_email': '*****@*****.**'})

            # Log back in
            template.clear_test_template_context()
            res = persona_plugin_app.post(
                '/auth/persona/login/')
            res.follow()

            assert urlparse.urlsplit(res.location)[2] == '/'
            assert 'mediagoblin/root.html' in template.TEMPLATE_TEST_CONTEXT

            # Make sure user is in the session
            context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
            session = context['request'].session
            assert session['user_id'] == six.text_type(test_user.id)
예제 #32
0
        def _test_registration():
            # No register users
            template.clear_test_template_context()
            res = persona_plugin_app.post('/auth/persona/login/', {})

            assert 'mediagoblin/auth/register.html' in template.TEMPLATE_TEST_CONTEXT
            context = template.TEMPLATE_TEST_CONTEXT[
                'mediagoblin/auth/register.html']
            register_form = context['register_form']

            assert register_form.email.data == u'*****@*****.**'
            assert register_form.persona_email.data == u'*****@*****.**'

            template.clear_test_template_context()
            res = persona_plugin_app.post('/auth/persona/register/', {})

            assert 'mediagoblin/auth/register.html' in template.TEMPLATE_TEST_CONTEXT
            context = template.TEMPLATE_TEST_CONTEXT[
                'mediagoblin/auth/register.html']
            register_form = context['register_form']

            assert register_form.username.errors == [
                u'This field is required.'
            ]
            assert register_form.email.errors == [u'This field is required.']
            assert register_form.persona_email.errors == [
                u'This field is required.'
            ]

            # Successful register
            template.clear_test_template_context()
            res = persona_plugin_app.post(
                '/auth/persona/register/', {
                    'username': '******',
                    'email': '*****@*****.**',
                    'persona_email': '*****@*****.**'
                })
            res.follow()

            assert urlparse.urlsplit(res.location)[2] == '/u/chris/'
            assert 'mediagoblin/user_pages/user.html' in template.TEMPLATE_TEST_CONTEXT

            # Try to register same Persona email address
            template.clear_test_template_context()
            res = persona_plugin_app.post(
                '/auth/persona/register/', {
                    'username': '******',
                    'email': '*****@*****.**',
                    'persona_email': '*****@*****.**'
                })

            assert 'mediagoblin/auth/register.html' in template.TEMPLATE_TEST_CONTEXT
            context = template.TEMPLATE_TEST_CONTEXT[
                'mediagoblin/auth/register.html']
            register_form = context['register_form']

            assert register_form.persona_email.errors == [
                u'Sorry, an account is already registered to that Persona email.'
            ]

            # Logout
            persona_plugin_app.get('/auth/logout/')

            # Get user and detach from session
            test_user = mg_globals.database.User.query.filter_by(
                username=u'chris').first()
            test_user.email_verified = True
            test_user.status = u'active'
            test_user.save()
            test_user = mg_globals.database.User.query.filter_by(
                username=u'chris').first()
            Session.expunge(test_user)

            # Add another user for _test_edit_persona
            persona_plugin_app.post(
                '/auth/persona/register/', {
                    'username': '******',
                    'email': '*****@*****.**',
                    'persona_email': '*****@*****.**'
                })

            # Log back in
            template.clear_test_template_context()
            res = persona_plugin_app.post('/auth/persona/login/')
            res.follow()

            assert urlparse.urlsplit(res.location)[2] == '/'
            assert 'mediagoblin/root.html' in template.TEMPLATE_TEST_CONTEXT

            # Make sure user is in the session
            context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
            session = context['request'].session
            assert session['user_id'] == unicode(test_user.id)