Skip to content

Commit

Permalink
tests: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jrcastro2 committed May 15, 2023
1 parent d5caca6 commit c077fc9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
19 changes: 18 additions & 1 deletion run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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"
34 changes: 27 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit c077fc9

Please sign in to comment.