コード例 #1
0
    def _setup(self, test_app):
        self.test_app = test_app

        fixture_add_user(u'allie',
            privileges=[u'reporter',u'active'])
        fixture_add_user(u'natalie',
            privileges=[u'active', u'moderator'])
コード例 #2
0
    def _setup(self, test_app):
        self.test_app = test_app

        fixture_add_user(u'allie',
            privileges=[u'reporter',u'active'])
        fixture_add_user(u'natalie',
            privileges=[u'active', u'moderator'])
コード例 #3
0
 def _setup(self):
     fixture_add_user(u'natalie',
                      privileges=[u'admin', u'moderator', u'active'])
     fixture_add_user(u'aeva', privileges=[u'moderator', u'active'])
     self.natalie_user = User.query.filter(
         User.username == u'natalie').first()
     self.aeva_user = User.query.filter(User.username == u'aeva').first()
コード例 #4
0
def test_search_link_present(test_app):
    """Test the search form is present if search is 'users only', and
    a user is logged in."""
    fixture_add_user(privileges=['active', 'uploader', 'commenter'])
    test_app.post('/auth/login/', {'username': '******', 'password': '******'})
    response = test_app.get('/')
    assert '/search/' in [form.action for form in itervalues(response.forms)]
コード例 #5
0
    def setup(self, test_app):
        self.test_app = test_app

        # TODO: Possibly abstract into a decorator like:
        # @as_authenticated_user('chris')
        fixture_add_user(privileges=[u'active', u'uploader', u'commenter'])

        self.login()
コード例 #6
0
ファイル: test_submission.py プロジェクト: piratas/biblioteca
    def setup(self, test_app):
        self.test_app = test_app

        # TODO: Possibly abstract into a decorator like:
        # @as_authenticated_user('chris')
        fixture_add_user(privileges=[u'active',u'uploader', u'commenter'])

        self.login()
コード例 #7
0
def test_search_link_present(test_app):
    """Test the search form is present if search is 'users only', and
    a user is logged in."""
    fixture_add_user(privileges=['active', 'uploader', 'commenter'])
    test_app.post('/auth/login/', {'username': '******',
                                   'password': '******'})
    response = test_app.get('/')
    assert '/search/' in [form.action for form in itervalues(response.forms)]
コード例 #8
0
ファイル: test_misc.py プロジェクト: ausbin/mediagoblin
def test_user_deletes_other_comments(test_app):
    user_a = fixture_add_user(u"chris_a")
    user_b = fixture_add_user(u"chris_b")

    media_a = fixture_media_entry(uploader=user_a.id, save=False,
                                  expunge=False, fake_upload=False)
    media_b = fixture_media_entry(uploader=user_b.id, save=False,
                                  expunge=False, fake_upload=False)
    Session.add(media_a)
    Session.add(media_b)
    Session.flush()

    # Create all 4 possible comments:
    for u in (user_a, user_b):
        for m in (media_a, media_b):
            cmt = TextComment()
            cmt.actor = u.id
            cmt.content = u"Some Comment"
            Session.add(cmt)
            # think i need this to get the command ID
            Session.flush()

            link = Comment()
            link.target = m
            link.comment = cmt
            Session.add(link)

    Session.flush()

    usr_cnt1 = User.query.count()
    med_cnt1 = MediaEntry.query.count()
    cmt_cnt1 = Comment.query.count()

    User.query.get(user_a.id).delete(commit=False)

    usr_cnt2 = User.query.count()
    med_cnt2 = MediaEntry.query.count()
    cmt_cnt2 = Comment.query.count()

    # One user deleted
    assert usr_cnt2 == usr_cnt1 - 1
    # One media gone
    assert med_cnt2 == med_cnt1 - 1
    # Three of four comments gone.
    assert cmt_cnt2 == cmt_cnt1 - 3

    User.query.get(user_b.id).delete()

    usr_cnt2 = User.query.count()
    med_cnt2 = MediaEntry.query.count()
    cmt_cnt2 = Comment.query.count()

    # All users gone
    assert usr_cnt2 == usr_cnt1 - 2
    # All media gone
    assert med_cnt2 == med_cnt1 - 2
    # All comments gone
    assert cmt_cnt2 == cmt_cnt1 - 4
コード例 #9
0
 def _setup(self):
     fixture_add_user('natalie',
         privileges=['admin','moderator','active'])
     fixture_add_user('aeva',
         privileges=['moderator','active'])
     self.natalie_user = LocalUser.query.filter(
         LocalUser.username=='natalie').first()
     self.aeva_user = LocalUser.query.filter(
         LocalUser.username=='aeva').first()
コード例 #10
0
 def _setup(self):
     fixture_add_user(u'natalie',
         privileges=[u'admin',u'moderator',u'active'])
     fixture_add_user(u'aeva',
         privileges=[u'moderator',u'active'])
     self.natalie_user = User.query.filter(
         User.username==u'natalie').first()
     self.aeva_user = User.query.filter(
         User.username==u'aeva').first()
コード例 #11
0
    def setup(self, video_plugin_app):
        self.test_app = video_plugin_app
        self.media_type = 'mediagoblin.media_types.video'

        # TODO: Possibly abstract into a decorator like:
        # @as_authenticated_user('chris')
        fixture_add_user(privileges=['active','uploader', 'commenter'])

        self.login()
コード例 #12
0
    def setup(self, test_app):
        self.test_app = test_app
        self.db = mg_globals.database

        self.user = fixture_add_user(privileges=[u'active', u'uploader', u'commenter'])
        self.other_user = fixture_add_user(
            username="******",
            privileges=[u'active', u'uploader', u'commenter']
        )
コード例 #13
0
    def setup(self, test_app):
        self.test_app = test_app

        if self.usernames is None:
            msg = ('The usernames attribute should be overridden '
                   'in the subclass')
            raise pytest.skip(msg)
        for username, options in self.usernames:
            fixture_add_user(username, **options)
コード例 #14
0
    def setup(self, test_app):
        self.test_app = test_app
        self.db = mg_globals.database

        self.user = fixture_add_user(
            privileges=[u'active', u'uploader', u'commenter'])
        self.other_user = fixture_add_user(
            username="******",
            privileges=[u'active', u'uploader', u'commenter'])
コード例 #15
0
def test_user_deletes_other_comments(test_app):
    user_a = fixture_add_user(u"chris_a")
    user_b = fixture_add_user(u"chris_b")

    media_a = fixture_media_entry(uploader=user_a.id,
                                  save=False,
                                  expunge=False,
                                  fake_upload=False)
    media_b = fixture_media_entry(uploader=user_b.id,
                                  save=False,
                                  expunge=False,
                                  fake_upload=False)
    Session.add(media_a)
    Session.add(media_b)
    Session.flush()

    # Create all 4 possible comments:
    for u_id in (user_a.id, user_b.id):
        for m_id in (media_a.id, media_b.id):
            cmt = MediaComment()
            cmt.media_entry = m_id
            cmt.author = u_id
            cmt.content = u"Some Comment"
            Session.add(cmt)

    Session.flush()

    usr_cnt1 = User.query.count()
    med_cnt1 = MediaEntry.query.count()
    cmt_cnt1 = MediaComment.query.count()

    User.query.get(user_a.id).delete(commit=False)

    usr_cnt2 = User.query.count()
    med_cnt2 = MediaEntry.query.count()
    cmt_cnt2 = MediaComment.query.count()

    # One user deleted
    assert usr_cnt2 == usr_cnt1 - 1
    # One media gone
    assert med_cnt2 == med_cnt1 - 1
    # Three of four comments gone.
    assert cmt_cnt2 == cmt_cnt1 - 3

    User.query.get(user_b.id).delete()

    usr_cnt2 = User.query.count()
    med_cnt2 = MediaEntry.query.count()
    cmt_cnt2 = MediaComment.query.count()

    # All users gone
    assert usr_cnt2 == usr_cnt1 - 2
    # All media gone
    assert med_cnt2 == med_cnt1 - 2
    # All comments gone
    assert cmt_cnt2 == cmt_cnt1 - 4
コード例 #16
0
    def test_change_bio_url(self, test_app):
        """Test changing bio and URL"""
        self.login(test_app)

        # Test if legacy profile editing URL redirects correctly
        res = test_app.post('/edit/profile/', {
            'bio': 'I love toast!',
            'url': 'http://dustycloud.org/'
        },
                            expect_errors=True)

        # Should redirect to /u/chris/edit/
        assert res.status_int == 302
        assert res.headers['Location'].endswith("/u/chris/edit/")

        res = test_app.post('/u/chris/edit/', {
            'bio': 'I love toast!',
            'url': 'http://dustycloud.org/'
        })

        test_user = LocalUser.query.filter(
            LocalUser.username == 'chris').first()
        assert test_user.bio == 'I love toast!'
        assert test_user.url == 'http://dustycloud.org/'

        # change a different user than the logged in (should fail with 403)
        fixture_add_user(username="******", privileges=['active'])
        res = test_app.post('/u/foo/edit/', {
            'bio': 'I love toast!',
            'url': 'http://dustycloud.org/'
        },
                            expect_errors=True)
        assert res.status_int == 403

        # test changing the bio and the URL inproperly
        too_long_bio = 150 * 'T' + 150 * 'o' + 150 * 'a' + 150 * 's' + 150 * 't'

        test_app.post(
            '/u/chris/edit/',
            {
                # more than 500 characters
                'bio': too_long_bio,
                'url': 'this-is-no-url'
            })

        # Check form errors
        context = template.TEMPLATE_TEST_CONTEXT[
            'mediagoblin/edit/edit_profile.html']
        form = context['form']

        assert form.bio.errors == [
            'Field must be between 0 and 500 characters long.'
        ]
        assert form.url.errors == ['This address contains errors']
