view test/session_common.py @ 5326:db8659c4e8eb

xmlrpc: logging; content property The 'content' property is special: It should not be set to None when receiving an empty string (creation of an empty file) but to an empty string instead. Otherwise we'll get a traceback from the backend.
author Ralf Schlatterbeck <rsc@runtux.com>
date Tue, 29 May 2018 13:36:22 +0200
parents 62de601bdf6f
children d26921b851c3
line wrap: on
line source

import os, shutil, unittest

from db_test_base import config


class SessionTest(object):
    def setUp(self):
        # remove previous test, ignore errors
        if os.path.exists(config.DATABASE):
            shutil.rmtree(config.DATABASE)
        os.makedirs(config.DATABASE + '/files')
        self.db = self.module.Database(config, 'admin')
        self.sessions = self.db.getSessionManager()
        self.otks = self.db.getOTKManager()

    def tearDown(self):
        if hasattr(self, 'db'):
            self.db.close()
        if os.path.exists(config.DATABASE):
            shutil.rmtree(config.DATABASE)

    def testList(self):
        self.sessions.list()
        self.sessions.set('random_key', text='hello, world!')
        self.sessions.list()

    def testGetAll(self):
        self.sessions.set('random_key', text='hello, world!')
        self.assertEqual(self.sessions.getall('random_key'),
            {'text': 'hello, world!'})

    def testDestroy(self):
        self.sessions.set('random_key', text='hello, world!')
        self.assertEquals(self.sessions.getall('random_key'),
            {'text': 'hello, world!'})
        self.sessions.destroy('random_key')
        self.assertRaises(KeyError, self.sessions.getall, 'random_key')

    def testSetSession(self):
        self.sessions.set('random_key', text='hello, world!')
        self.assertEqual(self.sessions.get('random_key', 'text'),
            'hello, world!')

    def testUpdateSession(self):
        self.sessions.set('random_key', text='hello, world!')
        self.assertEqual(self.sessions.get('random_key', 'text'),
            'hello, world!')
        self.sessions.set('random_key', text='nope')
        self.assertEqual(self.sessions.get('random_key', 'text'), 'nope')


Roundup Issue Tracker: http://roundup-tracker.org/