Exemplo n.º 1
0
def test_not_subscribed():
    pg = WM.Page(title='TestPage4c')
    M.Mailbox.unsubscribe(user_id=c.user._id,
                          project_id=c.project._id,
                          app_config_id=c.app.config._id)
    assert not pg.subscribed(include_parents=True)
    assert not pg.subscribed(include_parents=False)
Exemplo n.º 2
0
def test_versioning():
    pg = WM.Page(title='TestPage3')
    with patch('allura.model.artifact.request',
               Request.blank('/', remote_addr='1.1.1.1')):
        pg.commit()
    ThreadLocalORMSession.flush_all()
    pg.text = 'Here is some text'
    pg.commit()
    ThreadLocalORMSession.flush_all()
    ss = pg.get_version(1)
    assert ss.author.logged_ip == '1.1.1.1'
    assert ss.index()['is_history_b']
    assert ss.shorthand_id() == pg.shorthand_id() + '#1'
    assert ss.title == pg.title
    assert ss.text != pg.text
    ss = pg.get_version(-1)
    assert ss.index()['is_history_b']
    assert ss.shorthand_id() == pg.shorthand_id() + '#2'
    assert ss.title == pg.title
    assert ss.text == pg.text
    assert_raises(IndexError, pg.get_version, 42)
    pg.revert(1)
    pg.commit()
    ThreadLocalORMSession.flush_all()
    assert ss.text != pg.text
    assert pg.history().count() == 3
Exemplo n.º 3
0
def test_artifact():
    pg = WM.Page(title='TestPage1')
    assert pg.project == c.project
    assert pg.project_id == c.project._id
    assert pg.app.config == c.app.config
    assert pg.app_config == c.app.config
    u = M.User.query.get(username='******')
    pr = u.project_role()
    ThreadLocalORMSession.flush_all()
    REGISTRY.register(allura.credentials, allura.lib.security.Credentials())
    assert not security.has_access(pg, 'delete')(user=u)
    pg.acl.append(M.ACE.allow(pr._id, 'delete'))
    ThreadLocalORMSession.flush_all()
    c.memoize_cache = {}
    assert security.has_access(pg, 'delete')(user=u)
    pg.acl.pop()
    ThreadLocalORMSession.flush_all()
    c.memoize_cache = {}
    assert not security.has_access(pg, 'delete')(user=u)
    idx = pg.index()
    assert 'title' in idx
    assert 'url_s' in idx
    assert 'project_id_s' in idx
    assert 'mount_point_s' in idx
    assert 'type_s' in idx
    assert 'id' in idx
    assert idx['id'] == pg.index_id()
    assert 'text' in idx
    assert 'TestPage' in pg.shorthand_id()
    assert pg.link_text() == pg.shorthand_id()
Exemplo n.º 4
0
def test_artifactlink():
    pg = WM.Page(title='TestPage2')
    q = M.Shortlink.query.find(
        dict(project_id=c.project._id,
             app_config_id=c.app.config._id,
             link=pg.shorthand_id()))
    assert q.count() == 0
    ThreadLocalORMSession.flush_all()
    M.MonQTask.run_ready()
    ThreadLocalORMSession.flush_all()
    assert q.count() == 1
    assert M.Shortlink.lookup('[TestPage2]')
    assert M.Shortlink.lookup('[wiki:TestPage2]')
    assert M.Shortlink.lookup('[test:wiki:TestPage2]')
    assert not M.Shortlink.lookup('[test:wiki:TestPage2:foo]')
    assert not M.Shortlink.lookup('[Wiki:TestPage2]')
    assert not M.Shortlink.lookup('[TestPage2_no_such_page]')
    c.project.uninstall_app('wiki')
    ThreadLocalORMSession.flush_all()
    assert not M.Shortlink.lookup('[wiki:TestPage2]')
    pg.delete()
    ThreadLocalORMSession.flush_all()
    M.MonQTask.run_ready()
    ThreadLocalORMSession.flush_all()
    assert q.count() == 0