コード例 #17
0
def test_user_deletes_other_comments(test_app):
    user_a = fixture_add_user(u"chris_a")
    user_b = fixture_add_user(u"chris_b")

    media_a = fixture_media_entry(uploader=user_a.id, save=False,
                                  expunge=False, fake_upload=False)
    media_b = fixture_media_entry(uploader=user_b.id, save=False,
                                  expunge=False, fake_upload=False)
    Session.add(media_a)
    Session.add(media_b)
    Session.flush()

    # Create all 4 possible comments:
    for u_id in (user_a.id, user_b.id):
        for m_id in (media_a.id, media_b.id):
            cmt = MediaComment()
            cmt.media_entry = m_id
            cmt.author = u_id
            cmt.content = u"Some Comment"
            Session.add(cmt)

    Session.flush()

    usr_cnt1 = User.query.count()
    med_cnt1 = MediaEntry.query.count()
    cmt_cnt1 = MediaComment.query.count()

    User.query.get(user_a.id).delete(commit=False)

    usr_cnt2 = User.query.count()
    med_cnt2 = MediaEntry.query.count()
    cmt_cnt2 = MediaComment.query.count()

    # One user deleted
    assert usr_cnt2 == usr_cnt1 - 1
    # One media gone
    assert med_cnt2 == med_cnt1 - 1
    # Three of four comments gone.
    assert cmt_cnt2 == cmt_cnt1 - 3

    User.query.get(user_b.id).delete()

    usr_cnt2 = User.query.count()
    med_cnt2 = MediaEntry.query.count()
    cmt_cnt2 = MediaComment.query.count()

    # All users gone
    assert usr_cnt2 == usr_cnt1 - 2
    # All media gone
    assert med_cnt2 == med_cnt1 - 2
    # All comments gone
    assert cmt_cnt2 == cmt_cnt1 - 4
コード例 #18
0
    def test_change_bio_url(self, test_app):
        """Test changing bio and URL"""
        self.login(test_app)

        # Test if legacy profile editing URL redirects correctly
        res = test_app.post(
            '/edit/profile/', {
                'bio': u'I love toast!',
                'url': u'http://dustycloud.org/'}, expect_errors=True)

        # Should redirect to /u/chris/edit/
        assert res.status_int == 302
        assert res.headers['Location'].endswith("/u/chris/edit/")

        res = test_app.post(
            '/u/chris/edit/', {
                'bio': u'I love toast!',
                'url': u'http://dustycloud.org/'})

        test_user = User.query.filter_by(username=u'chris').first()
        assert test_user.bio == u'I love toast!'
        assert test_user.url == u'http://dustycloud.org/'

        # change a different user than the logged in (should fail with 403)
        fixture_add_user(username=u"foo",
                         privileges=[u'active'])
        res = test_app.post(
            '/u/foo/edit/', {
                'bio': u'I love toast!',
                'url': u'http://dustycloud.org/'}, expect_errors=True)
        assert res.status_int == 403

        # test changing the bio and the URL inproperly
        too_long_bio = 150 * 'T' + 150 * 'o' + 150 * 'a' + 150 * 's' + 150* 't'

        test_app.post(
            '/u/chris/edit/', {
                # more than 500 characters
                'bio': too_long_bio,
                'url': 'this-is-no-url'})

        # Check form errors
        context = template.TEMPLATE_TEST_CONTEXT[
            'mediagoblin/edit/edit_profile.html']
        form = context['form']

        assert form.bio.errors == [
            u'Field must be between 0 and 500 characters long.']
        assert form.url.errors == [
            u'This address contains errors']
コード例 #19
0
ファイル: test_openid.py プロジェクト: shahidge4/mediagoblin
        def _test_delete(self, test_user):
            # Delete openid from user
            # Create another user to test deleting OpenID that doesn't belong to them
            new_user = fixture_add_user(username='******')
            openid = OpenIDUserURL()
            openid.openid_url = 'http://realfake.myopenid.com/'
            openid.user_id = new_user.id
            openid.save()

            # Try and delete OpenID url that isn't the users
            template.clear_test_template_context()
            res = openid_plugin_app.post(
                '/edit/openid/delete/', {
                    'openid': 'http://realfake.myopenid.com/'})
            context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/plugins/openid/delete.html']
            form = context['form']
            assert form.openid.errors == [u'That OpenID is not registered to this account.']

            # Delete OpenID
            # Kind of weird to POST to delete/finish
            template.clear_test_template_context()
            res = openid_plugin_app.post(
                '/edit/openid/delete/finish/', {
                    'openid': u'http://add.myopenid.com'})
            res.follow()

            # Correct place?
            assert urlparse.urlsplit(res.location)[2] == '/edit/account/'
            assert 'mediagoblin/edit/edit_account.html' in template.TEMPLATE_TEST_CONTEXT

            # OpenID deleted?
            new_openid = mg_globals.database.OpenIDUserURL.query.filter_by(
                openid_url=u'http://add.myopenid.com').first()
            assert not new_openid
コード例 #20
0
def test_garbage_collection_task(test_app):
    """ Test old media entry are removed by GC task """
    user = fixture_add_user()

    # Create a media entry that's unprocessed and over an hour old.
    entry_id = 72
    now = datetime.datetime.now(pytz.UTC)
    file_data = FileStorage(
        stream=open(GOOD_JPG, "rb"),
        filename="mah_test.jpg",
        content_type="image/jpeg"
    )

    # Find media manager
    media_type, media_manager = sniff_media(file_data, "mah_test.jpg")
    entry = new_upload_entry(user)
    entry.id = entry_id
    entry.title = "Mah Image"
    entry.slug = "slugy-slug-slug"
    entry.media_type = 'image'
    entry.created = now - datetime.timedelta(days=2)
    entry.save()

    # Validate the model exists
    assert MediaEntry.query.filter_by(id=entry_id).first() is not None

    # Call the garbage collection task
    collect_garbage()

    # Now validate the image has been deleted
    assert MediaEntry.query.filter_by(id=entry_id).first() is None
