示例#1
0
    def test_version_race(self):
        # threads must not throw DuplicateKeyError
        # details https://sourceforge.net/p/allura/tickets/7647/
        import time
        import random
        from threading import Thread, Lock

        page = Page.upsert('test-page')
        page.commit()

        lock = Lock()
        def run(n):
            setup_global_objects()
            for i in range(10):
                page = Page.query.get(title='test-page')
                page.text = 'Test Page %s.%s' % (n, i)
                time.sleep(random.random())
                # tests use mim (mongo-in-memory), which isn't thread-safe
                lock.acquire()
                try:
                    page.commit()
                finally:
                    lock.release()

        t1 = Thread(target=lambda: run(1))
        t2 = Thread(target=lambda: run(2))
        t1.start()
        t2.start()
        t1.join()
        t2.join()

        page = Page.query.get(title='test-page')
        # 10 changes by each thread + initial upsert
        assert page.history().count() == 21, page.history().count()
示例#2
0
    def test_version_race(self):
        # threads must not throw DuplicateKeyError
        # details https://sourceforge.net/p/allura/tickets/7647/
        import time
        import random
        from threading import Thread, Lock

        page = Page.upsert('test-page')
        page.commit()

        lock = Lock()

        def run(n):
            setup_global_objects()
            for i in range(10):
                page = Page.query.get(title='test-page')
                page.text = 'Test Page %s.%s' % (n, i)
                time.sleep(random.random())
                # tests use mim (mongo-in-memory), which isn't thread-safe
                lock.acquire()
                try:
                    page.commit()
                finally:
                    lock.release()

        t1 = Thread(target=lambda: run(1))
        t2 = Thread(target=lambda: run(2))
        t1.start()
        t2.start()
        t1.join()
        t2.join()

        page = Page.query.get(title='test-page')
        # 10 changes by each thread + initial upsert
        assert page.history().count() == 21, page.history().count()
示例#3
0
def test_post_url_paginated_with_artifact():
    """Post.url_paginated should return link to attached artifact, if any"""
    from forgewiki.model import Page
    page = Page.upsert(title='Test Page')
    thread = page.discussion_thread
    comment = thread.post('Comment')
    url = page.url() + '?limit=50#' + comment.slug
    assert_equals(comment.url_paginated(), url)
示例#4
0
def test_post_url_paginated_with_artifact():
    """Post.url_paginated should return link to attached artifact, if any"""
    from forgewiki.model import Page
    page = Page.upsert(title='Test Page')
    thread = page.discussion_thread
    comment = thread.post('Comment')
    url = page.url() + '?limit=25#' + comment.slug
    assert_equals(comment.url_paginated(), url)
示例#5
0
    def test_authors(self):
        user = M.User.by_username('test-user')
        admin = M.User.by_username('test-admin')
        with h.push_config(c, user=admin):
            page = Page.upsert('test-admin')
            page.text = 'admin'
            page.commit()

        with h.push_config(c, user=user):
            page.text = 'user'
            page.commit()

        authors = page.authors()
        assert len(authors) == 2
        assert user in authors
        assert admin in authors

        user.disabled = True
        session(user).flush(user)

        authors = page.authors()
        assert len(authors) == 1
        assert user not in authors
        assert admin in authors
示例#6
0
    def test_authors(self):
        user = M.User.by_username('test-user')
        admin = M.User.by_username('test-admin')
        with h.push_config(c, user=admin):
            page = Page.upsert('test-admin')
            page.text = 'admin'
            page.commit()

        with h.push_config(c, user=user):
            page.text = 'user'
            page.commit()

        authors = page.authors()
        assert len(authors) == 2
        assert user in authors
        assert admin in authors

        user.disabled = True
        session(user).flush(user)

        authors = page.authors()
        assert len(authors) == 1
        assert user not in authors
        assert admin in authors