Exemplo n.º 5
0
    def test_commit(self):
        assert self.rev.primary() is self.rev
        assert self.rev.index_id().startswith('allura/model/repo/Commit#')
        self.rev.author_url
        self.rev.committer_url
        assert self.rev.tree._id == self.rev.tree_id
        assert self.rev.summary == self.rev.message.splitlines()[0]
        assert self.rev.shorthand_id() == '[1e146e]'
        assert self.rev.symbolic_ids == (['master'], ['foo'
                                                      ]), self.rev.symbolic_ids
        assert self.rev.url() == ('/p/test/src-git/ci/'
                                  '1e146e67985dcd71c74de79613719bef7bddca4a/')
        all_cis = list(self.repo.log(self.rev._id, id_only=True))
        assert len(all_cis) == 4
        c.lcid_cache = {}
        self.rev.tree.ls()
        # print self.rev.tree.readme()
        assert_equal(self.rev.tree.readme(),
                     ('README', 'This is readme\nAnother Line\n'))
        assert self.rev.tree.path() == '/'
        assert self.rev.tree.url() == (
            '/p/test/src-git/ci/'
            '1e146e67985dcd71c74de79613719bef7bddca4a/'
            'tree/')
        self.rev.tree.by_name['README']
        assert self.rev.tree.is_blob('README') == True
        ThreadLocalORMSession.close_all()
        c.app = None
        converted = g.markdown.convert('[1e146e]')
        assert '1e146e' in converted, converted
        h.set_context('test', 'wiki', neighborhood='Projects')
        pg = WM.Page(title='Test Page',
                     text='This is a commit reference: [1e146e]')
        ThreadLocalORMSession.flush_all()
        M.MonQTask.run_ready()
        for ci in pg.related_artifacts():
            assert ci.shorthand_id() == '[1e146e]', ci.shorthand_id()
            assert ci.url() == ('/p/test/src-git/ci/'
                                '1e146e67985dcd71c74de79613719bef7bddca4a/')

        assert_equal(self.rev.authored_user, None)
        assert_equal(self.rev.committed_user, None)
        user = M.User.upsert('rick')
        email = user.claim_address('*****@*****.**')
        email.confirmed = True
        session(email).flush(email)
        rev = self.repo.commit(
            self.rev._id)  # to update cached values of LazyProperty
        assert_equal(rev.authored_user, user)
        assert_equal(rev.committed_user, user)
        assert_equal(
            sorted(rev.webhook_info.keys()),
            sorted([
                'id', 'url', 'timestamp', 'message', 'author', 'committer',
                'added', 'removed', 'renamed', 'modified', 'copied'
            ]))
Exemplo n.º 6
0
def test_last_updated_disabled(_datetime):
    c.project.last_updated = datetime(2014, 1, 1)
    _datetime.utcnow.return_value = datetime(2014, 1, 2)
    try:
        M.artifact_orm_session._get().skip_last_updated = True
        WM.Page(title='TestPage1')
        ThreadLocalORMSession.flush_all()
        assert_equal(c.project.last_updated, datetime(2014, 1, 1))
    finally:
        M.artifact_orm_session._get().skip_last_updated = False
Exemplo n.º 7
0
def test_artifact_index():
    pg = WM.Page(title='TestPage1')
    idx = pg.index()
    assert 'title' in idx
    assert 'url_s' in idx
    assert 'project_id_s' in idx
    assert 'mount_point_s' in idx
    assert 'type_s' in idx
    assert 'id' in idx
    assert idx['id'] == pg.index_id()
    assert 'text' in idx
    assert 'TestPage' in pg.shorthand_id()
    assert pg.link_text() == pg.shorthand_id()
Exemplo n.º 8
0
def test_artifact():
    pg = WM.Page(title='TestPage1')
    assert pg.project == c.project
    assert pg.project_id == c.project._id
    assert pg.app.config == c.app.config
    assert pg.app_config == c.app.config
    u = M.User.query.get(username='******')
    pr = M.ProjectRole.by_user(u, upsert=True)
    ThreadLocalORMSession.flush_all()
    REGISTRY.register(allura.credentials, allura.lib.security.Credentials())
    assert not security.has_access(pg, 'delete')(user=u)
    pg.acl.append(M.ACE.allow(pr._id, 'delete'))
    ThreadLocalORMSession.flush_all()
    assert security.has_access(pg, 'delete')(user=u)
    pg.acl.pop()
    ThreadLocalORMSession.flush_all()
    assert not security.has_access(pg, 'delete')(user=u)
Exemplo n.º 9
0
 def test_commit(self):
     assert self.rev.primary() is self.rev
     assert self.rev.index_id().startswith('allura/model/repo/Commit#')
     self.rev.author_url
     self.rev.committer_url
     assert self.rev.tree._id == self.rev.tree_id
     assert self.rev.summary == self.rev.message.splitlines()[0]
     assert self.rev.shorthand_id() == '[1e146e]'
     assert self.rev.symbolic_ids == (['master', 'zz'], [])
     assert self.rev.url() == (
         '/p/test/src-git/ci/'
         '1e146e67985dcd71c74de79613719bef7bddca4a/')
     all_cis = self.repo.log(self.rev._id, 0, 1000)
     assert len(all_cis) == 4
     assert_equal(self.repo.log(self.rev._id, 1,1000), all_cis[1:])
     assert_equal(self.repo.log(self.rev._id, 0,3), all_cis[:3])
     assert_equal(self.repo.log(self.rev._id, 1,2), all_cis[1:3])
     for ci in all_cis:
         ci.context()
     self.rev.tree.ls()
     # print self.rev.tree.readme()
     assert_equal(self.rev.tree.readme(), (
         'README', 'This is readme\nAnother Line\n'))
     assert self.rev.tree.path() == '/'
     assert self.rev.tree.url() == (
         '/p/test/src-git/ci/'
         '1e146e67985dcd71c74de79613719bef7bddca4a/'
         'tree/')
     self.rev.tree.by_name['README']
     assert self.rev.tree.is_blob('README') == True
     ThreadLocalORMSession.close_all()
     c.app = None
     converted = g.markdown.convert('[1e146e]')
     assert '1e146e' in converted, converted
     h.set_context('test', 'wiki', neighborhood='Projects')
     pg = WM.Page(
         title='Test Page', text='This is a commit reference: [1e146e]')
     ThreadLocalORMSession.flush_all()
     M.MonQTask.run_ready()
     for ci in pg.related_artifacts():
         assert ci.shorthand_id() == '[1e146e]', ci.shorthand_id()
         assert ci.url() == (
             '/p/test/src-git/ci/'
             '1e146e67985dcd71c74de79613719bef7bddca4a/')
Exemplo n.º 10
0
def test_get_discussion_thread_dupe():
    artif = WM.Page(title='TestSomeArtifact')
    thr1 = artif.get_discussion_thread()[0]
    thr1.post('thr1-post1')
    thr1.post('thr1-post2')
    thr2 = M.Thread.new(ref_id=thr1.ref_id)
    thr2.post('thr2-post1')
    thr2.post('thr2-post2')
    thr2.post('thr2-post3')
    thr3 = M.Thread.new(ref_id=thr1.ref_id)
    thr3.post('thr3-post1')
    thr4 = M.Thread.new(ref_id=thr1.ref_id)

    thread_q = M.Thread.query.find(dict(ref_id=artif.index_id()))
    assert_equal(thread_q.count(), 4)

    thread = artif.get_discussion_thread()[0]  # force cleanup
    threads = thread_q.all()
    assert_equal(len(threads), 1)
    assert_equal(len(thread.posts), 6)
    assert not any(p.deleted for p in thread.posts)  # normal thread deletion propagates to children, make sure that doesn't happen
Exemplo n.º 11
0
def test_versioning():
    pg = WM.Page(title='TestPage3')
    pg.commit()
    ThreadLocalORMSession.flush_all()
    pg.text = 'Here is some text'
    pg.commit()
    ThreadLocalORMSession.flush_all()
    ss = pg.get_version(1)
    assert ss.author.logged_ip == '1.1.1.1'
    assert ss.index()['is_history_b']
    assert ss.shorthand_id() == pg.shorthand_id() + '#1'
    assert ss.title == pg.title
    assert ss.text != pg.text
    ss = pg.get_version(-1)
    assert ss.index()['is_history_b']
    assert ss.shorthand_id() == pg.shorthand_id() + '#2'
    assert ss.title == pg.title
    assert ss.text == pg.text
    assert_raises(IndexError, pg.get_version, 42)
    pg.revert(1)
    pg.commit()
    ThreadLocalORMSession.flush_all()
    assert ss.text != pg.text
    assert pg.history().count() == 3
Exemplo n.º 12
0
def test_subscribed():
    pg = WM.Page(title='TestPage4a')
    assert pg.subscribed(
        include_parents=True)  # tool is subscribed to admins by default
    assert not pg.subscribed(include_parents=False)
Exemplo n.º 13
0
def test_last_updated(_datetime):
    c.project.last_updated = datetime(2014, 1, 1)
    _datetime.utcnow.return_value = datetime(2014, 1, 2)
    WM.Page(title='TestPage1')
    ThreadLocalORMSession.flush_all()
    assert_equal(c.project.last_updated, datetime(2014, 1, 2))
Exemplo n.º 14
0
def test_artifact_messageid():
    p = WM.Page(title='T')
    assert re.match(r'*****@*****.**' % str(p._id), p.message_id())
Exemplo n.º 15
0
def test_artifact_messageid():
    p = WM.Page(title='T')
    assert re.match(r'*****@*****.**' % str(p._id),
                    p.message_id())