Exemplo n.º 1
0
    def test_rename_page(self):
        cursor = self.db.cursor()
        data = (1, 42, 'joe', '::1', 'Bla bla', 'Testing', 0)
        cursor.execute("INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
                       ('TestPage',) + data)
        attachment = Attachment(self.env, 'wiki', 'TestPage')
        attachment.insert('foo.txt', StringIO(), 0, 1)
        
        page = WikiPage(self.env, 'TestPage')
        page.rename('PageRenamed')
        self.assertEqual('PageRenamed', page.name)
        
        cursor.execute("SELECT version,time,author,ipnr,text,comment,"
                       "readonly FROM wiki WHERE name=%s", ('PageRenamed',))
        self.assertEqual(data, cursor.fetchone())
        self.assertEqual(None, cursor.fetchone())
        
        attachments = Attachment.select(self.env, 'wiki', 'PageRenamed')
        self.assertEqual('foo.txt', attachments.next().filename)
        self.assertRaises(StopIteration, attachments.next)
        Attachment.delete_all(self.env, 'wiki', 'PageRenamed', self.db)

        old_page = WikiPage(self.env, 'TestPage')
        self.assertEqual(False, old_page.exists)
        
        cursor.execute("SELECT version,time,author,ipnr,text,comment,"
                       "readonly FROM wiki WHERE name=%s", ('TestPage',))
        self.assertEqual(None, cursor.fetchone())
        
        listener = TestWikiChangeListener(self.env)
        self.assertEqual((page, 'TestPage'), listener.renamed[0])
Exemplo n.º 2
0
    def test_rename_page(self):
        data = (1, 42, 'joe', '::1', 'Bla bla', 'Testing', 0)
        self.env.db_transaction(
            "INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
            ('TestPage',) + data)
        attachment = Attachment(self.env, 'wiki', 'TestPage')
        attachment.insert('foo.txt', StringIO(), 0, 1)

        page = WikiPage(self.env, 'TestPage')
        page.rename('PageRenamed')
        self.assertEqual('PageRenamed', page.name)
        self.assertEqual('PageRenamed', page.resource.id)

        self.assertEqual([data], self.env.db_query("""
            SELECT version, time, author, ipnr, text, comment, readonly
            FROM wiki WHERE name=%s
            """, ('PageRenamed',)))

        attachments = Attachment.select(self.env, 'wiki', 'PageRenamed')
        self.assertEqual('foo.txt', attachments.next().filename)
        self.assertRaises(StopIteration, attachments.next)
        Attachment.delete_all(self.env, 'wiki', 'PageRenamed')

        old_page = WikiPage(self.env, 'TestPage')
        self.assertFalse(old_page.exists)

        self.assertEqual([], self.env.db_query("""
            SELECT version, time, author, ipnr, text, comment, readonly
            FROM wiki WHERE name=%s
            """, ('TestPage',)))

        listener = TestWikiChangeListener(self.env)
        self.assertEqual((page, 'TestPage'), listener.renamed[0])
Exemplo n.º 3
0
    def test_existing_page(self):
        t = datetime(2001, 1, 1, 1, 1, 1, 0, utc)
        self.env.db_transaction(
            "INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
            ('TestPage', 1, to_utimestamp(t), 'joe', '::1', 'Bla bla',
             'Testing', 0))

        page = WikiPage(self.env, 'TestPage')
        self.assertTrue(page.exists)
        self.assertEqual('TestPage', page.name)
        self.assertEqual(1, page.version)
        self.assertIsNone(page.resource.version)   # FIXME: Intentional?
        self.assertEqual('Bla bla', page.text)
        self.assertEqual(0, page.readonly)
        self.assertEqual('joe', page.author)
        self.assertEqual('Testing', page.comment)
        self.assertEqual(t, page.time)

        history = list(page.get_history())
        self.assertEqual(1, len(history))
        self.assertEqual((1, t, 'joe', 'Testing', '::1'), history[0])

        page = WikiPage(self.env, 'TestPage', 1)
        self.assertEqual(1, page.resource.version)
        self.assertEqual(1, page.version)

        resource = Resource('wiki', 'TestPage')
        page = WikiPage(self.env, resource, 1)
        self.assertEqual(1, page.version)
Exemplo n.º 4
0
    def process_request(self, req):
        req.perm.assert_permission ('WIKI_MODIFY')
        page_name = req.args['target_page'][req.args['target_page'].find('wiki')+5:]
        p = WikiPage(self.env, page_name )

        author_name = req.authname
        comment_text = req.args['comment']
        comment_parent = req.args['comment_parent']
        dt = datetime.now()
        comment_date = dt.strftime("%Y-%m-%d %H:%M:%S")
        comment_id = "%032x" % random.getrandbits(128)
        redirect_url = "%s%s#%s" % (req.base_path, req.args['target_page'],comment_id)
        changeset_comment = "%s..." % comment_text[:20]

        insertion_index = string.find( p.text, "=%s" % comment_parent )
        if ( insertion_index != -1 ):
            heads = string.count(p.text,"{{{#!WikiComments",0,insertion_index)
            tails = string.count(p.text,"}}}",0,insertion_index)
            level = heads - tails
            padding = ""
            comment_out = '%s{{{#!WikiComments author="%s" date="%s" id="%s""\n%s%s\n%s=%s\n%s}}}\n' \
                % (padding, author_name,comment_date,comment_id,padding,comment_text,padding,comment_id,padding)
            p.text = p.text[:insertion_index]+comment_out+p.text[insertion_index:]

        p.save( author_name, changeset_comment, req.remote_addr )
        req.redirect(redirect_url)
Exemplo n.º 5
0
    def _do_uploadPicture(self, req, userProfile, teamRosterData, req_arg_picture = 'tr_userProfile_picture' ):
        
        upload = req.args.get(req_arg_picture, None)
        if upload == None or not hasattr(upload, 'filename') or not upload.filename:
            return userProfile.picture_href
        
        if hasattr(upload.file, 'fileno'):
            size = os.fstat(upload.file.fileno())[6]
        else:
            upload.file.seek(0, 2) # seek to end of file
            size = upload.file.tell()
            upload.file.seek(0)
        if size == 0:
            raise TracError(_("Can't upload empty file"))

        filename = upload.filename
        filename = filename.replace('\\', '/').replace(':', '/')        
        filename = os.path.basename(filename)
        
        if not filename:
            raise TracError(_('No file uploaded'))
        
        page = WikiPage(self.env,  self.teamRoster_wikiPage)
        if not page.exists:
            page.text="= Team Roster Pictures ="
            page.save( 'trac', 'Page created by tracteamroster component',  req.remote_addr)
       
              
        attachment = Attachment(self.env, 'wiki', self.teamRoster_wikiPage)
        attachment.author = get_reporter_id(req, 'author')
        attachment.ipnr = req.remote_addr
        attachment.insert('_'.join([userProfile.id, filename]), upload.file, size)
        
        return req.href('/'.join(['raw-attachment', 'wiki',self.teamRoster_wikiPage,attachment.filename]))
 def test_wiki_page_unicode_error(self):
     import pkg_resources
     import define
     text = open(pkg_resources.resource_filename(define.__name__, 'default-pages/DefineGuide%2FTicketTutorial')).read()
     page = WikiPage(self.env, 'TicketTutorial')
     page.text = text.decode('utf-8')
     page.save('olle', 'Comment', 'define.logica.com')
     so = self._get_so()
     self.assertEquals('%s:wiki:TicketTutorial' % self.basename, so.doc_id)
Exemplo n.º 7
0
 def _create_wiki_page(self, name=None):
     name = name or self.INITIAL_NAME
     wiki_page = WikiPage(self.env, name)
     wiki_page.text = self.INITIAL_TEXT
     wiki_page.save(
         self.INITIAL_AUTHOR,
         self.INITIAL_COMMENT,
         self.INITIAL_REMOTE_ADDRESS)
     return wiki_page
Exemplo n.º 8
0
def test_parseTestcase_parseWikiPage(build_trac_env):
    env = build_trac_env

    wikipage = WikiPage(env, "TcTestplanCreate")
    wikipage.text = TESTCASE.decode("utf-8")
    wikipage.save("pytest", "comment", "127.0.0.1")

    tcp = TestcaseParser(env)
    testcase = tcp.parseTestcase(pagename="TcTestplanCreate")
    assert len(testcase.actions) == 5
Exemplo n.º 9
0
 def test_can_index_renamed_event(self):
     #arrange
     self.insert_wiki(self.DUMMY_PAGE_NAME)
     page = WikiPage(self.env, self.DUMMY_PAGE_NAME)
     page.rename("NewPageName")
     #act
     results = self.search_api.query("*:*")
     #assert
     self.print_result(results)
     self.assertEqual(1, results.hits)
     self.assertEqual("NewPageName", results.docs[0]["id"])
Exemplo n.º 10
0
 def _term_desc(self, target):
     page = self._wiki_prefix + target
     content = WikiPage(self.env, page).text
     lines = content.splitlines()
     if len(lines) <= 0:
         return target
     m = self._desc_regex.match(lines[0])
     if m:
         return m.group(1)
     else:
         return self._term_ns + ":" + target
Exemplo n.º 11
0
 def test_can_index_changed_event(self):
     #arrange
     self.insert_wiki(self.DUMMY_PAGE_NAME, "Text to be changed")
     page = WikiPage(self.env, self.DUMMY_PAGE_NAME)
     page.text = "changed text with keyword"
     page.save("anAuthor", "some comment", "::1")
     #act
     results = self.search_api.query("*:*")
     #assert
     self.print_result(results)
     self.assertEqual(1, results.hits)
     doc = results.docs[0]
     self.assertEqual("changed text with keyword", doc["content"])
Exemplo n.º 12
0
    def test_create_page(self):
        page = WikiPage(self.env)
        page.name = "TestPage"
        page.text = "Bla bla"
        page.save("joe", "Testing", "::1", 42)

        cursor = self.db.cursor()
        cursor.execute(
            "SELECT version,time,author,ipnr,text,comment," "readonly FROM wiki WHERE name=%s", ("TestPage",)
        )
        self.assertEqual((1, 42, "joe", "::1", "Bla bla", "Testing", 0), cursor.fetchone())

        listener = TestWikiChangeListener(self.env)
        self.assertEqual(page, listener.added[0])
Exemplo n.º 13
0
    def test_existing_page(self):
        cursor = self.db.cursor()
        cursor.execute(
            "INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
            ("TestPage", 0, 42, "joe", "::1", "Bla bla", "Testing", 0),
        )

        page = WikiPage(self.env, "TestPage")
        self.assertEqual("TestPage", page.name)
        self.assertEqual(0, page.version)
        self.assertEqual("Bla bla", page.text)
        self.assertEqual(False, page.readonly)
        history = list(page.get_history())
        self.assertEqual(1, len(history))
        self.assertEqual((0, 42, "joe", "Testing", "::1"), history[0])
Exemplo n.º 14
0
    def test_existing_page(self):
        t = datetime(2001, 1, 1, 1, 1, 1, 0, utc)
        cursor = self.db.cursor()
        cursor.execute("INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
                       ('TestPage', 0, to_timestamp(t), 'joe', '::1', 'Bla bla',
                        'Testing', 0))

        page = WikiPage(self.env, 'TestPage')
        self.assertEqual('TestPage', page.name)
        self.assertEqual(0, page.version)
        self.assertEqual('Bla bla', page.text)
        self.assertEqual(False, page.readonly)
        history = list(page.get_history())
        self.assertEqual(1, len(history))
        self.assertEqual((0, t, 'joe', 'Testing', '::1'), history[0])
Exemplo n.º 15
0
    def test_create_page(self):
        page = WikiPage(self.env)
        page.name = 'TestPage'
        page.text = 'Bla bla'
        t = datetime(2001, 1, 1, 1, 1, 1, 0, utc)
        page.save('joe', 'Testing', '::1', t)

        cursor = self.db.cursor()
        cursor.execute("SELECT version,time,author,ipnr,text,comment,"
                       "readonly FROM wiki WHERE name=%s", ('TestPage',))
        self.assertEqual((1, to_timestamp(t), 'joe', '::1', 'Bla bla', 'Testing', 0),
                         cursor.fetchone())

        listener = TestWikiChangeListener(self.env)
        self.assertEqual(page, listener.added[0])
Exemplo n.º 16
0
    def test_delete_page_last_version(self):
        cursor = self.db.cursor()
        cursor.execute("INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
                       ('TestPage', 1, 42, 'joe', '::1', 'Bla bla', 'Testing',
                        0))

        page = WikiPage(self.env, 'TestPage')
        page.delete(version=1)

        self.assertEqual(False, page.exists)

        cursor.execute("SELECT version,time,author,ipnr,text,comment,"
                       "readonly FROM wiki WHERE name=%s", ('TestPage',))
        self.assertEqual(None, cursor.fetchone())

        listener = TestWikiChangeListener(self.env)
        self.assertEqual(page, listener.deleted[0])
