Beispiel #1
0
    def setUp(self):
        self.env = EnvironmentStub(default_data=True,
                                   enable=['trac.*', 'tractags.*'])
        self.env.path = tempfile.mkdtemp()
        self.perms = PermissionSystem(self.env)

        self.tag_s = TagSystem(self.env)
        self.tag_wp = WikiTagProvider(self.env)

        self.db = self.env.get_db_cnx()
        setup = TagSetup(self.env)
        # Current tractags schema is partially setup with enabled component.
        #   Revert these changes for getting a clean setup.
        self._revert_tractags_schema_init()
        setup.upgrade_environment(self.db)

        cursor = self.db.cursor()
        # Populate table with initial test data.
        cursor.execute("""
            INSERT INTO tags
                   (tagspace, name, tag)
            VALUES ('wiki', 'WikiStart', 'tag1')
        """)

        self.req = Mock()
        # Mock an anonymous request.
        self.req.perm = PermissionCache(self.env)
        self.realm = 'wiki'
        self.tags = ['tag1']
Beispiel #2
0
    def setUp(self):
        self.env = EnvironmentStub(default_data=True,
                                   enable=['trac.*', 'tractags.*'])
        self.env.path = tempfile.mkdtemp()
        self.perms = PermissionSystem(self.env)

        self.db = self.env.get_db_cnx()
        setup = TagSetup(self.env)
        # Current tractags schema is setup with enabled component anyway.
        #   Revert these changes for getting default permissions inserted.
        self._revert_tractags_schema_init()
        setup.upgrade_environment(self.db)

        self.provider = TicketTagProvider(self.env)
        self.realm = 'ticket'
        self.tag_sys = TagSystem(self.env)
        self.tags = ['tag1', 'tag2']

        cursor = self.db.cursor()
        # Populate tables with initial test data.
        self._create_ticket(self.tags)

        # Mock an anonymous request.
        self.anon_req = Mock()
        self.anon_req.perm = PermissionCache(self.env)

        self.req = Mock(authname='editor')
        self.req.authname = 'editor'
        self.req.perm = PermissionCache(self.env, username='******')
Beispiel #3
0
    def setUp(self):
        self.env = EnvironmentStub(default_data=True,
                                   enable=['trac.*', 'tractags.*'])
        self.env.path = tempfile.mkdtemp()
        self.perms = PermissionSystem(self.env)

        setup = TagSetup(self.env)
        # Current tractags schema is setup with enabled component anyway.
        #   Revert these changes for getting default permissions inserted.
        self._revert_tractags_schema_init()
        setup.upgrade_environment()

        self.provider = TicketTagProvider(self.env)
        self.realm = 'ticket'
        self.tag_sys = TagSystem(self.env)
        self.tags = ['tag1', 'tag2']

        # Populate tables with initial test data.
        self._create_ticket(self.tags)

        # Mock an anonymous request.
        self.anon_req = Mock()
        self.anon_req.perm = PermissionCache(self.env)

        self.req = Mock(authname='editor')
        self.req.authname = 'editor'
        self.req.perm = PermissionCache(self.env, username='******')
Beispiel #4
0
    def setUp(self):
        self.env = EnvironmentStub(default_data=True,
                                   enable=['trac.*', 'tractags.*'])
        self.env.path = tempfile.mkdtemp()
        self.perms = PermissionSystem(self.env)

        self.db = self.env.get_db_cnx()
        setup = TagSetup(self.env)
        # Current tractags schema is setup with enabled component anyway.
        #   Revert these changes for getting default permissions inserted.
        self._revert_tractags_schema_init()
        setup.upgrade_environment(self.db)

        self.provider = TicketTagProvider(self.env)
        self.realm = 'ticket'
        self.tag_sys = TagSystem(self.env)
        self.tags = ['tag1']

        cursor = self.db.cursor()
        # Populate table with initial test data, not synced with tickets yet.
        cursor.execute("""
            INSERT INTO tags
                   (tagspace, name, tag)
            VALUES ('ticket', '1', 'deleted')""")
        self.realm = 'ticket'
        self._create_ticket(self.tags)

        self.req = Mock()
        # Mock an anonymous request.
        self.req.perm = PermissionCache(self.env)
Beispiel #5
0
    def setUp(self):
        self.env = EnvironmentStub(
                enable=['trac.*', 'tractags.*'])
        self.env.path = tempfile.mkdtemp()
        self.db = self.env.get_db_cnx()
        setup = TagSetup(self.env)
        # Current tractags schema is setup with enabled component anyway.
        #   Revert these changes for getting a clean setup.
        self._revert_tractags_schema_init()
        setup.upgrade_environment(self.db)

        self.tag_s = TagSystem(self.env)
        self.tag_rh = TagRequestHandler(self.env)

        perms = PermissionSystem(self.env)
        # Revoke default permissions, because more diversity is required here.
        perms.revoke_permission('anonymous', 'TAGS_VIEW')
        perms.revoke_permission('authenticated', 'TAGS_MODIFY')
        perms.grant_permission('reader', 'TAGS_VIEW')
        perms.grant_permission('writer', 'TAGS_MODIFY')
        perms.grant_permission('admin', 'TAGS_ADMIN')
        self.anonymous = PermissionCache(self.env)
        self.reader = PermissionCache(self.env, 'reader')
        self.writer = PermissionCache(self.env, 'writer')
        self.admin = PermissionCache(self.env, 'admin')

        self.href = Href('/trac')
        self.abs_href = Href('http://example.org/trac')
Beispiel #6
0
    def setUp(self):
        self.env = EnvironmentStub(default_data=True,
                                   enable=['trac.*', 'tractags.*'])
        self.env.path = tempfile.mkdtemp()
        self.perms = PermissionSystem(self.env)

        self.db = self.env.get_db_cnx()
        setup = TagSetup(self.env)
        # Current tractags schema is setup with enabled component anyway.
        #   Revert these changes for getting default permissions inserted.
        self._revert_tractags_schema_init()
        setup.upgrade_environment(self.db)

        self.provider = TicketTagProvider(self.env)
        self.realm = 'ticket'
        self.tag_sys = TagSystem(self.env)
        self.tags = ['tag1']

        cursor = self.db.cursor()
        # Populate table with initial test data, not synced with tickets yet.
        cursor.execute("""
            INSERT INTO tags
                   (tagspace, name, tag)
            VALUES ('ticket', '1', 'deleted')""")
        self.realm = 'ticket'
        self._create_ticket(self.tags)

        self.req = Mock()
        # Mock an anonymous request.
        self.req.perm = PermissionCache(self.env)
Beispiel #7
0
    def setUp(self):
        self.env = EnvironmentStub(default_data=True,
                                   enable=['trac.*', 'tractags.*'])
        self.env.path = tempfile.mkdtemp()
        self.db = self.env.get_db_cnx()
        setup = TagSetup(self.env)
        # Current tractags schema is partially setup with enabled component.
        #   Revert these changes for getting a clean setup.
        self._revert_tractags_schema_init()
        setup.upgrade_environment(self.db)

        self.perms = PermissionSystem(self.env)
        self.tag_s = TagSystem(self.env)
        self.tag_wp = WikiTagProvider(self.env)

        cursor = self.db.cursor()
        # Populate table with initial test data.
        cursor.execute("""
            INSERT INTO tags
                   (tagspace, name, tag)
            VALUES ('wiki', 'WikiStart', 'tag1')
        """)

        self.req = Mock(authname='editor')
        # Mock an anonymous request.
        self.req.perm = PermissionCache(self.env)
        self.realm = 'wiki'
        self.tags = ['tag1']
Beispiel #8
0
    def setUp(self):
        self.env = EnvironmentStub(
                enable=['trac.*', 'tractags.*'])
        self.env.path = tempfile.mkdtemp()

        self.tag_s = TagSystem(self.env)
        self.tag_rh = TagRequestHandler(self.env)

        self.db = self.env.get_db_cnx()
        setup = TagSetup(self.env)
        # Current tractags schema is setup with enabled component anyway.
        #   Revert these changes for getting a clean setup.
        self._revert_tractags_schema_init()
        setup.upgrade_environment(self.db)

        perms = PermissionSystem(self.env)
        # Revoke default permissions, because more diversity is required here.
        perms.revoke_permission('anonymous', 'TAGS_VIEW')
        perms.revoke_permission('authenticated', 'TAGS_MODIFY')
        perms.grant_permission('reader', 'TAGS_VIEW')
        perms.grant_permission('writer', 'TAGS_MODIFY')
        perms.grant_permission('admin', 'TAGS_ADMIN')
        self.anonymous = PermissionCache(self.env)
        self.reader = PermissionCache(self.env, 'reader')
        self.writer = PermissionCache(self.env, 'writer')
        self.admin = PermissionCache(self.env, 'admin')

        self.href = Href('/trac')
        self.abs_href = Href('http://example.org/trac')
