From fa2c50b9c6cc037a8ab348b5a746b2e728f3068a Mon Sep 17 00:00:00 2001 From: drebs Date: Mon, 25 Jul 2016 07:48:41 -0300 Subject: [test] allow custom couch url for couch tests --- testing/test_soledad/util.py | 4 ++-- testing/tests/conftest.py | 13 +++++++++++++ testing/tests/couch/common.py | 6 ++---- testing/tests/couch/couchdb.ini.template | 22 ---------------------- testing/tests/couch/test_backend.py | 5 +---- 5 files changed, 18 insertions(+), 32 deletions(-) create mode 100644 testing/tests/conftest.py delete mode 100644 testing/tests/couch/couchdb.ini.template (limited to 'testing') diff --git a/testing/test_soledad/util.py b/testing/test_soledad/util.py index 02f3859b..e23d185e 100644 --- a/testing/test_soledad/util.py +++ b/testing/test_soledad/util.py @@ -27,6 +27,7 @@ import shutil import random import string import couchdb +import pytest from uuid import uuid4 from mock import Mock @@ -344,6 +345,7 @@ class BaseSoledadTest(BaseLeapTest, MockedSharedDBTest): self.assertEqual(exp_doc.content, doc.content) +@pytest.mark.usefixtures("couch_url") class CouchDBTestCase(unittest.TestCase, MockedSharedDBTest): """ @@ -354,8 +356,6 @@ class CouchDBTestCase(unittest.TestCase, MockedSharedDBTest): """ Make sure we have a CouchDB instance for a test. """ - self.couch_port = 5984 - self.couch_url = 'http://localhost:%d' % self.couch_port self.couch_server = couchdb.Server(self.couch_url) def delete_db(self, name): diff --git a/testing/tests/conftest.py b/testing/tests/conftest.py new file mode 100644 index 00000000..3be9ba2a --- /dev/null +++ b/testing/tests/conftest.py @@ -0,0 +1,13 @@ +import pytest + + +def pytest_addoption(parser): + parser.addoption( + "--couch-url", type="string", default="http://127.0.0.1:5984", + help="the url for the couch server to be used during tests") + + +@pytest.fixture +def couch_url(request): + url = request.config.getoption('--couch-url') + request.cls.couch_url = url diff --git a/testing/tests/couch/common.py b/testing/tests/couch/common.py index 45cf8d7f..48d30168 100644 --- a/testing/tests/couch/common.py +++ b/testing/tests/couch/common.py @@ -13,10 +13,9 @@ nested_doc = tests.nested_doc def make_couch_database_for_test(test, replica_uid): - port = str(test.couch_port) dbname = ('test-%s' % uuid4().hex) db = couch.CouchDatabase.open_database( - urljoin('http://localhost:' + port, dbname), + urljoin(test.couch_url, dbname), create=True, replica_uid=replica_uid or 'test', ensure_ddocs=True) @@ -25,8 +24,7 @@ def make_couch_database_for_test(test, replica_uid): def copy_couch_database_for_test(test, db): - port = str(test.couch_port) - couch_url = 'http://localhost:' + port + couch_url = test.couch_url new_dbname = db._dbname + '_copy' new_db = couch.CouchDatabase.open_database( urljoin(couch_url, new_dbname), diff --git a/testing/tests/couch/couchdb.ini.template b/testing/tests/couch/couchdb.ini.template deleted file mode 100644 index 174d9d86..00000000 --- a/testing/tests/couch/couchdb.ini.template +++ /dev/null @@ -1,22 +0,0 @@ -; etc/couchdb/default.ini.tpl. Generated from default.ini.tpl.in by configure. - -; Upgrading CouchDB will overwrite this file. - -[couchdb] -database_dir = %(tempdir)s/lib -view_index_dir = %(tempdir)s/lib -max_document_size = 4294967296 ; 4 GB -os_process_timeout = 120000 ; 120 seconds. for view and external servers. -max_dbs_open = 100 -delayed_commits = true ; set this to false to ensure an fsync before 201 Created is returned -uri_file = %(tempdir)s/lib/couch.uri -file_compression = snappy - -[log] -file = %(tempdir)s/log/couch.log -level = info -include_sasl = true - -[httpd] -port = 0 -bind_address = 127.0.0.1 diff --git a/testing/tests/couch/test_backend.py b/testing/tests/couch/test_backend.py index c399338e..4fad11cf 100644 --- a/testing/tests/couch/test_backend.py +++ b/testing/tests/couch/test_backend.py @@ -39,10 +39,7 @@ class TestCouchBackendImpl(CouchDBTestCase): def test__allocate_doc_id(self): db = couch.CouchDatabase.open_database( - urljoin( - 'http://localhost:' + str(self.couch_port), - ('test-%s' % uuid4().hex) - ), + urljoin(self.couch_url, 'test-%s' % uuid4().hex), create=True) doc_id1 = db._allocate_doc_id() self.assertTrue(doc_id1.startswith('D-')) -- cgit v1.2.3