Exemplo n.º 17
0
    def test_delete_page_last_version(self):
        self.env.db_transaction(
            "INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
            ('TestPage', 1, 42, 'joe', '::1', 'Bla bla', 'Testing', 0))

        page = WikiPage(self.env, 'TestPage')
        page.delete(version=1)

        self.assertFalse(page.exists)

        self.assertEqual([], self.env.db_query("""
            SELECT version, time, author, ipnr, text, comment, readonly
            FROM wiki WHERE name=%s
            """, ('TestPage',)))

        listener = TestWikiChangeListener(self.env)
        self.assertEqual(page, listener.deleted[0])
    def test_wiki_page(self):
        page = WikiPage(self.env, 'NewPage')
        page.text = 'Lorem ipsum dolor sit amet'
        # TODO Tags
        page.save('santa', 'Commment', 'northpole.example.com')
        so = self._get_so()
        self.assertEquals('%s:wiki:NewPage' % self.basename, so.doc_id)
        self.assertEquals('wiki', so.realm)
        self.assertEquals('NewPage', so.id)
        self.assertTrue('NewPage' in so.title)
        self.assertTrue('Lorem ipsum' in so.title)
        self.assertEquals('santa', so.author)
        self.assertEquals(page.time, so.created)
        self.assertEquals(page.time, so.changed)
        self.assertTrue('santa' in so.involved)
        self.assertTrue('Lorem ipsum' in so.oneline)
        self.assertTrue('Lorem ipsum' in so.body)

        original_time = page.time
        page.text = 'No latin filler here'
        page.save('Jack Sprat', 'Could eat no fat', 'dinnertable.local')
        so = self._get_so()
        self.assertEquals('%s:wiki:NewPage' % self.basename, so.doc_id)
        self.assertEquals('wiki', so.realm)
        self.assertEquals('NewPage', so.id)
        self.assertEquals(original_time, so.created)
        self.assertEquals(page.time, so.changed)
        self.assertFalse('Lorem ipsum' in so.body)
        self.assertTrue('No latin filler here' in so.body)
        self.assertTrue('Could eat no fat' in so.comments)
Exemplo n.º 19
0
    def test_delete_page_version(self):
        self.env.db_transaction.executemany(
            "INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
            [('TestPage', 1, 42, 'joe', '::1', 'Bla bla', 'Testing', 0),
             ('TestPage', 2, 43, 'kate', '192.168.0.11', 'Bla', 'Changing', 0)])

        page = WikiPage(self.env, 'TestPage')
        page.delete(version=2)

        self.assertEqual(True, page.exists)
        self.assertEqual(
            [(1, 42, 'joe', '::1', 'Bla bla', 'Testing', 0)],
            self.env.db_query("""
                SELECT version, time, author, ipnr, text, comment, readonly
                FROM wiki WHERE name=%s
                """, ('TestPage',)))

        listener = TestWikiChangeListener(self.env)
        self.assertEqual(page, listener.deleted_version[0])
Exemplo n.º 20
0
    def test_delete_page_version(self):
        self.env.db_transaction.executemany(
            "INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
            [('TestPage', 1, 42, 'joe', '::1', 'Bla bla', 'Testing', 0),
             ('TestPage', 2, 43, 'kate', '192.168.0.11', 'Bla', 'Changing', 0)])

        page = WikiPage(self.env, 'TestPage')
        page.delete(version=2)

        self.assertTrue(page.exists)
        self.assertEqual(
            [(1, 42, 'joe', '::1', 'Bla bla', 'Testing', 0)],
            self.env.db_query("""
                SELECT version, time, author, ipnr, text, comment, readonly
                FROM wiki WHERE name=%s
                """, ('TestPage',)))

        listener = TestWikiChangeListener(self.env)
        self.assertEqual(page, listener.deleted_version[0])
Exemplo n.º 21
0
    def get_uploaded_file_href(self, req, user, field, req_field):
        """Returns uploaded file's url
        
        @param req: trac.web.req
        @param user: tracusermanager.api.User
        @param field: str
        @param req_field: str 
        @return: str
        """
        
        # validate request field
        upload = req.args.get(req_field, None)
        if upload == None or not hasattr(upload, 'filename') or not upload.filename:
            return user[field]
        
        if hasattr(upload.file, 'fileno'):
            size = os.fstat(upload.file.fileno())[6]
        else:
            upload.file.seek(0, 2) # seek to end of file
            size = upload.file.tell()
            upload.file.seek(0)
        if size == 0:
            raise TracError(_("Can't upload empty file"))

        filename = upload.filename
        filename = filename.replace('\\', '/').replace(':', '/')        
        filename = os.path.basename(filename)
        
        if not filename:
            raise TracError(_('No file uploaded'))
        
        page = WikiPage(self.env,  self.attachments_wikiPage)
        if not page.exists:
            page.text="= UserManager's Attachments ="
            page.save( 'trac', 'Page created by tracusermanager.profile component',  req.remote_addr)
       
        attachment = Attachment(self.env, 'wiki', self.attachments_wikiPage)
        attachment.author = get_reporter_id(req, 'author')
        attachment.ipnr = req.remote_addr
        attachment.description = (_("%s\'s Avatar") % (user.username))
        attachment.insert('_'.join([user.username, filename]), upload.file, size)
        
        return req.href('/'.join(['raw-attachment', 'wiki',self.attachments_wikiPage, attachment.filename]))
Exemplo n.º 22
0
Arquivo: model.py Projeto: t2y/trac
    def test_delete_page_last_version(self):
        self.env.db_transaction(
            "INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
            ('TestPage', 1, 42, 'joe', '::1', 'Bla bla', 'Testing', 0))

        page = WikiPage(self.env, 'TestPage')
        page.delete(version=1)

        self.assertFalse(page.exists)

        self.assertEqual([],
                         self.env.db_query(
                             """
            SELECT version, time, author, ipnr, text, comment, readonly
            FROM wiki WHERE name=%s
            """, ('TestPage', )))

        listener = TestWikiChangeListener(self.env)
        self.assertEqual(page, listener.deleted[0])
Exemplo n.º 23
0
Arquivo: model.py Projeto: t2y/trac
 def test_new_page(self):
     page = WikiPage(self.env)
     self.assertFalse(page.exists)
     self.assertIsNone(page.name)
     self.assertEqual(0, page.version)
     self.assertEqual('', page.text)
     self.assertEqual(0, page.readonly)
     self.assertEqual('', page.author)
     self.assertEqual('', page.comment)
     self.assertIsNone(page.time)
Exemplo n.º 24
0
    def test_delete_page(self):
        cursor = self.db.cursor()
        cursor.execute(
            "INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
            ("TestPage", 1, 42, "joe", "::1", "Bla bla", "Testing", 0),
        )

        page = WikiPage(self.env, "TestPage")
        page.delete()

        self.assertEqual(False, page.exists)

        cursor.execute(
            "SELECT version,time,author,ipnr,text,comment," "readonly FROM wiki WHERE name=%s", ("TestPage",)
        )
        self.assertEqual(None, cursor.fetchone())

        listener = TestWikiChangeListener(self.env)
        self.assertEqual(page, listener.deleted[0])
Exemplo n.º 25
0
    def test_delete_page_version(self):
        cursor = self.db.cursor()
        cursor.executemany("INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
                           [('TestPage', 1, 42, 'joe', '::1', 'Bla bla',
                            'Testing', 0),
                            ('TestPage', 2, 43, 'kate', '192.168.0.101', 'Bla',
                            'Changing', 0)])

        page = WikiPage(self.env, 'TestPage')
        page.delete(version=2)

        self.assertEqual(True, page.exists)

        cursor.execute("SELECT version,time,author,ipnr,text,comment,"
                       "readonly FROM wiki WHERE name=%s", ('TestPage',))
        self.assertEqual((1, 42, 'joe', '::1', 'Bla bla', 'Testing', 0),
                         cursor.fetchone())
        self.assertEqual(None, cursor.fetchone())

        listener = TestWikiChangeListener(self.env)
        self.assertEqual(page, listener.deleted_version[0])
Exemplo n.º 26
0
    def test_delete_page_version(self):
        cursor = self.db.cursor()
        cursor.executemany("INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
                           [('TestPage', 1, 42, 'joe', '::1', 'Bla bla',
                            'Testing', 0),
                            ('TestPage', 2, 43, 'kate', '192.168.0.101', 'Bla',
                            'Changing', 0)])

        page = WikiPage(self.env, 'TestPage')
        page.delete(version=2)

        self.assertEqual(True, page.exists)

        cursor.execute("SELECT version,time,author,ipnr,text,comment,"
                       "readonly FROM wiki WHERE name=%s", ('TestPage',))
        self.assertEqual((1, 42, 'joe', '::1', 'Bla bla', 'Testing', 0),
                         cursor.fetchone())
        self.assertEqual(None, cursor.fetchone())

        listener = TestWikiChangeListener(self.env)
        self.assertEqual(page, listener.deleted_version[0])
Exemplo n.º 27
0
    def test_update_page(self):
        cursor = self.db.cursor()
        t = datetime(2001, 1, 1, 1, 1, 1, 0, utc)
        t2 = datetime(2002, 1, 1, 1, 1, 1, 0, utc)
        cursor.execute("INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
                       ('TestPage', 1, to_timestamp(t), 'joe', '::1', 'Bla bla',
                        'Testing', 0))

        page = WikiPage(self.env, 'TestPage')
        page.text = 'Bla'
        page.save('kate', 'Changing', '192.168.0.101', t2)
        self.assertEqual(2, page.resource.version)

        cursor.execute("SELECT version,time,author,ipnr,text,comment,"
                       "readonly FROM wiki WHERE name=%s", ('TestPage',))
        self.assertEqual((1, to_timestamp(t), 'joe', '::1', 'Bla bla', 'Testing', 0),
                         cursor.fetchone())
        self.assertEqual((2, to_timestamp(t2), 'kate', '192.168.0.101', 'Bla',
                          'Changing', 0), cursor.fetchone())

        listener = TestWikiChangeListener(self.env)
        self.assertEqual((page, 2, t2, 'Changing', 'kate', '192.168.0.101'),
                         listener.changed[0])

        page = WikiPage(self.env, 'TestPage')
        history = list(page.get_history())
        self.assertEqual(2, len(history))
        self.assertEqual((2, t2, 'kate', 'Changing', '192.168.0.101'),
                         history[0])
        self.assertEqual((1, t, 'joe', 'Testing', '::1'), history[1])
Exemplo n.º 28
0
    def test_update_page(self):
        cursor = self.db.cursor()
        cursor.execute(
            "INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
            ("TestPage", 1, 42, "joe", "::1", "Bla bla", "Testing", 0),
        )

        page = WikiPage(self.env, "TestPage")
        page.text = "Bla"
        page.save("kate", "Changing", "192.168.0.101", 43)

        cursor.execute(
            "SELECT version,time,author,ipnr,text,comment," "readonly FROM wiki WHERE name=%s", ("TestPage",)
        )
        self.assertEqual((1, 42, "joe", "::1", "Bla bla", "Testing", 0), cursor.fetchone())
        self.assertEqual((2, 43, "kate", "192.168.0.101", "Bla", "Changing", 0), cursor.fetchone())

        listener = TestWikiChangeListener(self.env)
        self.assertEqual((page, 2, 43, "Changing", "kate", "192.168.0.101"), listener.changed[0])

        page = WikiPage(self.env, "TestPage")
        history = list(page.get_history())
        self.assertEqual(2, len(history))
        self.assertEqual((2, 43, "kate", "Changing", "192.168.0.101"), history[0])
        self.assertEqual((1, 42, "joe", "Testing", "::1"), history[1])
Exemplo n.º 29
0
Arquivo: model.py Projeto: t2y/trac
    def test_create_page(self):
        page = WikiPage(self.env)
        page.name = 'TestPage'
        page.text = 'Bla bla'
        t = datetime(2001, 1, 1, 1, 1, 1, 0, utc)
        page.save('joe', 'Testing', '::1', t)

        self.assertTrue(page.exists)
        self.assertEqual(1, page.version)
        self.assertEqual(1, page.resource.version)
        self.assertEqual(0, page.readonly)
        self.assertEqual('joe', page.author)
        self.assertEqual('Testing', page.comment)
        self.assertEqual(t, page.time)

        self.assertEqual(
            [(1, to_utimestamp(t), 'joe', '::1', 'Bla bla', 'Testing', 0)],
            self.env.db_query(
                """
                SELECT version, time, author, ipnr, text, comment, readonly
                FROM wiki WHERE name=%s
                """, ('TestPage', )))

        listener = TestWikiChangeListener(self.env)
        self.assertEqual(page, listener.added[0])
Exemplo n.º 30
0
    def test_create_page(self):
        page = WikiPage(self.env)
        page.name = 'TestPage'
        page.text = 'Bla bla'
        t = datetime(2001, 1, 1, 1, 1, 1, 0, utc)
        page.save('joe', 'Testing', '::1', t)

        self.assertEqual(True, page.exists)
        self.assertEqual(1, page.version)
        self.assertEqual(1, page.resource.version)
        self.assertEqual(0, page.readonly)
        self.assertEqual('joe', page.author)
        self.assertEqual('Testing', page.comment)
        self.assertEqual(t, page.time)

        cursor = self.db.cursor()
        cursor.execute(
            "SELECT version,time,author,ipnr,text,comment,"
            "readonly FROM wiki WHERE name=%s", ('TestPage', ))
        self.assertEqual(
            (1, to_utimestamp(t), 'joe', '::1', 'Bla bla', 'Testing', 0),
            cursor.fetchone())

        listener = TestWikiChangeListener(self.env)
        self.assertEqual(page, listener.added[0])
Exemplo n.º 31
0
    def test_invalid_page_name(self):
        invalid_names = ('../Page', 'Page/..', 'Page/////SubPage',
                         'Page/./SubPage', '/PagePrefix', 'PageSuffix/')

        for name in invalid_names:
            page = WikiPage(self.env)
            page.name = name
            page.text = 'Bla bla'
            t = datetime(2001, 1, 1, 1, 1, 1, 0, utc)
            self.assertRaises(TracError, page.save, 'joe', 'Testing', '::1', t)

        page = WikiPage(self.env)
        page.name = 'TestPage'
        page.text = 'Bla bla'
        t = datetime(2001, 1, 1, 1, 1, 1, 0, utc)
        page.save('joe', 'Testing', '::1', t)
        for name in invalid_names:
            page = WikiPage(self.env, 'TestPage')
            self.assertRaises(TracError, page.rename, name)
Exemplo n.º 32
0
    def test_delete_page_version(self):
        cursor = self.db.cursor()
        cursor.executemany(
            "INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
            [
                ("TestPage", 1, 42, "joe", "::1", "Bla bla", "Testing", 0),
                ("TestPage", 2, 43, "kate", "192.168.0.101", "Bla", "Changing", 0),
            ],
        )

        page = WikiPage(self.env, "TestPage")
        page.delete(version=2)

        self.assertEqual(True, page.exists)

        cursor.execute(
            "SELECT version,time,author,ipnr,text,comment," "readonly FROM wiki WHERE name=%s", ("TestPage",)
        )
        self.assertEqual((1, 42, "joe", "::1", "Bla bla", "Testing", 0), cursor.fetchone())
        self.assertEqual(None, cursor.fetchone())

        listener = TestWikiChangeListener(self.env)
        self.assertEqual(page, listener.deleted_version[0])
Exemplo n.º 33
0
Arquivo: model.py Projeto: t2y/trac
    def test_rename_page(self):
        data = (1, 42, 'joe', '::1', 'Bla bla', 'Testing', 0)
        self.env.db_transaction(
            "INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
            ('TestPage', ) + data)
        attachment = Attachment(self.env, 'wiki', 'TestPage')
        attachment.insert('foo.txt', StringIO(), 0, 1)

        page = WikiPage(self.env, 'TestPage')
        page.rename('PageRenamed')
        self.assertEqual('PageRenamed', page.name)
        self.assertEqual('PageRenamed', page.resource.id)

        self.assertEqual([data],
                         self.env.db_query(
                             """
            SELECT version, time, author, ipnr, text, comment, readonly
            FROM wiki WHERE name=%s
            """, ('PageRenamed', )))

        attachments = Attachment.select(self.env, 'wiki', 'PageRenamed')
        self.assertEqual('foo.txt', attachments.next().filename)
        self.assertRaises(StopIteration, attachments.next)
        Attachment.delete_all(self.env, 'wiki', 'PageRenamed')

        old_page = WikiPage(self.env, 'TestPage')
        self.assertFalse(old_page.exists)

        self.assertEqual([],
                         self.env.db_query(
                             """
            SELECT version, time, author, ipnr, text, comment, readonly
            FROM wiki WHERE name=%s
            """, ('TestPage', )))

        listener = TestWikiChangeListener(self.env)
        self.assertEqual((page, 'TestPage'), listener.renamed[0])
Exemplo n.º 34
0
 def test_can_index_version_deleted_event(self):
     #arrange
     self.insert_wiki(self.DUMMY_PAGE_NAME, "version1")
     page = WikiPage(self.env, self.DUMMY_PAGE_NAME)
     page.text = "version 2"
     page.save("anAuthor", "some comment", "::1")
     page.delete(version=2)
     #act
     results = self.search_api.query("*:*")
     #assert
     self.print_result(results)
     self.assertEqual(1, results.hits)
     self.assertEqual("version1", results.docs[0]["content"])
Exemplo n.º 35
0
    def __parse_wiki_and_create_ticket(self, page, version):
        page = WikiPage(self.env, page.name, version)

        lines = page.text.splitlines()
        new_lines = []

        for line in page.text.splitlines():
            matched = self._new_ticket_re.search(line)
            if matched:
                ticket_id = self.__create_new_ticket(page, matched.group(1), page.author)
                if ticket_id:
                    self.env.log.debug("create ticket from wiki: %s, ticket: %s" % (page.name, ticket_id))
                    new_line = line.replace(self._new_ticket_tag, '#%s ' % ticket_id, 1)
                else:
                    self.env.log.error("failed to create ticket from wiki: %s" % page.name)
                    new_line = line

            else:
                new_line = line

            new_lines.append(new_line)

        page.text = "\n".join(new_lines)
        self.__update_wiki(page)
Exemplo n.º 36
0
    def test_create_page(self):
        page = WikiPage(self.env)
        page.name = 'TestPage'
        page.text = 'Bla bla'
        t = datetime(2001, 1, 1, 1, 1, 1, 0, utc)
        page.save('joe', 'Testing', '::1', t)

        self.assertTrue(page.exists)
        self.assertEqual(1, page.version)
        self.assertEqual(1, page.resource.version)
        self.assertEqual(0, page.readonly)
        self.assertEqual('joe', page.author)
        self.assertEqual('Testing', page.comment)
        self.assertEqual(t, page.time)

        self.assertEqual(
            [(1, to_utimestamp(t), 'joe', '::1', 'Bla bla', 'Testing', 0)],
            self.env.db_query("""
                SELECT version, time, author, ipnr, text, comment, readonly
                FROM wiki WHERE name=%s
                """, ('TestPage',)))

        listener = TestWikiChangeListener(self.env)
        self.assertEqual(page, listener.added[0])