Beispiel #9
0
    def setUp(self):
        self.env = EnvironmentStub(enable=['trac.*', 'tractags.*'])
        self.env.path = tempfile.mkdtemp()

        self.db = self.env.get_db_cnx()
        setup = TagSetup(self.env)
        setup.upgrade_environment(self.db)
        self.tag_twm = TagWikiMacros(self.env)
Beispiel #10
0
    def setUp(self):
        self.env = EnvironmentStub(
                enable=['trac.*', 'tractags.*'])
        self.env.path = tempfile.mkdtemp()

        self.db = self.env.get_db_cnx()
        setup = TagSetup(self.env)
        setup.upgrade_environment(self.db)
        self.tag_twm = TagWikiMacros(self.env)
Beispiel #11
0
    def setUp(self):
        self.env = EnvironmentStub(default_data=True,
                                   enable=['trac.*', 'tractags.*'])
        self.env.path = tempfile.mkdtemp()

        setup = TagSetup(self.env)
        # Current tractags schema is setup with enabled component anyway.
        #   Revert these changes for getting default permissions inserted.
        self._revert_tractags_schema_init()
        setup.upgrade_environment()
Beispiel #12
0
    def setUp(self):
        self.env = EnvironmentStub(default_data=True,
                                   enable=['trac.*', 'tractags.*'])
        self.env.path = tempfile.mkdtemp()

        setup = TagSetup(self.env)
        # Current tractags schema is setup with enabled component anyway.
        #   Revert these changes for getting default permissions inserted.
        self._revert_tractags_schema_init()
        setup.upgrade_environment()
Beispiel #13
0
    def setUp(self):
        self.env = EnvironmentStub(default_data=True,
                                   enable=['trac.*', 'tractags.*'])
        self.env.path = tempfile.mkdtemp()
        self.perms = PermissionSystem(self.env)

        self.actions = ['TAGS_ADMIN', 'TAGS_MODIFY', 'TAGS_VIEW']
        setup = TagSetup(self.env)
        # Current tractags schema is setup with enabled component anyway.
        #   Revert these changes for getting default permissions inserted.
        self._revert_tractags_schema_init()
        setup.upgrade_environment()
        self.tag_s = tractags.api.TagSystem(self.env)
Beispiel #14
0
    def setUp(self):
        self.env = EnvironmentStub(default_data=True,
                                   enable=['trac.*', 'tractags.*'])
        self.env.path = tempfile.mkdtemp()
        self.perms = PermissionSystem(self.env)
        self.req = Mock(authname='editor')

        self.actions = ['TAGS_ADMIN', 'TAGS_MODIFY', 'TAGS_VIEW']
        setup = TagSetup(self.env)
        # Current tractags schema is setup with enabled component anyway.
        #   Revert these changes for getting default permissions inserted.
        self._revert_tractags_schema_init()
        setup.upgrade_environment()
        self.tag_s = tractags.api.TagSystem(self.env)
Beispiel #15
0
def wiki_setup(tc):
    tc.env = EnvironmentStub(default_data=True,
                             enable=['trac.*', 'tractags.*'])
    tc.env.path = tempfile.mkdtemp()
    tc.db_mgr = DatabaseManager(tc.env)
    tc.db = tc.env.get_db_cnx()

    TagSetup(tc.env).upgrade_environment(tc.db)

    now = datetime.now(utc)
    wiki = WikiPage(tc.env)
    wiki.name = 'TestPage'
    wiki.text = '--'
    wiki.save('joe', 'TagsPluginTestPage', '::1', now)

    req = Mock(href=Href('/'),
               abs_href=Href('http://www.example.com/'),
               authname='anonymous',
               perm=MockPerm(),
               tz=utc,
               args={},
               locale=Locale.parse('en_US') if Locale else None)
    tc.env.href = req.href
    tc.env.abs_href = req.abs_href
    tc.context = Context.from_request(req)
    # Enable big diff output.
    tc.maxDiff = None
Beispiel #16
0
    def setUp(self):
        self.env = EnvironmentStub(default_data=True,
                                   enable=['trac.*', 'tractags.*'])
        self.env.path = tempfile.mkdtemp()
        setup = TagSetup(self.env)
        # Current tractags schema is partially setup with enabled component.
        #   Revert these changes for getting a clean setup.
        self._revert_tractags_schema_init()
        setup.upgrade_environment()

        self.perms = PermissionSystem(self.env)
        self.tag_s = TagSystem(self.env)

        # Populate table with initial test data.
        self.env.db_transaction("""
            INSERT INTO tags (tagspace, name, tag)
            VALUES ('wiki', 'WikiStart', 'tag1')
            """)

        self.req = MockRequest(self.env, authname='editor')
Beispiel #17
0
    def setUp(self):
        self.env = EnvironmentStub(default_data=True,
                                   enable=['trac.*', 'tractags.*'])
        self.env.path = tempfile.mkdtemp()
        self.perms = PermissionSystem(self.env)
        self.req = Mock(authname='editor')

        self.check_perm = WikiTagProvider(self.env).check_permission
        setup = TagSetup(self.env)
        # Current tractags schema is setup with enabled component anyway.
        #   Revert these changes for getting default permissions inserted.
        self._revert_tractags_schema_init()
        setup.upgrade_environment()

        # Populate table with initial test data.
        self.env.db_transaction("""
            INSERT INTO tags (tagspace, name, tag)
            VALUES ('wiki', 'WikiStart', 'tag1')
            """)
        self.realm = 'wiki'
Beispiel #18
0
def wiki_setup(tc):
    tc.env.enable_component('tractags')
    tc.env.path = tempfile.mkdtemp()
    _revert_tractags_schema_init(tc.env)
    TagSetup(tc.env).upgrade_environment()

    tags = ('2ndtag', 'a.really?_\wild-thing', 'heavily-quoted',
            'onetag', 'tagged', "single'quote")
    _insert_tags(tc.env, 'wiki', 'TestPage', tags)

    # Enable big diff output.
    tc.maxDiff = None
Beispiel #19
0
    def setUp(self):
        self.env = EnvironmentStub(
                enable=['trac.*', 'tractags.*'])
        self.env.path = tempfile.mkdtemp()
        self.req = Mock(path_info='/wiki/ListTaggedPage',
                        args={}, authname='user', perm=MockPerm(),
                        href=Href('/'),
                        abs_href=Href('http://example.org/trac/'),
                        chrome={}, session={}, locale='', tz='')

        self.db = self.env.get_db_cnx()
        cursor = self.db.cursor()
        cursor.execute("DROP TABLE IF EXISTS tags")
        cursor.execute("DROP TABLE IF EXISTS tags_change")
        cursor.execute("DELETE FROM system WHERE name='tags_version'")
        cursor.execute("DELETE FROM permission WHERE action %s"
                       % self.db.like(), ('TAGS_%',))

        setup = TagSetup(self.env)
        setup.upgrade_environment(self.db)
        self.tag_twm = TagWikiMacros(self.env)
