Commit 7b7d8d8b authored by Michael Thies's avatar Michael Thies
Browse files

test: Skip CouchDB tutorial test if CouchDB is not available

parent 6905b38b
Pipeline #358417 failed with stages
in 1 minute and 30 seconds
import configparser
import os.path
import urllib.request
import urllib.error
import base64
TEST_CONFIG = configparser.ConfigParser()
TEST_CONFIG.read((os.path.join(os.path.dirname(__file__), "..", "test_config.default.ini"),
os.path.join(os.path.dirname(__file__), "..", "test_config.ini")))
# Check if CouchDB database is available. Otherwise, skip tests.
try:
request = urllib.request.Request(
"{}/{}".format(TEST_CONFIG['couchdb']['url'], TEST_CONFIG['couchdb']['database']),
headers={
'Authorization': 'Basic %s' % base64.b64encode(
('%s:%s' % (TEST_CONFIG['couchdb']['user'], TEST_CONFIG['couchdb']['password']))
.encode('ascii')).decode("ascii")
},
method='HEAD')
urllib.request.urlopen(request)
COUCHDB_OKAY = True
COUCHDB_ERROR = None
except urllib.error.URLError as e:
COUCHDB_OKAY = False
COUCHDB_ERROR = e
......@@ -8,44 +8,20 @@
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
import base64
import configparser
import os
import unittest
import unittest.mock
import urllib.request
import urllib.error
from aas.backend import couchdb
from aas.examples.data.example_aas import *
from .._helper.test_helpers import TEST_CONFIG, COUCHDB_OKAY, COUCHDB_ERROR
TEST_CONFIG = configparser.ConfigParser()
TEST_CONFIG.read((os.path.join(os.path.dirname(__file__), "..", "test_config.default.ini"),
os.path.join(os.path.dirname(__file__), "..", "test_config.ini")))
source_core: str = "couchdb://" + TEST_CONFIG["couchdb"]["url"].lstrip("http://") + "/" + \
TEST_CONFIG["couchdb"]["database"] + "/"
# Check if CouchDB database is available. Otherwise, skip tests.
try:
request = urllib.request.Request(
"{}/{}".format(TEST_CONFIG['couchdb']['url'], TEST_CONFIG['couchdb']['database']),
headers={
'Authorization': 'Basic %s' % base64.b64encode(
('%s:%s' % (TEST_CONFIG['couchdb']['user'], TEST_CONFIG['couchdb']['password']))
.encode('ascii')).decode("ascii")
},
method='HEAD')
urllib.request.urlopen(request)
COUCHDB_OKAY = True
COUCHDB_ERROR = None
except urllib.error.URLError as e:
COUCHDB_OKAY = False
COUCHDB_ERROR = e
class CouchDBBackendOfflineMethodsTest(unittest.TestCase):
def test_parse_source(self):
couchdb.register_credentials(url="couchdb.plt.rwth-aachen.de:5984",
......
......@@ -14,13 +14,12 @@ Tests for the tutorials
Functions to test if a tutorial is executable
"""
import os
import re
import tempfile
import unittest
from contextlib import contextmanager
from aas import model
from aas.adapter.json import read_aas_json_file
from .._helper.test_helpers import COUCHDB_OKAY, TEST_CONFIG, COUCHDB_ERROR
class TutorialTest(unittest.TestCase):
......@@ -34,6 +33,9 @@ class TutorialTest(unittest.TestCase):
from aas.examples import tutorial_storage
# The tutorial already includes assert statements for the relevant points. So no further checks are required.
@unittest.skipUnless(COUCHDB_OKAY, "No CouchDB is reachable at {}/{}: {}".format(TEST_CONFIG['couchdb']['url'],
TEST_CONFIG['couchdb']['database'],
COUCHDB_ERROR))
def test_tutorial_backend_couchdb(self):
from aas.examples import tutorial_backend_couchdb
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment