Skip to content

Commit

Permalink
use env files for selenium tests docker compose. (#994)
Browse files Browse the repository at this point in the history
  • Loading branch information
JFU-GIT committed Nov 24, 2021
1 parent c02a2bb commit 046b14e
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 89 deletions.
54 changes: 16 additions & 38 deletions docker-compose.selenium.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
version: '3'

services:
tests:
selenium-tests:
build:
context: ./
dockerfile: Dockerfile.selenium
command: python runtests.py apps.integration_tests.selenium_tests.SeleniumTests
environment:
- HOSTNAME_URL=${HOSTNAME_URL}
- USE_MSLSX=${USE_MSLSX}
- USE_DEBUG=${USE_DEBUG}
command: python runtests.py --selenium apps.integration_tests.selenium_tests.SeleniumTests
env_file:
- docker-compose/selenium-env-vars.env
volumes:
- .:/code
depends_on:
- bb2slsx

tests-debug:
selenium-tests-debug:
build:
context: ./
dockerfile: Dockerfile.selenium
command: python runtests.py apps.integration_tests.selenium_tests.SeleniumTests
environment:
- HOSTNAME_URL=${HOSTNAME_URL}
- USE_MSLSX=${USE_MSLSX}
- USE_DEBUG=${USE_DEBUG}
command: python runtests.py --selenium apps.integration_tests.selenium_tests.SeleniumTests
env_file:
- docker-compose/selenium-env-vars.env
volumes:
- .:/code
depends_on:
Expand All @@ -47,9 +43,8 @@ services:

db:
image: postgres
environment:
- POSTGRES_DB=bluebutton
- POSTGRES_PASSWORD=toor
env_file:
- docker-compose/db-env-vars.env
ports:
- "5432:5432"
healthcheck:
Expand All @@ -58,32 +53,15 @@ services:
timeout: 5s
retries: 5


bb2slsx:
build: .
command: ./docker-compose/bluebutton_server_start.sh
environment:
- DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE}
- DATABASES_CUSTOM=postgres:https://postgres:toor@db:5432/bluebutton
- OAUTHLIB_INSECURE_TRANSPORT=true
- DJANGO_DEFAULT_SAMPLE_FHIR_ID="-20140000008325"
- DJANGO_SECURE_SESSION=False
- FHIR_URL="https://prod-sbx.bfd.cms.gov"
- DJANGO_FHIR_CERTSTORE=${DJANGO_FHIR_CERTSTORE}
- DJANGO_MEDICARE_SLSX_REDIRECT_URI=${DJANGO_MEDICARE_SLSX_REDIRECT_URI}
- DJANGO_MEDICARE_SLSX_LOGIN_URI=${DJANGO_MEDICARE_SLSX_LOGIN_URI}
- DJANGO_SLSX_HEALTH_CHECK_ENDPOINT=${DJANGO_SLSX_HEALTH_CHECK_ENDPOINT}
- DJANGO_SLSX_TOKEN_ENDPOINT=${DJANGO_SLSX_TOKEN_ENDPOINT}
- DJANGO_SLSX_SIGNOUT_ENDPOINT=${DJANGO_SLSX_SIGNOUT_ENDPOINT}
- DJANGO_SLSX_USERINFO_ENDPOINT=${DJANGO_SLSX_USERINFO_ENDPOINT}
- DJANGO_SLSX_CLIENT_ID=bb2api
- DJANGO_SLSX_CLIENT_SECRET=${DJANGO_SLSX_CLIENT_SECRET}
- HOSTNAME_URL=${HOSTNAME_URL}
- DJANGO_SLSX_VERIFY_SSL_INTERNAL=False
- DJANGO_SLSX_VERIFY_SSL_EXTERNAL=True
- DJANGO_LOG_JSON_FORMAT_PRETTY=${DJANGO_LOG_JSON_FORMAT_PRETTY}
- DJANGO_USER_ID_ITERATIONS=${DJANGO_USER_ID_ITERATIONS}
- DJANGO_USER_ID_SALT=${DJANGO_USER_ID_SALT}
env_file:
- docker-compose/web-env-vars.env
- docker-compose/slsx-env-vars.env
- docker-compose/selenium-env-vars.env
# local devel specific variables go here!
- .env
volumes:
- .:/code
ports:
Expand Down
31 changes: 23 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ services:
command: msls
ports:
- "8080:8080"
profiles:
- mocksls
db:
image: postgres
env_file:
Expand All @@ -19,14 +21,8 @@ services:
command: ./docker-compose/bluebutton_server_start.sh
env_file:
- docker-compose/web-env-vars.env
#
# Uncomment line below to use SLSx as the identity service.
- docker-compose/slsx-env-vars.env
#
# Uncomment line below to use MSLS as a MOCK SLSx identity service.
#- docker-compose/msls-env-vars.env
#
# Your local devel specific variables go here!
# local devel specific variables go here!
- .env
volumes:
- .:/code
Expand All @@ -35,7 +31,24 @@ services:
- "5678:5678"
depends_on:
- db

web_msls:
build: .
command: ./docker-compose/bluebutton_server_start.sh
env_file:
- docker-compose/web-env-vars.env
- docker-compose/msls-env-vars.env
# local devel specific variables go here!
- .env
volumes:
- .:/code
ports:
- "8000:8000"
- "5678:5678"
depends_on:
- db
- msls
profiles:
- mocksls
unittests:
build: .
command: python3 -m debugpy --listen 0.0.0.0:6789 --wait-for-client runtests.py
Expand All @@ -45,3 +58,5 @@ services:
- "6789:6789"
volumes:
- .:/code
profiles:
- tests
22 changes: 6 additions & 16 deletions docker-compose/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,22 @@ To enable usage of the AWS CLI/Boto3 for AWS services (for example S3 or Kinesis

To setup any ENV variables specific to your local development work, add them to the `.env` file. This file is in the `.gitignore`, so will not get added in commits (local use only). You can also override ENVs used in the `docker-compose/bluebutton_server_start.sh` web server startup script.

Edit the `docker-compose.yml` file to choose between SLSx (default) or MSLS mode:

To run the web server in SLSx mode (default), un-comment/comment the following lines like so:
To startup the Docker containerized BB2 server using slsx:

```
# Uncomment line below to use SLSx as the identity service.
- docker-compose/slsx-env-vars.env
#
# Uncomment line below to use MSLS as a MOCK SLSx identity service.
#- docker-compose/msls-env-vars.env
docker-compose up -d
```
Or equivalently:

Alternately, to run the web server in MSLS (mock service) mode, edit like so:
```
# Uncomment line below to use SLSx as the identity service.
#- docker-compose/slsx-env-vars.env
#
# Uncomment line below to use MSLS as a MOCK SLSx identity service.
- docker-compose/msls-env-vars.env
docker-compose up -d web
```


To startup the Docker containerized BB2 server:
To startup the Docker containerized BB2 server using msls:

```
docker-compose up -d
docker-compose up -d web_msls
```

To shutdown the Docker containerized BB2 server (this is needed when switching between SLSx and MSLS modes):
Expand Down
24 changes: 6 additions & 18 deletions docker-compose/run_selenium_tests_local_keybase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ export HOSTNAME_URL="http:https://bb2slsx:8000"
# Backend FHIR server to use for selenium tests with FHIR requests:
FHIR_URL="https://prod-sbx.bfd.cms.gov"

# List of tests to run. To be passed in to runtests.py.
TESTS_LIST="apps.integration_tests.selenium_tests.SeleniumTests"

export DJANGO_SETTINGS_MODULE="hhs_oauth_server.settings.logging_it"

# Echo function that includes script name on each line for console log readability
Expand All @@ -45,7 +42,8 @@ set -e -u -o pipefail

export USE_MSLSX=true
export USE_DEBUG=false

export SERVICE_NAME="selenium-tests"
export TESTS_LIST="apps.integration_tests.selenium_tests.SeleniumTests"
export DJANGO_MEDICARE_SLSX_REDIRECT_URI="http:https://bb2slsx:8000/mymedicare/sls-callback"
export DJANGO_MEDICARE_SLSX_LOGIN_URI="http:https://msls:8080/sso/authorize?client_id=bb2api"
export DJANGO_SLSX_HEALTH_CHECK_ENDPOINT="http:https://msls:8080/health"
Expand Down Expand Up @@ -83,6 +81,7 @@ else
if [[ $1 == *debug ]]
then
export USE_DEBUG=true
export SERVICE_NAME="selenium-tests-debug"
fi
if [[ $1 == "slsx" || $1 == "slsx-debug" ]]
then
Expand All @@ -96,15 +95,14 @@ else
fi
if [[ $1 == "logit" ]]
then
TESTS_LIST="apps.integration_tests.logging_tests.LoggingTests.test_auth_fhir_flows_logging"
export TESTS_LIST="apps.integration_tests.logging_tests.LoggingTests.test_auth_fhir_flows_logging"
export DJANGO_LOG_JSON_FORMAT_PRETTY=False
fi
fi
fi

echo "DJANGO_SETTINGS_MODULE: " ${DJANGO_SETTINGS_MODULE}
echo "HOSTNAME_URL: " ${HOSTNAME_URL}
echo "TESTS: " ${TESTS_LIST}

# Set KeyBase ENV path based on your type of system
SYSTEM=$(uname -s)
Expand Down Expand Up @@ -206,22 +204,12 @@ export DJANGO_PASSWORD_HASH_ITERATIONS=${DJANGO_PASSWORD_HASH_ITERATIONS}
export DJANGO_SLSX_CLIENT_ID=${DJANGO_SLSX_CLIENT_ID}
export DJANGO_SLSX_CLIENT_SECRET=${DJANGO_SLSX_CLIENT_SECRET}

TEST_SERVICE_NAME="tests"
if [[ "$USE_DEBUG" = true ]]
then
TEST_SERVICE_NAME="tests-debug"
fi

echo "Selenium tests ..."
echo "MSLSX=" ${USE_MSLSX}
echo "DEBUG=" ${USE_DEBUG}
echo "SERVICE NAME=" ${SERVICE_NAME}

if [ "$USE_DEBUG" = true ]
then
docker-compose -f docker-compose.selenium.yml run tests-debug bash -c "python runtests.py --selenium ${TESTS_LIST}"
else
docker-compose -f docker-compose.selenium.yml run tests bash -c "python runtests.py --selenium ${TESTS_LIST}"
fi
docker-compose -f docker-compose.selenium.yml run ${SERVICE_NAME} bash -c "python runtests.py --selenium ${TESTS_LIST}"

# Stop containers after use
echo_msg
Expand Down
5 changes: 5 additions & 0 deletions docker-compose/selenium-env-vars.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Selenium tests related ENV vars file for the "tests" service containter.
HOSTNAME_URL=${HOSTNAME_URL}
USE_MSLSX=${USE_MSLSX}
USE_DEBUG=${USE_DEBUG}
DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE:-"hhs_oauth_server.settings.logging_it"}
12 changes: 6 additions & 6 deletions docker-compose/slsx-env-vars.env
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# SLSx (TEST) related ENV vars file for the "web" service containter.
DJANGO_MEDICARE_SLSX_AKAMAI_ACA_TOKEN=${DJANGO_MEDICARE_SLSX_AKAMAI_ACA_TOKEN}
DJANGO_MEDICARE_SLSX_REDIRECT_URI=http:https://localhost:8000/mymedicare/sls-callback
DJANGO_MEDICARE_SLSX_LOGIN_URI=https://test.medicare.gov/sso/authorize?client_id=bb2api
DJANGO_SLSX_HEALTH_CHECK_ENDPOINT=https://test.accounts.cms.gov/health
DJANGO_SLSX_TOKEN_ENDPOINT=https://test.medicare.gov/sso/session
DJANGO_SLSX_SIGNOUT_ENDPOINT=https://test.medicare.gov/sso/signout
DJANGO_SLSX_USERINFO_ENDPOINT=https://test.accounts.cms.gov/v1/users
DJANGO_MEDICARE_SLSX_REDIRECT_URI=${DJANGO_MEDICARE_SLSX_REDIRECT_URI:-"http:https://localhost:8000/mymedicare/sls-callback"}
DJANGO_MEDICARE_SLSX_LOGIN_URI=${DJANGO_MEDICARE_SLSX_LOGIN_URI:-"https://test.medicare.gov/sso/authorize?client_id=bb2api"}
DJANGO_SLSX_HEALTH_CHECK_ENDPOINT=${DJANGO_SLSX_HEALTH_CHECK_ENDPOINT:-"https://test.accounts.cms.gov/health"}
DJANGO_SLSX_TOKEN_ENDPOINT=${DJANGO_SLSX_TOKEN_ENDPOINT:-"https://test.medicare.gov/sso/session"}
DJANGO_SLSX_SIGNOUT_ENDPOINT=${DJANGO_SLSX_SIGNOUT_ENDPOINT:-"https://test.medicare.gov/sso/signout"}
DJANGO_SLSX_USERINFO_ENDPOINT=${DJANGO_SLSX_USERINFO_ENDPOINT:-"https://test.accounts.cms.gov/v1/users"}