Beispiel #20
0
def wiki_setup(tc):
    tc.env = EnvironmentStub(default_data=True,
                             enable=['trac.*', 'tractags.*'])
    tc.env.path = tempfile.mkdtemp()
    tc.db_mgr = DatabaseManager(tc.env)
    tc.db = tc.env.get_db_cnx()

    cursor = tc.db.cursor()
    cursor.execute("DROP TABLE IF EXISTS tags")
    cursor.execute("DROP TABLE IF EXISTS tags_change")
    cursor.execute("DELETE FROM system WHERE name='tags_version'")
    cursor.execute("DELETE FROM permission WHERE action %s" % tc.db.like(),
                   ('TAGS_%', ))

    TagSetup(tc.env).upgrade_environment(tc.db)

    now = datetime.now(utc)
    wiki = WikiPage(tc.env)
    wiki.name = 'TestPage'
    wiki.text = '--'
    wiki.save('joe', 'TagsPluginTestPage', '::1', now)

    cursor = tc.db.cursor()
    # Populate table with initial test data.
    cursor.executemany(
        """
        INSERT INTO tags
               (tagspace, name, tag)
        VALUES (%s,%s,%s)
    """, [
            ('wiki', 'TestPage', '2ndtag'),
            ('wiki', 'TestPage', 'a.really?_\wild-thing'),
            ('wiki', 'TestPage', 'heavily-quoted'),
            ('wiki', 'TestPage', 'onetag'),
            ('wiki', 'TestPage', 'tagged'),
            ('wiki', 'TestPage', "single'quote"),
        ])

    req = Mock(href=Href('/'),
               abs_href=Href('http://www.example.com/'),
               authname='anonymous',
               perm=MockPerm(),
               tz=utc,
               args={},
               locale=locale_en)
    tc.env.href = req.href
    tc.env.abs_href = req.abs_href
    tc.context = Context.from_request(req)
    # Enable big diff output.
    tc.maxDiff = None
Beispiel #21
0
    def test_upgrade_schema_v2(self):
        # Just register a current, but unversioned schema.
        schema = [
            Table('tags', key=('tagspace', 'name',
                               'tag'))[Column('tagspace'),
                                       Column('name'),
                                       Column('tag'),
                                       Index(['tagspace', 'name']),
                                       Index(['tagspace', 'tag']), ]
        ]
        setup = TagSetup(self.env)
        # Current tractags schema is setup with enabled component anyway.
        #   Revert these changes for clean install testing.
        self._revert_tractags_schema_init()

        connector = self.db_mgr._get_connector()[0]
        cursor = self.db.cursor()
        for table in schema:
            for stmt in connector.to_sql(table):
                cursor.execute(stmt)
        # Populate table with test data.
        cursor.execute("""
            INSERT INTO tags
                   (tagspace, name, tag)
            VALUES ('wiki', 'WikiStart', 'tag')
        """)

        cursor.execute("SELECT * FROM tags")
        tags = cursor.fetchall()
        self.assertEquals([('wiki', 'WikiStart', 'tag')], tags)
        self.assertEquals(2, setup.get_schema_version(self.db))
        self.assertTrue(setup.environment_needs_upgrade(self.db))

        setup.upgrade_environment(self.db)
        self.assertFalse(setup.environment_needs_upgrade(self.db))
        cursor = self.db.cursor()
        cursor.execute("SELECT * FROM tags")
        tags = cursor.fetchall()
        # Db should be unchanged.
        self.assertEquals([('wiki', 'WikiStart', 'tag')], tags)
        self.assertEquals(
            ['tagspace', 'name', 'tag'],
            [col[0] for col in self._get_cursor_description(cursor)])
        cursor.execute("""
            SELECT value
              FROM system
             WHERE name='tags_version'
        """)
        version = int(cursor.fetchone()[0])
        self.assertEquals(db_default.schema_version, version)
Beispiel #22
0
    def test_upgrade_schema_v2(self):
        # Just register a current, but unversioned schema.
        schema = [
            Table("tags", key=("tagspace", "name", "tag"))[
                Column("tagspace"),
                Column("name"),
                Column("tag"),
                Index(["tagspace", "name"]),
                Index(["tagspace", "tag"]),
            ]
        ]
        setup = TagSetup(self.env)
        # Current tractags schema is setup with enabled component anyway.
        #   Revert these changes for clean install testing.
        self._revert_tractags_schema_init()

        connector = self.db_mgr._get_connector()[0]
        cursor = self.db.cursor()
        for table in schema:
            for stmt in connector.to_sql(table):
                cursor.execute(stmt)
        # Populate table with test data.
        cursor.execute(
            """
            INSERT INTO tags
                   (tagspace, name, tag)
            VALUES ('wiki', 'WikiStart', 'tag')
        """
        )

        cursor.execute("SELECT * FROM tags")
        tags = cursor.fetchall()
        self.assertEquals([("wiki", "WikiStart", "tag")], tags)
        self.assertEquals(2, setup.get_schema_version(self.db))
        self.assertTrue(setup.environment_needs_upgrade(self.db))

        setup.upgrade_environment(self.db)
        self.assertFalse(setup.environment_needs_upgrade(self.db))
        cursor = self.db.cursor()
        cursor.execute("SELECT * FROM tags")
        tags = cursor.fetchall()
        # Db should be unchanged.
        self.assertEquals([("wiki", "WikiStart", "tag")], tags)
        self.assertEquals(["tagspace", "name", "tag"], [col[0] for col in self._get_cursor_description(cursor)])
        cursor.execute(
            """
            SELECT value
              FROM system
             WHERE name='tags_version'
        """
        )
        version = int(cursor.fetchone()[0])
        self.assertEquals(db_default.schema_version, version)
Beispiel #23
0
    def test_new_install(self):
        setup = TagSetup(self.env)
        # Current tractags schema is setup with enabled component anyway.
        #   Revert these changes for clean install testing.
        self._revert_tractags_schema_init()
        self.assertEquals(0, setup.get_schema_version())
        self.assertTrue(setup.environment_needs_upgrade())

        setup.upgrade_environment()
        self.assertFalse(setup.environment_needs_upgrade())
        with self.env.db_query as db:
            cursor = db.cursor()
            cursor.execute("SELECT * FROM tags")
            cols = [col[0] for col in self._get_cursor_description(cursor)]
            self.assertEquals([], cursor.fetchall())
            self.assertEquals(['tagspace', 'name', 'tag'], cols)
        self.assertEquals(db_default.schema_version, self.get_db_version())
Beispiel #24
0
    def test_upgrade_schema_v1(self):
        # Ancient, unversioned schema - wiki only.
        schema = [
            Table('wiki_namespace')[
                Column('name'),
                Column('namespace'),
                Index(['name', 'namespace']),
            ]
        ]
        setup = TagSetup(self.env)
        # Current tractags schema is setup with enabled component anyway.
        #   Revert these changes for clean install testing.
        self._revert_tractags_schema_init()

        connector = self.db_mgr._get_connector()[0]
        cursor = self.db.cursor()
        for table in schema:
            for stmt in connector.to_sql(table):
                cursor.execute(stmt)
        # Populate table with migration test data.
        cursor.execute("""
            INSERT INTO wiki_namespace
                   (name, namespace)
            VALUES ('WikiStart', 'tag')
        """)

        cursor = self.db.cursor()
        cursor.execute("SELECT * FROM wiki_namespace")
        tags = cursor.fetchall()
        self.assertEquals([('WikiStart', 'tag')], tags)
        self.assertEquals(1, setup.get_schema_version(self.db))
        self.assertTrue(setup.environment_needs_upgrade(self.db))

        setup.upgrade_environment(self.db)
        self.assertFalse(setup.environment_needs_upgrade(self.db))
        cursor = self.db.cursor()
        cursor.execute("SELECT * FROM tags")
        tags = cursor.fetchall()
        # Db content should be migrated.
        self.assertEquals([('wiki', 'WikiStart', 'tag')], tags)
        self.assertEquals(['tagspace', 'name', 'tag'],
                [col[0] for col in self._get_cursor_description(cursor)])
        cursor.execute("""
            SELECT value
              FROM system
             WHERE name='tags_version'
        """)
        version = int(cursor.fetchone()[0])
        self.assertEquals(db_default.schema_version, version)
Beispiel #25
0
    def test_upgrade_schema_v3(self):
        # Add table for tag change records to the schema.
        schema = [
            Table('tags', key=('tagspace', 'name',
                               'tag'))[Column('tagspace'),
                                       Column('name'),
                                       Column('tag'),
                                       Index(['tagspace', 'name']),
                                       Index(['tagspace', 'tag']), ]
        ]
        setup = TagSetup(self.env)
        # Current tractags schema is setup with enabled component anyway.
        #   Revert these changes for clean install testing.
        self._revert_tractags_schema_init()

        connector = self.db_mgr._get_connector()[0]
        cursor = self.db.cursor()
        for table in schema:
            for stmt in connector.to_sql(table):
                cursor.execute(stmt)
        # Preset system db table with old version.
        cursor.execute("""
            INSERT INTO system
                   (name, value)
            VALUES ('tags_version', '3')
        """)

        self.assertEquals(3, setup.get_schema_version(self.db))
        self.assertTrue(setup.environment_needs_upgrade(self.db))

        setup.upgrade_environment(self.db)
        self.assertFalse(setup.environment_needs_upgrade(self.db))
        cursor = self.db.cursor()
        cursor.execute("SELECT * FROM tags_change")
        self.assertEquals(
            ['tagspace', 'name', 'time', 'author', 'oldtags', 'newtags'],
            [col[0] for col in self._get_cursor_description(cursor)])
        cursor.execute("""
            SELECT value
              FROM system
             WHERE name='tags_version'
        """)
        version = int(cursor.fetchone()[0])
        self.assertEquals(db_default.schema_version, version)
