diff --git a/run-tests.sh b/run-tests.sh index 7dd4e9d..537d00b 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -19,6 +19,23 @@ set -o errexit # Quit on unbound symbols set -o nounset +keep_services=0 +pytest_args=() +for arg in $@; do + # from the CLI args, filter out some known values and forward the rest to "pytest" + # note: we don't use "getopts" here b/c of some limitations (e.g. long options), + # which means that we can't combine short options (e.g. "./run-tests -Kk pattern") + case ${arg} in + -K|--keep-services) + keep_services=1 + ;; + *) + pytest_args+=( ${arg} ) + ;; + esac +done + + # Always bring down docker services function cleanup() { eval "$(docker-services-cli down --env)" @@ -29,6 +46,6 @@ python -m check_manifest python -m setup extract_messages --output-file /dev/null python -m sphinx.cmd.build -qnNW docs docs/_build/html eval "$(docker-services-cli up --db ${DB:-postgresql} --search ${SEARCH:-opensearch} --cache ${CACHE:-redis} --mq ${MQ:-rabbitmq} --env)" -python -m pytest +python -m pytest ${pytest_args[@]+"${pytest_args[@]}"} tests_exit_code=$? exit "$tests_exit_code" diff --git a/tests/conftest.py b/tests/conftest.py index eca4183..f01eeca 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -213,9 +213,11 @@ def users(UserFixture, app, database, users_data): return users -def _create_group(name, description, database): +def _create_group(id, name, description, is_managed, database): """Creates a Role/Group.""" - r = current_datastore.create_role(name=name, description=description) + r = current_datastore.create_role( + id=id, name=name, description=description, is_managed=is_managed + ) current_datastore.commit() return r @@ -224,20 +226,38 @@ def _create_group(name, description, database): @pytest.fixture(scope="module") def group(database): """A single group.""" - r = _create_group(name="it-dep", description="IT Department", database=database) + r = _create_group( + id="it-dep", + name="it-dep", + description="IT Department", + is_managed=True, + database=database, + ) GroupAggregate.index.refresh() return r @pytest.fixture(scope="module") -def groups(database, group): +def group2(database): """A single group.""" - roles = [group] # it-dep - roles.append( - _create_group(name="hr-dep", description="HR Department", database=database) + r = _create_group( + id="hr-dep", + name="hr-dep", + description="HR Department", + is_managed=True, + database=database, ) + GroupAggregate.index.refresh() + return r + + +@pytest.fixture(scope="module") +def groups(database, group, group2): + """A single group.""" + roles = [group, group2] + GroupAggregate.index.refresh() return roles