Exemplo n.º 1
0
Arquivo: session.py Projeto: t2y/trac
    def test_session_set(self):
        """Verify that setting a variable in a session to the default value
        removes it from the session.
        """
        with self.env.db_transaction as db:
            db("INSERT INTO session VALUES ('john', 1, 0)")
            db("INSERT INTO session_attribute VALUES ('john', 1, 'foo', 'bar')"
               )

        session = DetachedSession(self.env, 'john')
        self.assertEqual('bar', session['foo'])

        # Setting the variable to the default value removes the variable
        with self.env.db_transaction as db:
            session.set('foo', 'default', 'default')
            session.save()
        self.assertEqual(
            0,
            self.env.db_query("""
            SELECT COUNT(*) FROM session_attribute
            WHERE sid='john' AND name='foo'
            """)[0][0])

        # Setting the variable to a value different from the default sets it
        with self.env.db_transaction as db:
            session.set('foo', 'something', 'default')
            session.save()
        self.assertEqual(
            'something',
            self.env.db_query("""
            SELECT value FROM session_attribute
            WHERE sid='john' AND name='foo'
            """)[0][0])
Exemplo n.º 2
0
 def setUp(self):
     self.env = EnvironmentStub(default_data=True, enable=[
         default_workflow.ConfigurableTicketWorkflow,
         DefaultPermissionPolicy, DefaultPermissionStore,
         BatchModifyModule, api.TicketSystem, web_ui.TicketModule
     ])
     self.env.config.set('trac', 'permission_policies',
                         'DefaultPermissionPolicy')
     self.env.config.set('ticket-custom', 'text1', 'text')
     self.env.config.set('ticket-custom', 'text1.max_size', 5)
     self.env.config.set('ticket-custom', 'time1', 'time')
     self.env.config.set('ticket-custom', 'time1.format', 'date')
     self.env.config.set('ticket-workflow',
                         'acknowledge', '* -> acknowledged')
     ps = PermissionSystem(self.env)
     ps.grant_permission('has_ta_&_bm', 'TICKET_ADMIN')
     ps.grant_permission('has_bm', 'TICKET_BATCH_MODIFY')
     ps.grant_permission('has_ta_&_bm', 'TICKET_BATCH_MODIFY')
     session = DetachedSession(self.env, 'has_ta_&_bm')
     session.set('query_href', '')
     session.save()
     session = DetachedSession(self.env, 'has_bm')
     session.set('query_href', '')
     session.save()
     self._insert_ticket('Ticket 1', reporter='user1',
                         component='component1', description='the desc',
                         keywords='foo one', status='new')
     self._insert_ticket('Ticket 2', reporter='user1',
                         component='component2', description='the desc',
                         keywords='baz two', status='new')
Exemplo n.º 3
0
    def test_session_set(self):
        """Verify that setting a variable in a session to the default value
        removes it from the session.
        """
        with self.env.db_transaction as db:
            db("INSERT INTO session VALUES ('john', 1, 0)")
            db("INSERT INTO session_attribute VALUES ('john', 1, 'foo', 'bar')")

        session = DetachedSession(self.env, 'john')
        self.assertEqual('bar', session['foo'])
            
        # Setting the variable to the default value removes the variable
        with self.env.db_transaction as db:
            session.set('foo', 'default', 'default')
            session.save()
        self.assertEqual(0, self.env.db_query("""
            SELECT COUNT(*) FROM session_attribute
            WHERE sid='john' AND name='foo'
            """)[0][0])
        
        # Setting the variable to a value different from the default sets it
        with self.env.db_transaction as db:
            session.set('foo', 'something', 'default')
            session.save()
        self.assertEqual('something', self.env.db_query("""
            SELECT value FROM session_attribute
            WHERE sid='john' AND name='foo'
            """)[0][0])
Exemplo n.º 4
0
 def setUp(self):
     self.env = EnvironmentStub(default_data=True, enable=[
         default_workflow.ConfigurableTicketWorkflow,
         DefaultPermissionPolicy, DefaultPermissionStore,
         BatchModifyModule, api.TicketSystem, web_ui.TicketModule
     ])
     self.env.config.set('trac', 'permission_policies',
                         'DefaultPermissionPolicy')
     ps = PermissionSystem(self.env)
     ps.grant_permission('has_ta_&_bm', 'TICKET_ADMIN')
     ps.grant_permission('has_bm', 'TICKET_BATCH_MODIFY')
     ps.grant_permission('has_ta_&_bm', 'TICKET_BATCH_MODIFY')
     session = DetachedSession(self.env, 'has_ta_&_bm')
     session.set('query_href', '')
     session.save()
     session = DetachedSession(self.env, 'has_bm')
     session.set('query_href', '')
     session.save()