コード例 #21
0
ファイル: test_misc.py プロジェクト: ausbin/mediagoblin
def test_comments_removed_when_graveyarded(test_app):
    """ Checks comments which are tombstones are removed from collection """
    user = fixture_add_user()
    media = fixture_media_entry(
        uploader=user.id,
        expunge=False,
        fake_upload=False
    )
    
    # Add the TextComment
    comment = TextComment()
    comment.actor = user.id
    comment.content = u"This is a comment that will be deleted."
    comment.save()

    # Add a link for the comment
    link = Comment()
    link.target = media
    link.comment = comment
    link.save()

    # First double check it's there and all is well...
    assert Comment.query.filter_by(target_id=link.target_id).first() is not None

    # Now delete the comment.
    comment.delete()

    # Verify this also deleted the Comment link, ergo there is no comment left.
    assert Comment.query.filter_by(target_id=link.target_id).first() is None
コード例 #22
0
def test_change_password(test_app):
        """Test changing password correctly and incorrectly"""
        test_user = fixture_add_user(password=u'toast')

        test_app.post(
            '/auth/login/', {
                'username': u'chris',
                'password': u'toast'})

        # test that the password can be changed
        res = test_app.post(
            '/edit/password/', {
                'old_password': '******',
                'new_password': '******',
                })
        res.follow()

        # Did we redirect to the correct page?
        assert urlparse.urlsplit(res.location)[2] == '/edit/account/'

        # test_user has to be fetched again in order to have the current values
        test_user = User.query.filter_by(username=u'chris').first()
        assert auth_tools.bcrypt_check_password('123456', test_user.pw_hash)

        # test that the password cannot be changed if the given
        # old_password is wrong
        template.clear_test_template_context()
        test_app.post(
            '/edit/password/', {
                'old_password': '******',
                'new_password': '******',
                })

        test_user = User.query.filter_by(username=u'chris').first()
        assert not auth_tools.bcrypt_check_password('098765', test_user.pw_hash)
コード例 #23
0
ファイル: test_misc.py プロジェクト: gitGNU/gnu_mediagoblin
def test_garbage_collection_task(test_app):
    """ Test old media entry are removed by GC task """
    user = fixture_add_user()

    # Create a media entry that's unprocessed and over an hour old.
    entry_id = 72
    now = datetime.datetime.now(pytz.UTC)
    file_data = FileStorage(stream=open(GOOD_JPG, "rb"),
                            filename="mah_test.jpg",
                            content_type="image/jpeg")

    # Find media manager
    media_type, media_manager = sniff_media(file_data, "mah_test.jpg")
    entry = new_upload_entry(user)
    entry.id = entry_id
    entry.title = "Mah Image"
    entry.slug = "slugy-slug-slug"
    entry.media_type = 'image'
    entry.created = now - datetime.timedelta(days=2)
    entry.save()

    # Validate the model exists
    assert MediaEntry.query.filter_by(id=entry_id).first() is not None

    # Call the garbage collection task
    collect_garbage()

    # Now validate the image has been deleted
    assert MediaEntry.query.filter_by(id=entry_id).first() is None
コード例 #24
0
ファイル: test_edit.py プロジェクト: 3rdwiki/mediagoblin
def change_bio_url(test_app):
    """Test changing bio and URL"""
    # set up new user
    test_user = fixture_add_user()

    # test changing the bio and the URL properly
    test_app.post(
        '/edit/profile/', {
            'bio': u'I love toast!',
            'url': u'http://dustycloud.org/'})

    test_user = mg_globals.database.User.one({'username': u'chris'})

    assert test_user.bio == u'I love toast!'
    assert test_user.url == u'http://dustycloud.org/'

    # test changing the bio and the URL inproperly
    too_long_bio = 150 * 'T' + 150 * 'o' + 150 * 'a' + 150 * 's' + 150* 't'

    test_app.post(
        '/edit/profile/', {
            # more than 500 characters
            'bio': too_long_bio,
            'url': 'this-is-no-url'})

    test_user = mg_globals.database.User.one({'username': u'chris'})

    context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/edit/edit_profile.html']
    form = context['edit_profile_form']

    assert form.bio.errors == [u'Field must be between 0 and 500 characters long.']
    assert form.url.errors == [u'Improperly formed URL']