Beispiel #26
0
    def test_new_install(self):
        setup = TagSetup(self.env)
        # Current tractags schema is setup with enabled component anyway.
        #   Revert these changes for clean install testing.
        self._revert_tractags_schema_init()
        self.assertEquals(0, setup.get_schema_version())
        self.assertTrue(setup.environment_needs_upgrade())

        setup.upgrade_environment()
        self.assertFalse(setup.environment_needs_upgrade())
        with self.env.db_query as db:
            cursor = db.cursor()
            cursor.execute("SELECT * FROM tags")
            cols = [col[0] for col in self._get_cursor_description(cursor)]
            self.assertEquals([], cursor.fetchall())
            self.assertEquals(['tagspace', 'name', 'tag'], cols)
        self.assertEquals(db_default.schema_version, self.get_db_version())
Beispiel #27
0
    def test_upgrade_schema_v3(self):
        # Add table for tag change records to the schema.
        schema = [
            Table('tags', key=('tagspace', 'name', 'tag'))[
                Column('tagspace'),
                Column('name'),
                Column('tag'),
                Index(['tagspace', 'name']),
                Index(['tagspace', 'tag']),
            ]
        ]
        setup = TagSetup(self.env)
        # Current tractags schema is setup with enabled component anyway.
        #   Revert these changes for clean install testing.
        self._revert_tractags_schema_init()

        connector = self.db_mgr._get_connector()[0]
        cursor = self.db.cursor()
        for table in schema:
            for stmt in connector.to_sql(table):
                cursor.execute(stmt)
        # Preset system db table with old version.
        cursor.execute("""
            INSERT INTO system
                   (name, value)
            VALUES ('tags_version', '3')
        """)

        self.assertEquals(3, setup.get_schema_version(self.db))
        self.assertTrue(setup.environment_needs_upgrade(self.db))

        setup.upgrade_environment(self.db)
        self.assertFalse(setup.environment_needs_upgrade(self.db))
        cursor = self.db.cursor()
        cursor.execute("SELECT * FROM tags_change")
        self.assertEquals(['tagspace', 'name', 'time', 'author',
                           'oldtags', 'newtags'],
                [col[0] for col in self._get_cursor_description(cursor)])
        cursor.execute("""
            SELECT value
              FROM system
             WHERE name='tags_version'
        """)
        version = int(cursor.fetchone()[0])
        self.assertEquals(db_default.schema_version, version)
Beispiel #28
0
    def test_upgrade_schema_v1(self):
        # Ancient, unversioned schema - wiki only.
        schema = [
            Table('wiki_namespace')[
                Column('name'),
                Column('namespace'),
                Index(['name', 'namespace']),
            ]
        ]
        setup = TagSetup(self.env)
        # Current tractags schema is setup with enabled component anyway.
        #   Revert these changes for clean install testing.
        self._revert_tractags_schema_init()

        connector = self.db_mgr.get_connector()[0]
        with self.env.db_transaction as db:
            for table in schema:
                for stmt in connector.to_sql(table):
                    db(stmt)
            # Populate table with migration test data.
            db("""INSERT INTO wiki_namespace (name, namespace)
                  VALUES ('WikiStart', 'tag')""")

        tags = self.env.db_query("SELECT * FROM wiki_namespace")
        self.assertEquals([('WikiStart', 'tag')], tags)
        self.assertEquals(1, setup.get_schema_version())
        self.assertTrue(setup.environment_needs_upgrade())

        setup.upgrade_environment()
        self.assertFalse(setup.environment_needs_upgrade())
        with self.env.db_query as db:
            cursor = db.cursor()
            cursor.execute("SELECT * FROM tags")
            tags = cursor.fetchall()
            cols = [col[0] for col in self._get_cursor_description(cursor)]
            # Db content should be migrated.
            self.assertEquals([('wiki', 'WikiStart', 'tag')], tags)
            self.assertEquals(['tagspace', 'name', 'tag'], cols)
            self.assertEquals(db_default.schema_version, self.get_db_version())
