示例#1
0
    def get_storage_args(self, request, tmpdir, slow_create_collection):
        tmpdir.mkdir('xandikos')
        backend = XandikosBackend(path=str(tmpdir))
        cup = '/user/'
        backend.create_principal(cup, create_defaults=True)
        app = XandikosApp(backend, cup)

        app = WellknownRedirector(app, '/')

        wsgi_intercept.requests_intercept.install()
        wsgi_intercept.add_wsgi_intercept('127.0.0.1', 8080, lambda: app)

        def teardown():
            wsgi_intercept.remove_wsgi_intercept('127.0.0.1', 8080)
            wsgi_intercept.requests_intercept.uninstall()
        request.addfinalizer(teardown)

        def inner(collection='test'):
            url = 'http://127.0.0.1:8080/'
            args = {'url': url, 'collection': collection}

            if collection is not None:
                args = self.storage_class.create_collection(**args)
            return args
        return inner
示例#2
0
 def test_backend(self):
     path = tempfile.mkdtemp()
     try:
         backend = XandikosBackend(path)
         backend.create_principal("foo", create_defaults=True)
         XandikosApp(backend, "foo")
     finally:
         shutil.rmtree(path)
示例#3
0
class TestLocalXandikos(RepeatedFunctionalTestsBaseClass):
    """
    Sets up a local Xandikos server and Runs the functional tests towards it
    """
    def setup(self):
        if not test_xandikos:
            raise SkipTest("Skipping Xadikos test due to configuration")
        self.serverdir = tempfile.TemporaryDirectory()
        self.serverdir.__enter__()
        ## TODO - we should do something with the access logs from Xandikos
        self.backend = XandikosBackend(path=self.serverdir.name)
        self.backend.create_principal('/sometestuser/', create_defaults=True)
        self.xandikos_server = make_server(
            xandikos_host, xandikos_port,
            XandikosApp(self.backend, '/sometestuser/'))
        self.xandikos_thread = threading.Thread(
            target=self.xandikos_server.serve_forever)
        self.xandikos_thread.start()
        self.server_params = {
            'url':
            'http://%s:%i/sometestuser/' % (xandikos_host, xandikos_port),
            'username': '******',
            'password': '******'
        }
        ## TODO: this should go away eventually.  Ref https://github.com/jelmer/xandikos/issues/102 support for expanded search for recurring events has been fixed in the master branch of xandikos.
        self.server_params['norecurring'] = True
        RepeatedFunctionalTestsBaseClass.setup(self)

    def teardown(self):
        if not test_xandikos:
            return
        self.xandikos_server.shutdown()
        self.xandikos_server.socket.close()
        i = 0
        while (self.xandikos_thread.is_alive()):
            time.sleep(0.05)
            i += 1
            assert (i < 100)
        self.serverdir.__exit__(None, None, None)
        RepeatedFunctionalTestsBaseClass.teardown(self)
示例#4
0
 def setup(self):
     if not test_xandikos:
         raise SkipTest("Skipping Xadikos test due to configuration")
     self.serverdir = tempfile.TemporaryDirectory()
     self.serverdir.__enter__()
     ## TODO - we should do something with the access logs from Xandikos
     self.backend = XandikosBackend(path=self.serverdir.name)
     self.backend.create_principal('/sometestuser/', create_defaults=True)
     self.xandikos_server = make_server(
         xandikos_host, xandikos_port,
         XandikosApp(self.backend, '/sometestuser/'))
     self.xandikos_thread = threading.Thread(
         target=self.xandikos_server.serve_forever)
     self.xandikos_thread.start()
     self.server_params = {
         'url':
         'http://%s:%i/sometestuser/' % (xandikos_host, xandikos_port),
         'username': '******',
         'password': '******'
     }
     ## TODO: this should go away eventually.  Ref https://github.com/jelmer/xandikos/issues/102 support for expanded search for recurring events has been fixed in the master branch of xandikos.
     self.server_params['norecurring'] = True
     RepeatedFunctionalTestsBaseClass.setup(self)
示例#5
0
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA  02110-1301, USA.

"""WSGI wrapper for xandikos.
"""

import logging
import os

from xandikos.web import XandikosBackend, XandikosApp

backend = XandikosBackend(path=os.environ['XANDIKOSPATH'])
if not os.path.isdir(backend.path):
    if os.getenv('AUTOCREATE'):
        os.makedirs(os.environ['XANDIKOSPATH'])
    else:
        logging.warning('%r does not exist.', backend.path)

current_user_principal = os.environ.get('CURRENT_USER_PRINCIPAL', '/user/')
if not backend.get_resource(current_user_principal):
    if os.getenv('AUTOCREATE'):
        backend.create_principal(
            current_user_principal,
            create_defaults=os.environ['AUTOCREATE'] == 'defaults')
    else:
        logging.warning(
            'default user principal \'%s\' does not exist. Create directory %s'