Exemplo n.º 37
0
    def test_existing_page(self):
        t = datetime(2001, 1, 1, 1, 1, 1, 0, utc)
        self.env.db_transaction(
            "INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
            ('TestPage', 1, to_utimestamp(t), 'joe', '::1', 'Bla bla',
             'Testing', 0))

        page = WikiPage(self.env, 'TestPage')
        self.assertEqual(True, page.exists)
        self.assertEqual('TestPage', page.name)
        self.assertEqual(1, page.version)
        self.assertEqual(None, page.resource.version)   # FIXME: Intentional?
        self.assertEqual('Bla bla', page.text)
        self.assertEqual(0, page.readonly)
        self.assertEqual('joe', page.author)
        self.assertEqual('Testing', page.comment)
        self.assertEqual(t, page.time)

        history = list(page.get_history())
        self.assertEqual(1, len(history))
        self.assertEqual((1, t, 'joe', 'Testing', '::1'), history[0])

        page = WikiPage(self.env, 'TestPage', 1)
        self.assertEqual(1, page.resource.version)
Exemplo n.º 38
0
    def test_update_page(self):
        t = datetime(2001, 1, 1, 1, 1, 1, 0, utc)
        t2 = datetime(2002, 1, 1, 1, 1, 1, 0, utc)
        self.env.db_transaction(
            "INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
            ('TestPage', 1, to_utimestamp(t), 'joe', '::1', 'Bla bla',
             'Testing', 0))

        page = WikiPage(self.env, 'TestPage')
        page.text = 'Bla'
        page.save('kate', 'Changing', '192.168.0.101', t2)

        self.assertEqual(2, page.version)
        self.assertIsNone(page.resource.version)
        self.assertEqual(0, page.readonly)
        self.assertEqual('kate', page.author)
        self.assertEqual('Changing', page.comment)
        self.assertEqual(t2, page.time)

        with self.env.db_query as db:
            rows = db(
                """
               SELECT version, time, author, ipnr, text, comment, readonly
               FROM wiki WHERE name=%s ORDER BY version
               """, ('TestPage', ))
            self.assertEqual(2, len(rows))
            self.assertEqual(
                (1, to_utimestamp(t), 'joe', '::1', 'Bla bla', 'Testing', 0),
                rows[0])
            self.assertEqual((2, to_utimestamp(t2), 'kate', '192.168.0.101',
                              'Bla', 'Changing', 0), rows[1])

        listener = TestLegacyWikiChangeListener(self.env)
        self.assertEqual((page, 2, t2, 'Changing', 'kate', '192.168.0.101'),
                         listener.changed[0])
        listener = TestWikiChangeListener(self.env)
        self.assertEqual((page, 2, t2, 'Changing', 'kate'),
                         listener.changed[0])

        page = WikiPage(self.env, 'TestPage')
        history = list(page.get_history())
        self.assertEqual(2, len(history))
        self.assertEqual((2, t2, 'kate', 'Changing', '192.168.0.101'),
                         history[0])
        self.assertEqual((1, t, 'joe', 'Testing', '::1'), history[1])
Exemplo n.º 39
0
    def test_invalid_version(self):
        data = (1, 42, 'joe', '::1', 'Bla bla', 'Testing', 0)
        self.env.db_transaction(
            "INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
            ('TestPage',) + data)

        self.assertRaises(ValueError, WikiPage, self.env,
                          'TestPage', '1abc')

        resource = Resource('wiki', 'TestPage')
        self.assertRaises(ValueError, WikiPage, self.env,
                          resource, '1abc')

        resource = Resource('wiki', 'TestPage', '1abc')
        page = WikiPage(self.env, resource)
        self.assertEqual(1, page.version)
Exemplo n.º 40
0
    def test_create_page(self):
        page = WikiPage(self.env)
        page.name = 'TestPage'
        page.text = 'Bla bla'
        page.save('joe', 'Testing', '::1', 42)

        cursor = self.db.cursor()
        cursor.execute("SELECT version,time,author,ipnr,text,comment,"
                       "readonly FROM wiki WHERE name=%s", ('TestPage',))
        self.assertEqual((1, 42, 'joe', '::1', 'Bla bla', 'Testing', 0),
                         cursor.fetchone())

        listener = TestWikiChangeListener(self.env)
        self.assertEqual(page, listener.added[0])
Exemplo n.º 41
0
    def runTest(self):
        """Test timeline in RSS format."""
        pagename = random_unique_camel()
        self._tester.create_wiki_page(pagename)
        page = WikiPage(self._testenv.get_trac_environment(), pagename)
        self._tester.go_to_timeline()
        code, content = tc.download_link("RSS Feed")
        self.assertEqual(200, code)
        pattern = r"""<\?xml version="1.0"\?>[\n]+
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Functional Tests</title>
    <link>http://127.0.0.1:\d+/timeline</link>
    <description>Trac Timeline</description>
    <language>en-US</language>
    <generator>Trac [^<]+</generator>
    <image>
      <title>Functional Tests</title>
      <url>http://127.0.0.1:\d+/chrome/site/your_project_logo.png</url>
      <link>http://127.0.0.1:\d+/timeline</link>
    </image>
    <item>
      <title>%(pagename)s created</title>

      <dc:creator>admin</dc:creator>
      <pubDate>%(http_date)s</pubDate>
      <link>http://127.0.0.1:\d+/wiki/%(pagename)s\?version=1</link>
      <guid isPermaLink="false">http://127.0.0.1:\d+/wiki/%(pagename)s\?version=1/\d+</guid>
      <description>[^<]+</description>
      <category>wiki</category>
    </item>
""" % {
            'pagename': pagename,
            'http_date': http_date(page.time)
        }
        if not re.match(pattern.encode('utf-8'), content,
                        re.MULTILINE | re.DOTALL):
            url = tc.write_source(content)
            raise AssertionError(
                "Regex didn't match: {!r} not found in {}".format(
                    pattern, url))
Exemplo n.º 42
0
    def test_update_page(self):
        cursor = self.db.cursor()
        t = datetime(2001, 1, 1, 1, 1, 1, 0, utc)
        t2 = datetime(2002, 1, 1, 1, 1, 1, 0, utc)
        cursor.execute("INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
                       ('TestPage', 1, to_utimestamp(t), 'joe', '::1',
                        'Bla bla', 'Testing', 0))

        page = WikiPage(self.env, 'TestPage')
        page.text = 'Bla'
        page.save('kate', 'Changing', '192.168.0.101', t2)

        self.assertEqual(2, page.version)
        self.assertEqual(2, page.resource.version)
        self.assertEqual(0, page.readonly)
        self.assertEqual('kate', page.author)
        self.assertEqual('Changing', page.comment)
        self.assertEqual(t2, page.time)

        cursor.execute(
            "SELECT version,time,author,ipnr,text,comment,"
            "readonly FROM wiki WHERE name=%s", ('TestPage', ))
        self.assertEqual(
            (1, to_utimestamp(t), 'joe', '::1', 'Bla bla', 'Testing', 0),
            cursor.fetchone())
        self.assertEqual((2, to_utimestamp(t2), 'kate', '192.168.0.101', 'Bla',
                          'Changing', 0), cursor.fetchone())

        listener = TestWikiChangeListener(self.env)
        self.assertEqual((page, 2, t2, 'Changing', 'kate', '192.168.0.101'),
                         listener.changed[0])

        page = WikiPage(self.env, 'TestPage')
        history = list(page.get_history())
        self.assertEqual(2, len(history))
        self.assertEqual((2, t2, 'kate', 'Changing', '192.168.0.101'),
                         history[0])
        self.assertEqual((1, t, 'joe', 'Testing', '::1'), history[1])