コード例 #25
0
        def _test_delete(self, test_user):
            # Delete openid from user
            # Create another user to test deleting OpenID that doesn't belong to them
            new_user = fixture_add_user(username="******")
            openid = OpenIDUserURL()
            openid.openid_url = "http://realfake.myopenid.com/"
            openid.user_id = new_user.id
            openid.save()

            # Try and delete OpenID url that isn't the users
            template.clear_test_template_context()
            res = openid_plugin_app.post("/edit/openid/delete/", {"openid": "http://realfake.myopenid.com/"})
            context = template.TEMPLATE_TEST_CONTEXT["mediagoblin/plugins/openid/delete.html"]
            form = context["form"]
            assert form.openid.errors == [u"That OpenID is not registered to this account."]

            # Delete OpenID
            # Kind of weird to POST to delete/finish
            template.clear_test_template_context()
            res = openid_plugin_app.post("/edit/openid/delete/finish/", {"openid": u"http://add.myopenid.com"})
            res.follow()

            # Correct place?
            assert urlparse.urlsplit(res.location)[2] == "/edit/account/"
            assert "mediagoblin/edit/edit_account.html" in template.TEMPLATE_TEST_CONTEXT

            # OpenID deleted?
            new_openid = mg_globals.database.OpenIDUserURL.query.filter_by(
                openid_url=u"http://add.myopenid.com"
            ).first()
            assert not new_openid
コード例 #26
0
def test_change_password(test_app):
    """Test changing password correctly and incorrectly"""
    test_user = fixture_add_user(password=u'toast', privileges=[u'active'])

    test_app.post('/auth/login/', {'username': u'chris', 'password': u'toast'})

    # test that the password can be changed
    res = test_app.post('/edit/password/', {
        'old_password': '******',
        'new_password': '******',
    })
    res.follow()

    # Did we redirect to the correct page?
    assert urlparse.urlsplit(res.location)[2] == '/edit/account/'

    # test_user has to be fetched again in order to have the current values
    test_user = User.query.filter_by(username=u'chris').first()
    assert auth_tools.bcrypt_check_password('123456', test_user.pw_hash)

    # test that the password cannot be changed if the given
    # old_password is wrong
    template.clear_test_template_context()
    test_app.post('/edit/password/', {
        'old_password': '******',
        'new_password': '******',
    })

    test_user = User.query.filter_by(username=u'chris').first()
    assert not auth_tools.bcrypt_check_password('098765', test_user.pw_hash)
コード例 #27
0
ファイル: test_misc.py プロジェクト: gitGNU/gnu_mediagoblin
def test_comments_removed_when_graveyarded(test_app):
    """ Checks comments which are tombstones are removed from collection """
    user = fixture_add_user()
    media = fixture_media_entry(uploader=user.id,
                                expunge=False,
                                fake_upload=False)

    # Add the TextComment
    comment = TextComment()
    comment.actor = user.id
    comment.content = u"This is a comment that will be deleted."
    comment.save()

    # Add a link for the comment
    link = Comment()
    link.target = media
    link.comment = comment
    link.save()

    # First double check it's there and all is well...
    assert Comment.query.filter_by(
        target_id=link.target_id).first() is not None

    # Now delete the comment.
    comment.delete()

    # Verify this also deleted the Comment link, ergo there is no comment left.
    assert Comment.query.filter_by(target_id=link.target_id).first() is None
コード例 #28
0
    def setup(self):
        self.db = mg_globals.database

        self.user_password = '******'
        self.user = fixture_add_user('joapi',
                                     self.user_password,
                                     privileges=['active', 'uploader'])
コード例 #29
0
ファイル: test_edit.py プロジェクト: ausbin/mediagoblin
 def setup(self, test_app):
     # set up new user
     self.user_password = u'toast'
     self.user = fixture_add_user(
         password = self.user_password,
         privileges=[u'active',u'admin']
     )
     self.test_app = test_app
コード例 #30
0
    def setUp(self):
        self.app = get_test_app()
        self.db = mg_globals.database

        self.user_password = u'secret'
        self.user = fixture_add_user(u'call_back', self.user_password)

        self.login()
コード例 #31
0
    def setup(self, test_app):
        self.test_app = test_app

        self.db = mg_globals.database

        self.user_password = u'secret'
        self.user = fixture_add_user(u'call_back', self.user_password)

        self.login()
コード例 #32
0
    def setup(self, test_app):
        self.test_app = test_app

        self.db = mg_globals.database

        self.user_password = u'secret'
        self.user = fixture_add_user(u'call_back', self.user_password)

        self.login()
コード例 #33
0
ファイル: test_oauth.py プロジェクト: 3rdwiki/mediagoblin
    def setUp(self):
        self.app = get_test_app()
        self.db = mg_globals.database

        self.pman = pluginapi.PluginManager()

        self.user_password = '******'
        self.user = fixture_add_user('joauth', self.user_password)

        self.login()
コード例 #34
0
    def setup(self, test_app):
        self.test_app = test_app

        # TODO: Possibly abstract into a decorator like:
        # @as_authenticated_user('chris')
        self.test_user = fixture_add_user()

        self.current_user = None

        self.login()
コード例 #35
0
    def setup(self, test_app):
        self.test_app = test_app

        # TODO: Possibly abstract into a decorator like:
        # @as_authenticated_user('chris')
        self.test_user = fixture_add_user(privileges=[u"active", u"commenter"])

        self.current_user = None

        self.login()
コード例 #36
0
    def setup(self, test_app):
        self.test_app = test_app

        # TODO: Possibly abstract into a decorator like:
        # @as_authenticated_user('chris')
        test_user = fixture_add_user()

        self.test_user = test_user

        self.login()
コード例 #37
0
    def setup(self, test_app):
        self.test_app = test_app

        self.db = mg_globals.database

        self.pman = pluginapi.PluginManager()

        self.user_password = u'4cc355_70k3N'
        self.user = fixture_add_user(u'joauth', self.user_password)

        self.login()
コード例 #38
0
    def setup(self, test_app):
        self.test_app = test_app

        self.db = mg_globals.database

        self.pman = pluginapi.PluginManager()

        self.user_password = "******"
        self.user = fixture_add_user("OAuthy", self.user_password)

        self.login()
コード例 #39
0
ファイル: test_oauth.py プロジェクト: RichoHan/MediaGoblin
    def setup(self, test_app):
        self.test_app = test_app

        self.db = mg_globals.database

        self.pman = pluginapi.PluginManager()

        self.user_password = u'4cc355_70k3N'
        self.user = fixture_add_user(u'joauth', self.user_password)

        self.login()
コード例 #40
0
    def setup(self, test_app):
        self.test_app = test_app

        self.db = mg_globals.database

        self.pman = pluginapi.PluginManager()

        self.user_password = "******"
        self.user = fixture_add_user("OAuthy", self.user_password)

        self.login()
コード例 #41
0
    def setup(self, test_app):
        self.test_app = test_app

        # TODO: Possibly abstract into a decorator like:
        # @as_authenticated_user('chris')
        fixture_add_user(privileges=['active', 'uploader', 'commenter'])

        self.login()

        upload_fields = [('title number one', 'description number one'),
                         ('title number two', 'description number two')]
        upload = webtest.forms.Upload(os.path.join('test', 'image.png'))

        for title, description in upload_fields:
            response = self.test_app.get('/submit/')
            # Test upload of an image when a user has no collections.
            submit_form = self.get_form_from_response(response, '/submit/')
            submit_form['file'] = upload
            submit_form['title'] = title
            submit_form['description'] = description
            submit_form.submit()
コード例 #42
0
    def setup(self, test_app):
        self.test_app = test_app

        # TODO: Possibly abstract into a decorator like:
        # @as_authenticated_user('chris')
        fixture_add_user(privileges=['active', 'uploader', 'commenter'])

        self.login()

        upload_fields = [('title number one', 'description number one'),
                         ('title number two', 'description number two')]
        upload = webtest.forms.Upload(os.path.join('test', 'image.png'))

        for title, description in upload_fields:
            response = self.test_app.get('/submit/')
            # Test upload of an image when a user has no collections.
            submit_form = self.get_form_from_response(response, '/submit/')
            submit_form['file'] = upload
            submit_form['title'] = title
            submit_form['description'] = description
            submit_form.submit()
コード例 #43
0
def test_user_deletes_collection(test_app):
    # Setup db.
    user = fixture_add_user()
    coll = fixture_add_collection(user=user)
    # Reload into session:
    user = User.query.get(user.id)

    cnt1 = Collection.query.count()
    user.delete()
    cnt2 = Collection.query.count()

    assert cnt1 == cnt2 + 1
コード例 #44
0
    def test_mark_all_comment_notifications_seen(self):
        """ Test that mark_all_comments_seen works"""

        user = fixture_add_user('otherperson', password='******',
                        privileges=[u'active'])

        media_entry = fixture_media_entry(uploader=user.id, state=u'processed')

        fixture_comment_subscription(media_entry)

        media_uri_id = '/u/{0}/m/{1}/'.format(user.username,
                                              media_entry.id)

        # add 2 comments
        self.test_app.post(
            media_uri_id + 'comment/add/',
            {
                'comment_content': u'Test comment #43'
            }
        )

        self.test_app.post(
            media_uri_id + 'comment/add/',
            {
                'comment_content': u'Test comment #44'
            }
        )

        notifications = Notification.query.filter_by(
            user_id=user.id).all()

        assert len(notifications) == 2

        # both comments should not be marked seen
        assert notifications[0].seen == False
        assert notifications[1].seen == False

        # login with other user to mark notifications seen
        self.logout()
        self.login('otherperson', 'nosreprehto')

        # mark all comment notifications seen
        res = self.test_app.get('/notifications/comments/mark_all_seen/')
        res.follow()

        assert urlparse.urlsplit(res.location)[2] == '/'

        notifications = Notification.query.filter_by(
            user_id=user.id).all()

        # both notifications should be marked seen
        assert notifications[0].seen == True
        assert notifications[1].seen == True
コード例 #45
0
    def _setup(self, test_app):
        self.test_app = test_app

        fixture_add_user(u"alex", privileges=[u"admin", u"active"])
        fixture_add_user(u"meow", privileges=[u"moderator", u"active", u"reporter"])
        fixture_add_user(u"natalie", privileges=[u"active"])
        self.query_for_users()
コード例 #46
0
    def _setup(self, test_app):
        self.test_app = test_app

        fixture_add_user(u'admin', privileges=[u'admin', u'active'])
        fixture_add_user(u'moderator', privileges=[u'moderator', u'active'])
        fixture_add_user(u'regular', privileges=[u'active', u'commenter'])
        self.query_for_users()
コード例 #47
0
ファイル: test_misc.py プロジェクト: praveen97uma/goblin
def test_media_deletes_broken_attachment(test_app):
    user_a = fixture_add_user(u"chris_a")

    media = fixture_media_entry(uploader=user_a.id, save=False)
    media.attachment_files.append(dict(
            name=u"some name",
            filepath=[u"does", u"not", u"exist"],
            ))
    Session.add(media)
    Session.flush()

    MediaEntry.query.get(media.id).delete()
    User.query.get(user_a.id).delete()
