Repository navigation
sdk: Add REQUIRE_COUCHDB_INTEGRATION_TESTS to fail CouchDB tests
#653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,13 +21,22 @@ | |
| ) | ||
|
|
||
|
|
||
| def env_flag(name: str) -> bool: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice helper. |
||
| """Return whether the environment variable ``name`` is set to "1", "true" or "yes" (case-insensitive).""" | ||
| return os.environ.get(name, "false").lower() in {"1", "true", "yes"} | ||
|
|
||
|
|
||
| # By default, the schema validation tests are skipped when the AAS schema files are missing, so that a plain local | ||
| # `python -m unittest` run doesn't require downloading them first. Set this environment variable to "1"/"true" | ||
| # (e.g. in CI) to instead make those tests fail if the files are missing, so a broken download can't silently cause | ||
| # the tests to be skipped without anyone noticing. | ||
| REQUIRE_SCHEMAS = os.environ.get("REQUIRE_SCHEMA_TESTS", "false").lower() in {"1", "true", "yes"} | ||
| REQUIRE_SCHEMAS = env_flag("REQUIRE_SCHEMA_TESTS") | ||
|
|
||
| # Likewise, the CouchDB tests are skipped when no CouchDB is reachable. Set this environment variable to fail them | ||
| # instead. | ||
| REQUIRE_COUCHDB_INTEGRATION_TESTS = env_flag("REQUIRE_COUCHDB_INTEGRATION_TESTS") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: module-level constants could be annotated |
||
|
|
||
| # Check if CouchDB database is available. Otherwise, skip tests. | ||
| # Check if CouchDB database is available. Otherwise, skip tests (unless REQUIRE_COUCHDB_INTEGRATION_TESTS is set). | ||
| try: | ||
| request = urllib.request.Request( | ||
| "{}/{}".format( | ||
|
|
@@ -53,3 +62,7 @@ | |
| except urllib.error.URLError as e: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that CI relies on this probe, it should be more robust:
Suggestion: |
||
| COUCHDB_OKAY = False | ||
| COUCHDB_ERROR = e | ||
|
|
||
| COUCHDB_UNREACHABLE_MESSAGE = "No CouchDB is reachable at {}/{}: {}".format( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: this message is always built, so when CouchDB is reachable it reads |
||
| TEST_CONFIG["couchdb"]["url"], TEST_CONFIG["couchdb"]["database"], COUCHDB_ERROR | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,12 @@ | |
| from basyx.aas.backend import couchdb | ||
| from basyx.aas.examples.data.example_aas import * | ||
|
|
||
| from test._helper.test_helpers import COUCHDB_ERROR, COUCHDB_OKAY, TEST_CONFIG | ||
| from test._helper.test_helpers import ( | ||
| COUCHDB_OKAY, | ||
| COUCHDB_UNREACHABLE_MESSAGE, | ||
| REQUIRE_COUCHDB_INTEGRATION_TESTS, | ||
| TEST_CONFIG, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| ) | ||
|
|
||
| source_core: str = ( | ||
| "couchdb://" | ||
|
|
@@ -21,13 +26,14 @@ | |
| ) | ||
|
|
||
|
|
||
| @unittest.skipUnless( | ||
| COUCHDB_OKAY, | ||
| "No CouchDB is reachable at {}/{}: {}".format( | ||
| TEST_CONFIG["couchdb"]["url"], TEST_CONFIG["couchdb"]["database"], COUCHDB_ERROR | ||
| ), | ||
| ) | ||
| @unittest.skipUnless(COUCHDB_OKAY or REQUIRE_COUCHDB_INTEGRATION_TESTS, COUCHDB_UNREACHABLE_MESSAGE) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same condition is checked twice here: once in def require_couchdb() -> None:
if not COUCHDB_OKAY:
if REQUIRE_COUCHDB_INTEGRATION_TESTS:
raise RuntimeError(COUCHDB_UNREACHABLE_MESSAGE)
raise unittest.SkipTest(COUCHDB_UNREACHABLE_MESSAGE) |
||
| class CouchDBBackendTest(unittest.TestCase): | ||
|
|
||
| @classmethod | ||
| def setUpClass(cls) -> None: | ||
| if not COUCHDB_OKAY: | ||
| raise RuntimeError(f"REQUIRE_COUCHDB_INTEGRATION_TESTS is set. {COUCHDB_UNREACHABLE_MESSAGE}") | ||
|
|
||
| def setUp(self) -> None: | ||
| self.couch_identifiable_store = couchdb.CouchDBIdentifiableStore( | ||
| TEST_CONFIG["couchdb"]["url"], TEST_CONFIG["couchdb"]["database"] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ | |
|
|
||
| from basyx.aas import model | ||
|
|
||
| from .._helper.test_helpers import COUCHDB_ERROR, COUCHDB_OKAY, TEST_CONFIG | ||
| from .._helper.test_helpers import COUCHDB_OKAY, COUCHDB_UNREACHABLE_MESSAGE, REQUIRE_COUCHDB_INTEGRATION_TESTS | ||
|
|
||
|
|
||
| class TutorialTest(unittest.TestCase): | ||
|
|
@@ -35,16 +35,10 @@ def test_tutorial_storage(self): | |
| pass | ||
| # 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, | ||
| ), | ||
| ) | ||
| @unittest.skipUnless(COUCHDB_OKAY or REQUIRE_COUCHDB_INTEGRATION_TESTS, COUCHDB_UNREACHABLE_MESSAGE) | ||
| def test_tutorial_backend_couchdb(self): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| pass | ||
| if not COUCHDB_OKAY: | ||
| self.fail(f"REQUIRE_COUCHDB_INTEGRATION_TESTS is set. {COUCHDB_UNREACHABLE_MESSAGE}") | ||
| # The tutorial already includes assert statements for the relevant points. So no further checks are required. | ||
|
|
||
| def test_tutorial_serialization_deserialization_json(self): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring presents
--failsafeas safe for idempotent re-runs, but it has two side effects that should be mentioned:_securityentry. If an earlier run failed after creating the DB, re-running with--failsafeleaves the user missing, the probe gets a 401, and the tests skip or fail.