Exemplo n.º 43
0
    def runTest(self):
        """Test timeline in RSS format."""
        pagename = random_unique_camel()
        self._tester.create_wiki_page(pagename)
        page = WikiPage(self._testenv.get_trac_environment(), pagename)
        self._tester.go_to_timeline()
        tc.follow("RSS Feed")
        tc.find(
            r"""<\?xml version="1.0"\?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Functional Tests</title>
    <link>http://127.0.0.1:\d+/timeline</link>
    <description>Trac Timeline</description>
    <language>en-US</language>
    <generator>Trac [^<]+</generator>
    <image>
      <title>Functional Tests</title>
      <url>http://127.0.0.1:\d+/chrome/site/your_project_logo.png</url>
      <link>http://127.0.0.1:\d+/timeline</link>
    </image>
    <item>
      <title>%(pagename)s created</title>
\s+
        <dc:creator>admin</dc:creator>

      <pubDate>%(http_date)s</pubDate>
      <link>http://127.0.0.1:\d+/wiki/%(pagename)s\?version=1</link>
      <guid isPermaLink="false">http://127.0.0.1:\d+/wiki/%(pagename)s\?version=1/\d+</guid>
      <description>[^<]+</description>
      <category>wiki</category>
    </item><item>
""" % {
                'pagename': pagename,
                'http_date': http_date(page.time)
            }, 'ms')
Exemplo n.º 44
0
    def test_update_page(self):
        t = datetime(2001, 1, 1, 1, 1, 1, 0, utc)
        t2 = datetime(2002, 1, 1, 1, 1, 1, 0, utc)
        self.env.db_transaction(
            "INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
            ('TestPage', 1, to_utimestamp(t), 'joe', '::1', 'Bla bla',
             'Testing', 0))

        page = WikiPage(self.env, 'TestPage')
        page.text = 'Bla'
        page.save('kate', 'Changing', '192.168.0.101', t2)

        self.assertEqual(2, page.version)
        self.assertEqual(2, page.resource.version)
        self.assertEqual(0, page.readonly)
        self.assertEqual('kate', page.author)
        self.assertEqual('Changing', page.comment)
        self.assertEqual(t2, page.time)

        with self.env.db_query as db:
            rows = db("""
               SELECT version, time, author, ipnr, text, comment, readonly
               FROM wiki WHERE name=%s ORDER BY version
               """, ('TestPage',))
            self.assertEqual(2, len(rows))
            self.assertEqual((1, to_utimestamp(t), 'joe', '::1', 'Bla bla',
                              'Testing', 0), rows[0])
            self.assertEqual((2, to_utimestamp(t2), 'kate', '192.168.0.101',
                              'Bla', 'Changing', 0), rows[1])

        listener = TestLegacyWikiChangeListener(self.env)
        self.assertEqual((page, 2, t2, 'Changing', 'kate', '192.168.0.101'),
                         listener.changed[0])
        listener = TestWikiChangeListener(self.env)
        self.assertEqual((page, 2, t2, 'Changing', 'kate'),
                         listener.changed[0])

        page = WikiPage(self.env, 'TestPage')
        history = list(page.get_history())
        self.assertEqual(2, len(history))
        self.assertEqual((2, t2, 'kate', 'Changing', '192.168.0.101'),
                         history[0])
        self.assertEqual((1, t, 'joe', 'Testing', '::1'), history[1])