# SLSx credentials
DJANGO_SLSX_CLIENT_ID=bb2api
Expand Down
2 changes: 1 addition & 1 deletion docker-compose/unittests-env-vars.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
DJANGO_SETTINGS_MODULE=hhs_oauth_server.settings.dev
DATABASES_CUSTOM=postgres:https://postgres:toor@db:5432/bluebutton
OAUTHLIB_INSECURE_TRANSPORT=true
DJANGO_DEFAULT_SAMPLE_FHIR_ID="-20140000008325"
# DJANGO_DEFAULT_SAMPLE_FHIR_ID="-20140000008325"
DJANGO_SECURE_SESSION=False
2 changes: 1 addition & 1 deletion docker-compose/web-env-vars.env
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ DJANGO_SETTINGS_MODULE=hhs_oauth_server.settings.dev
DATABASES_CUSTOM=postgres:https://postgres:toor@db:5432/bluebutton
OAUTHLIB_INSECURE_TRANSPORT=true
DJANGO_SECURE_SESSION=False
DJANGO_LOG_JSON_FORMAT_PRETTY=True
DJANGO_LOG_JSON_FORMAT_PRETTY=${DJANGO_LOG_JSON_FORMAT_PRETTY:-True}

# AWS credentials
AWS_DEFAULT_REGION=us-east-1
Expand Down
1 change: 0 additions & 1 deletion runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
if env_var in os.environ:
del os.environ[env_var]
elif not args.selenium:
# For tests using selenium, inherit SLSX config from context;
# Unset ENV variables for Django unit type tests so default values get set.
for env_var in ['FHIR_URL', 'DJANGO_MEDICARE_SLSX_LOGIN_URI', 'DJANGO_MEDICARE_SLSX_REDIRECT_URI',
'DJANGO_SLSX_USERINFO_ENDPOINT', 'DJANGO_SLSX_TOKEN_ENDPOINT',
Expand Down

0 comments on commit 046b14e

Please sign in to comment.