Beispiel #29
0
    def test_upgrade_schema_v2(self):
        # Just register a current, but unversioned schema.
        schema = [
            Table('tags', key=('tagspace', 'name', 'tag'))[
                Column('tagspace'),
                Column('name'),
                Column('tag'),
                Index(['tagspace', 'name']),
                Index(['tagspace', 'tag']),
            ]
        ]
        setup = TagSetup(self.env)
        # Current tractags schema is setup with enabled component anyway.
        #   Revert these changes for clean install testing.
        self._revert_tractags_schema_init()

        connector = self.db_mgr._get_connector()[0]
        with self.env.db_transaction as db:
            for table in schema:
                for stmt in connector.to_sql(table):
                    db(stmt)
            # Populate table with test data.
            db("""INSERT INTO tags (tagspace, name, tag)
                  VALUES ('wiki', 'WikiStart', 'tag')""")

        tags = self.env.db_query("SELECT * FROM tags")
        self.assertEquals([('wiki', 'WikiStart', 'tag')], tags)
        self.assertEquals(2, setup.get_schema_version())
        self.assertTrue(setup.environment_needs_upgrade())

        setup.upgrade_environment()
        self.assertFalse(setup.environment_needs_upgrade())
        with self.env.db_query as db:
            cursor = db.cursor()
            cursor.execute("SELECT * FROM tags")
            tags = cursor.fetchall()
            cols = [col[0] for col in self._get_cursor_description(cursor)]
            # Db should be unchanged.
            self.assertEquals([('wiki', 'WikiStart', 'tag')], tags)
            self.assertEquals(['tagspace', 'name', 'tag'], cols)
            self.assertEquals(db_default.schema_version, self.get_db_version())
Beispiel #30
0
    def test_new_install(self):
        setup = TagSetup(self.env)
        # Current tractags schema is setup with enabled component anyway.
        #   Revert these changes for clean install testing.
        self._revert_tractags_schema_init()
        self.assertEquals(0, setup.get_schema_version(self.db))
        self.assertTrue(setup.environment_needs_upgrade(self.db))

        setup.upgrade_environment(self.db)
        self.assertFalse(setup.environment_needs_upgrade(self.db))
        cursor = self.db.cursor()
        cursor.execute("SELECT * FROM tags")
        tags = cursor.fetchall()
        self.assertEquals([], tags)
        self.assertEquals(
            ['tagspace', 'name', 'tag'],
            [col[0] for col in self._get_cursor_description(cursor)])
        cursor.execute("""
            SELECT value
              FROM system
             WHERE name='tags_version'
        """)
        version = int(cursor.fetchone()[0])
        self.assertEquals(db_default.schema_version, version)
Beispiel #31
0
    def test_new_install(self):
        setup = TagSetup(self.env)
        # Current tractags schema is setup with enabled component anyway.
        #   Revert these changes for clean install testing.
        self._revert_tractags_schema_init()
        self.assertEquals(0, setup.get_schema_version(self.db))
        self.assertTrue(setup.environment_needs_upgrade(self.db))

        setup.upgrade_environment(self.db)
        self.assertFalse(setup.environment_needs_upgrade(self.db))
        cursor = self.db.cursor()
        cursor.execute("SELECT * FROM tags")
        tags = cursor.fetchall()
        self.assertEquals([], tags)
        self.assertEquals(['tagspace', 'name', 'tag'],
                [col[0] for col in self._get_cursor_description(cursor)])
        cursor.execute("""
            SELECT value
              FROM system
             WHERE name='tags_version'
        """)
        version = int(cursor.fetchone()[0])
        self.assertEquals(db_default.schema_version, version)
Beispiel #32
0
def listtagged_setup(tc):
    _revert_tractags_schema_init(tc.env)
    TagSetup(tc.env).upgrade_environment()
    _insert_tags(tc.env, 'wiki', 'WikiStart', ('abc', 'xyz'))