Exemplo n.º 45
0
def execute(hdf, template, env):
    out = StringIO()
    errors = []
    authname = hdf.getValue("trac.authname", "anonymous")
    if not template:
        raise TracError("No template page supplied")
    if authname == "anonymous":
        errors.append(
            'You need to <a href="%s">register</a> then <a href="%s">login</a> in order to create a new hack.'
            % (hdf.getValue("trac.href.registration",
                            ""), hdf.getValue("trac.href.login", "")))
    db = env.get_db_cnx()
    cursor = db.cursor()

    # Fetch meta-data from tags
    META_TAGS = set()
    from tractags.api import TagEngine
    wikitags = TagEngine(env).tagspace.wiki
    for tag in wikitags.get_tagged_names(['metatag']):
        META_TAGS.update(wikitags.get_tagged_names([tag]))
    TYPES = wikitags.get_tagged_names(['type'])
    RELEASES = wikitags.get_tagged_names(['release'])

    page_name = hdf.getValue('args.name', '')
    if not page_name.lower().endswith(hdf.getValue('args.type', '')):
        page_name += hdf.getValue('args.type', '').title()
    page_title = hdf.getValue('args.title', '')
    page_description = hdf.getValue('args.description', '')
    page_example = hdf.getValue('args.example', '')
    page_type = hdf.getValue('args.type', 'plugin')
    page_tags = get_branch_values(hdf, 'args.tags')
    page_releases = get_branch_values(hdf, 'args.releases')
    page_preview = hdf.getValue('args.previewhack', '')
    page_create = hdf.getValue('args.createhack', '')

    def write_tags(out, tags, checked=(), name="tags", type="checkbox"):
        count = 0
        for tag in sorted(tags):
            if tag.startswith('tags/'):
                continue
            (linktext, title, desc) = getInfo(db, tag)
            link = env.href.wiki(tag)
            check = ""
            if tag in checked:
                check = " checked"
            out.write(
                '<input type="%s" name="%s" value="%s"%s/> <a href="%s" title="%s">%s</a>&nbsp;&nbsp;\n'
                % (type, name, tag, check, link, title, tag))
            count += 1
            if count % 8 == 0:
                out.write("<br/>\n")
        return count

    # Validation
    if page_preview or page_create:
        try:
            fetch_page(cursor, page_name)
        except:
            pass
        else:
            errors.append("Page name %s already exists" % page_name)
        if not re.match('^([A-Z][a-z]+){2,}$', page_name):
            errors.append(
                'Invalid WikiName, only alpha characters are accepted and must be CamelCase'
            )
        if not page_name: errors.append("No WikiName provided")
        if not page_title: errors.append("No page title provided")
        if not page_type: errors.append('No page type selected')
        if not page_description: errors.append("No description provided")
        if not page_example: errors.append("No example provided")
        if not page_releases: errors.append("No releases selected")

    if page_create and not errors:
        import subprocess
        repos_dir = env.config.get('trac', 'repository_dir')
        cursor.execute("SELECT name FROM component WHERE name=%s",
                       (page_name, ))
        row = cursor.fetchone()
        if row:
            errors.append("Component '%s' already exists" % page_name)
        if subprocess.call(
            ["svn", "ls",
             "%s/%s" % (SVN_LOCAL_PATH, page_name.lower())]) == 0:
            errors.append("Repository path '%s' already exists" %
                          page_name.lower())
        if not os.access(SVN_PERMISSIONS, os.W_OK):
            errors.append("Can't write to Subversion permissions file")

        lockfile = open("/var/tmp/newhack.lock", "w")
        try:
            rv = fcntl.flock(lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
            if rv:
                errors.append(
                    'Failed to acquire lock, received error code %i' % rv)
        except IOError:
            errors.append(
                'A hack is currently being created by another user. Try again later.'
            )

        if not errors:
            try:
                # Insert component
                cursor.execute(
                    'INSERT INTO component (name, owner) VALUES (%s, %s)',
                    (page_name, authname))
                # Create page
                page = WikiPage(env, page_name, db=db)
                page.text = expand_vars(fetch_page(cursor, template),
                                        generate_vars(hdf))
                out.write('Created wiki page.<br>\n')
                # Creating SVN paths
                paths = ['%s/%s' % (SVN_LOCAL_PATH, page_name.lower())]
                for release in page_releases:
                    paths.append("%s/%s/%s" %
                                 (SVN_LOCAL_PATH, page_name.lower(), release))
                output = os.popen(
                    '/usr/bin/op create-hack %s "New hack %s, created by %s" %s 2>&1'
                    % (authname, page_name, authname,
                       ' '.join(paths))).readlines()
                if output:
                    raise Exception("Failed to create Subversion paths:\n%s" %
                                    ''.join(output))
                out.write("Created SVN layout.<br>\n")
                # Add SVN permissions
                perms = open(SVN_PERMISSIONS, "a")
                perms.write("\n[/%s]\n%s = rw\n" %
                            (page_name.lower(), authname))
                out.write('Added SVN write permission.<br>\n')
                out.write('\nFinished.<p><h1>Hack Details</h1>\n')
                for release in page_releases:
                    svnpath = "%s%s/%s" % (SVN_URL, page_name.lower(), release)
                    out.write(
                        'The Subversion repository path for %s is <a href="%s">%s</a>.<br>\n'
                        % (release, svnpath, svnpath))
                out.write(
                    'The page for your hack is <a href="%s">%s</a>.<br>\n' %
                    (env.href.wiki(page_name), page_name))
                page.save(authname,
                          'New hack %s, created by %s' % (page_name, authname),
                          None)
                db.commit()
                # Add tags
                env.log.debug(vars)
                tags = [page_type, authname] + page_tags + page_releases
                env.log.debug(tags)
                wikitags.replace_tags(None, page_name, tags)
                # Finish up
                rv = fcntl.flock(lockfile, fcntl.LOCK_UN)
                return out.getvalue()
            except Exception, e:
                # TODO Roll back changes to SVN_PERMISSIONS file
                db.rollback()
                rv = fcntl.flock(lockfile, fcntl.LOCK_UN)
                env.log.error(e, exc_info=True)
                raise TracError(str(e))
Exemplo n.º 46
0
 def get_entries_for_index(self):
     page_names = WikiSystem(self.env).get_pages()
     for page_name in page_names:
         page = WikiPage(self.env, page_name)
         yield self.build_doc(page)
Exemplo n.º 47
0
 def create_wiki(self, name, text, **kw):
     page = WikiPage(self.env, name)
     page.text = text
     for k, v in kw.items():
         page[k] = v
     return page
Exemplo n.º 48
0
    def test_invalid_page_name(self):
        invalid_names = ('../Page', 'Page/..', 'Page/////SubPage',
                         'Page/./SubPage', '/PagePrefix', 'PageSuffix/')

        for name in invalid_names:
            page = WikiPage(self.env)
            page.name = name
            page.text = 'Bla bla'
            t = datetime(2001, 1, 1, 1, 1, 1, 0, utc)
            self.assertRaises(TracError, page.save, 'joe', 'Testing', '::1', t)

        page = WikiPage(self.env)
        page.name = 'TestPage'
        page.text = 'Bla bla'
        t = datetime(2001, 1, 1, 1, 1, 1, 0, utc)
        page.save('joe', 'Testing', '::1', t)
        for name in invalid_names:
            page = WikiPage(self.env, 'TestPage')
            self.assertRaises(TracError, page.rename, name)
Exemplo n.º 49
0
def build_table_plugin_styles_page(env):
    table_plugin_style_page = WikiPage(env, 'TablePluginStyles')
    table_plugin_style_page.text = \
"""
== Location for !TablePlugin Style Definitions ==

Define the table styles and CSS styles below in a codeblock.

{{{
@table default:

table.default {
    font-family: verdana,arial,sans-serif;
    font-size:11px;
    color:#333333;
    border-width: 1px;
    border-color: #666666;
    border-collapse: collapse;
    }

table.default thead th {
    border-width: 1px;
    padding: 2px;
    border-style: solid;
    border-color: #666666;
    background-color: #dedede;
    }

table.default tbody td {
    border-width: 1px;
    padding: 2px;
    border-style: solid;
    border-color: #666666;
    background-color: #ffffff;
    }

@css header:
   font-weight: bold;
   text-align: center;
}}}

----

An example of a table styled using the above would look like the following:

{{{
#!table

@table mytable (@default):

@column number
@column item
@column width
@column height

@row (@header)
@number: Number
@item: Item
@width: Width
@height: Height

@number: 1
@item: Item 1
@width: 10
@height: 10

@number: 2
@item: Item 2
@width: 20
@height: 20

@number: 3
@item: Item 3
@width: 30
@height: 30

@number: 4
@item: Item 4
@width: 40
@height: 40

}}}

"""
    try:
        table_plugin_style_page.save('TablePlugin',
                                     'Creating default styles for !TablePlugin',
                                     table_plugin_style_page.resource.id,
                                     )
    except:
        # For some reason, we get an error about
        # saving the page, not sure why?
        pass