|
| 1 | +# coding: utf-8 |
| 2 | +from __future__ import unicode_literals |
| 3 | +from __future__ import absolute_import |
| 4 | + |
| 5 | +import re |
| 6 | +import time |
| 7 | +import unittest |
| 8 | +import fs.test |
| 9 | +import docker |
| 10 | + |
| 11 | +from .base import _TestWebDAVFS |
| 12 | + |
| 13 | + |
| 14 | +class _TestDocker(_TestWebDAVFS, fs.test.FSTestCases): |
| 15 | + """Test WebDAVFS implementation using docker images.""" |
| 16 | + |
| 17 | + server_image = NotImplemented |
| 18 | + |
| 19 | + @classmethod |
| 20 | + def serverStarted(cls): |
| 21 | + regex = re.compile(b'Server [hw]as started') |
| 22 | + cls.webdav_container.update() |
| 23 | + return regex.search(cls.webdav_container.logs()) is not None |
| 24 | + |
| 25 | + @classmethod |
| 26 | + def startServer(cls): |
| 27 | + cls.webdav_container = cls.docker_client.containers.run( |
| 28 | + cls.server_image, detach=True, tty=True, |
| 29 | + ports={'8080/tcp': ('127.0.0.1', 10080)} |
| 30 | + ) |
| 31 | + while not cls.serverStarted(): |
| 32 | + time.sleep(1) |
| 33 | + |
| 34 | + @classmethod |
| 35 | + def stopServer(cls): |
| 36 | + cls.webdav_container.kill() |
| 37 | + cls.webdav_container.remove() |
| 38 | + |
| 39 | + @classmethod |
| 40 | + def setUpClass(cls): |
| 41 | + cls.docker_client = docker.from_env(version='auto') |
| 42 | + cls.startServer() |
| 43 | + |
| 44 | + @classmethod |
| 45 | + def tearDownClass(cls): |
| 46 | + cls.stopServer() |
| 47 | + time.sleep(20) |
| 48 | + |
| 49 | + |
| 50 | +class TestExistDB30(_TestDocker, unittest.TestCase): |
| 51 | + server_image = 'zopyx/existdb-30' |
| 52 | + webdav_url = 'webdav://admin:admin@localhost:10080/exist/webdav/db' |
| 53 | + |
| 54 | +class TestExistDB22(_TestDocker, unittest.TestCase): |
| 55 | + server_image = 'zopyx/existdb-22' |
| 56 | + webdav_url = 'webdav://admin:admin@localhost:10080/exist/webdav/db' |
| 57 | + |
| 58 | +class TestBaseX86(_TestDocker, unittest.TestCase): |
| 59 | + server_image = 'zopyx/basex-86' |
| 60 | + webdav_url = 'webdav://admin:admin@localhost:10080/webdav' |
0 commit comments