コード例 #48
0
def test_media_deletes_broken_attachment(test_app):
    user_a = fixture_add_user(u"chris_a")

    media = fixture_media_entry(uploader=user_a.id, save=False, expunge=False)
    media.attachment_files.append(dict(
            name=u"some name",
            filepath=[u"does", u"not", u"exist"],
            ))
    Session.add(media)
    Session.flush()

    MediaEntry.query.get(media.id).delete()
    User.query.get(user_a.id).delete()
コード例 #49
0
    def _setup(self, test_app):
        self.test_app = test_app

        fixture_add_user('alex', privileges=['admin', 'active'])
        fixture_add_user('meow',
                         privileges=['moderator', 'active', 'reporter'])
        fixture_add_user('natalie', privileges=['active'])
        self.query_for_users()
コード例 #50
0
ファイル: test_subtitles.py プロジェクト: mtlynch/mediagoblin
def test_customize_subtitle(test_app):
    user_a = fixture_add_user(u"test_user")

    media = fixture_media_entry(uploader=user_a.id, save=False, expunge=False)
    media.subtitle_files.append(
        dict(
            name=u"some name",
            filepath=[u"does", u"not", u"exist"],
        ))
    Session.add(media)
    Session.flush()

    for subtitle in media.subtitle_files:
        assert '' == open_subtitle(subtitle['filepath'])[0]
コード例 #51
0
ファイル: test_subtitles.py プロジェクト: mtlynch/mediagoblin
def test_add_subtitle_entry(test_app):
    user_a = fixture_add_user(u"test_user")

    media = fixture_media_entry(uploader=user_a.id, save=False, expunge=False)
    media.subtitle_files.append(
        dict(
            name=u"some name",
            filepath=[u"does", u"not", u"exist"],
        ))
    Session.add(media)
    Session.flush()

    MediaEntry.query.get(media.id).delete()
    User.query.get(user_a.id).delete()
コード例 #52
0
    def _setup(self, test_app):
        self.test_app = test_app

        fixture_add_user(u'admin',
            privileges=[u'admin',u'active'])
        fixture_add_user(u'moderator',
            privileges=[u'moderator',u'active'])
        fixture_add_user(u'regular',
            privileges=[u'active',u'commenter'])
        self.query_for_users()
コード例 #53
0
ファイル: test_privileges.py プロジェクト: ausbin/mediagoblin
    def _setup(self, test_app):
        self.test_app = test_app

        fixture_add_user(u'alex',
            privileges=[u'admin',u'active'])
        fixture_add_user(u'meow',
            privileges=[u'moderator',u'active',u'reporter'])
        fixture_add_user(u'natalie',
            privileges=[u'active'])
        self.query_for_users()
コード例 #54
0
ファイル: test_edit.py プロジェクト: spaetz/mediagoblin_blog
    def test_user_deletion(self, test_app):
        """Delete user via web interface"""
        self.login(test_app)

        # Make sure user exists
        assert User.query.filter_by(username=u'chris').first()

        res = test_app.post('/edit/account/delete/', {'confirmed': 'y'})

        # Make sure user has been deleted
        assert User.query.filter_by(username=u'chris').first() == None

        #TODO: make sure all corresponding items comments etc have been
        # deleted too. Perhaps in submission test?

        #Restore user at end of test
        self.user = fixture_add_user(password=self.user_password)
        self.login(test_app)
コード例 #55
0
    def test_user_deletion(self, test_app):
        """Delete user via web interface"""
        self.login(test_app)

        # Make sure user exists
        assert User.query.filter_by(username=u'chris').first()

        res = test_app.post('/edit/account/delete/', {'confirmed': 'y'})

        # Make sure user has been deleted
        assert User.query.filter_by(username=u'chris').first() == None

        #TODO: make sure all corresponding items comments etc have been
        # deleted too. Perhaps in submission test?

        #Restore user at end of test
        self.user = fixture_add_user(password = self.user_password)
        self.login(test_app)
コード例 #56
0
    def test_mark_all_comment_notifications_seen(self):
        """ Test that mark_all_comments_seen works"""

        user = fixture_add_user('otherperson',
                                password='******',
                                privileges=[u'active'])

        media_entry = fixture_media_entry(uploader=user.id, state=u'processed')

        fixture_comment_subscription(media_entry)

        media_uri_id = '/u/{0}/m/{1}/'.format(user.username, media_entry.id)

        # add 2 comments
        self.test_app.post(media_uri_id + 'comment/add/',
                           {'comment_content': u'Test comment #43'})

        self.test_app.post(media_uri_id + 'comment/add/',
                           {'comment_content': u'Test comment #44'})

        notifications = Notification.query.filter_by(user_id=user.id).all()

        assert len(notifications) == 2

        # both comments should not be marked seen
        assert notifications[0].seen == False
        assert notifications[1].seen == False

        # login with other user to mark notifications seen
        self.logout()
        self.login('otherperson', 'nosreprehto')

        # mark all comment notifications seen
        res = self.test_app.get('/notifications/comments/mark_all_seen/')
        res.follow()

        assert urlparse.urlsplit(res.location)[2] == '/'

        notifications = Notification.query.filter_by(user_id=user.id).all()

        # both notifications should be marked seen
        assert notifications[0].seen == True
        assert notifications[1].seen == True
コード例 #57
0
def test_authentication_views(test_app):
    """
    Test logging in and logging out
    """
    # Make a new user
    test_user = fixture_add_user()

    # Get login
    # ---------
    test_app.get('/auth/login/')
    assert 'mediagoblin/auth/login.html' in template.TEMPLATE_TEST_CONTEXT

    # Failed login - blank form
    # -------------------------
    template.clear_test_template_context()
    response = test_app.post('/auth/login/')
    context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/login.html']
    form = context['login_form']
    assert form.username.errors == [u'This field is required.']

    # Failed login - blank user
    # -------------------------
    template.clear_test_template_context()
    response = test_app.post('/auth/login/', {'password': u'toast'})
    context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/login.html']
    form = context['login_form']
    assert form.username.errors == [u'This field is required.']

    # Failed login - blank password
    # -----------------------------
    template.clear_test_template_context()
    response = test_app.post('/auth/login/', {'username': u'chris'})
    assert 'mediagoblin/auth/login.html' in template.TEMPLATE_TEST_CONTEXT

    # Failed login - bad user
    # -----------------------
    template.clear_test_template_context()
    response = test_app.post('/auth/login/', {
        'username': u'steve',
        'password': '******'
    })
    context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/login.html']
    assert context['login_failed']

    # Failed login - bad password
    # ---------------------------
    template.clear_test_template_context()
    response = test_app.post('/auth/login/', {
        'username': u'chris',
        'password': '******'
    })
    context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/login.html']
    assert context['login_failed']

    # Successful login
    # ----------------
    template.clear_test_template_context()
    response = test_app.post('/auth/login/', {
        'username': u'chris',
        'password': '******'
    })

    # User should be redirected
    response.follow()
    assert urlparse.urlsplit(response.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)

    # Successful logout
    # -----------------
    template.clear_test_template_context()
    response = test_app.get('/auth/logout/')

    # Should be redirected to index page
    response.follow()
    assert urlparse.urlsplit(response.location)[2] == '/'
    assert 'mediagoblin/root.html' in template.TEMPLATE_TEST_CONTEXT

    # Make sure the user is not in the session
    context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
    session = context['request'].session
    assert 'user_id' not in session

    # User is redirected to custom URL if POST['next'] is set
    # -------------------------------------------------------
    template.clear_test_template_context()
    response = test_app.post('/auth/login/', {
        'username': u'chris',
        'password': '******',
        'next': '/u/chris/'
    })
    assert urlparse.urlsplit(response.location)[2] == '/u/chris/'

    ## Verify that username is lowercased on login attempt
    template.clear_test_template_context()
    response = test_app.post('/auth/login/', {
        'username': u'ANDREW',
        'password': '******'
    })
    context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/login.html']
    form = context['login_form']

    # Username should no longer be uppercased; it should be lowercased
    assert not form.username.data == u'ANDREW'
    assert form.username.data == u'andrew'
コード例 #58
0
ファイル: test_misc.py プロジェクト: gitGNU/gnu_mediagoblin
def test_user_deletes_other_comments(test_app):
    user_a = fixture_add_user(u"chris_a")
    user_b = fixture_add_user(u"chris_b")

    media_a = fixture_media_entry(uploader=user_a.id,
                                  save=False,
                                  expunge=False,
                                  fake_upload=False)
    media_b = fixture_media_entry(uploader=user_b.id,
                                  save=False,
                                  expunge=False,
                                  fake_upload=False)
    Session.add(media_a)
    Session.add(media_b)
    Session.flush()

    # Create all 4 possible comments:
    for u in (user_a, user_b):
        for m in (media_a, media_b):
            cmt = TextComment()
            cmt.actor = u.id
            cmt.content = u"Some Comment"
            Session.add(cmt)
            # think i need this to get the command ID
            Session.flush()

            link = Comment()
            link.target = m
            link.comment = cmt
            Session.add(link)

    Session.flush()

    usr_cnt1 = User.query.count()
    med_cnt1 = MediaEntry.query.count()
    cmt_cnt1 = Comment.query.count()

    User.query.get(user_a.id).delete(commit=False)

    usr_cnt2 = User.query.count()
    med_cnt2 = MediaEntry.query.count()
    cmt_cnt2 = Comment.query.count()

    # One user deleted
    assert usr_cnt2 == usr_cnt1 - 1
    # One media gone
    assert med_cnt2 == med_cnt1 - 1
    # Three of four comments gone.
    assert cmt_cnt2 == cmt_cnt1 - 3

    User.query.get(user_b.id).delete()

    usr_cnt2 = User.query.count()
    med_cnt2 = MediaEntry.query.count()
    cmt_cnt2 = Comment.query.count()

    # All users gone
    assert usr_cnt2 == usr_cnt1 - 2
    # All media gone
    assert med_cnt2 == med_cnt1 - 2
    # All comments gone
    assert cmt_cnt2 == cmt_cnt1 - 4