Skip to content

Commit 113320f

Browse files
author
James Fuqian
authored
Merge pull request #26 from CMSgov/jfuqian/BB2-1702-Python-Sample-App-code-cleanup
[BB2-1702] BB2 Python Sample App code refactor (use SDK) & cleanup
2 parents 72c5acc + 4433e43 commit 113320f

34 files changed

+297
-865
lines changed

README-bb2-dev.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Blue Button 2.0 Sample Application Development Documentation
2+
3+
## Introduction
4+
5+
This README contains information related to developing the SDK.
6+
7+
It is intended for BB2 team members or others performing sample application development work.
8+
9+
## Run selenium tests in docker
10+
11+
Configure the remote target BB2 instance where the tested app is registered (as described above "Running the Back-end & Front-end")
12+
13+
Change your `callback_url` configuration to use `server` instead of `localhost`. For example:
14+
```JSON
15+
"callback_url": "http://server:3001/api/bluebutton/callback/"
16+
```
17+
You can also start your configuration by following the sample config template for selenium tests:
18+
19+
cp server/sample-bluebutton-selenium-config.json server/.bluebutton-config.json
20+
21+
You will also need to add this URL to your `redirect_uris` list in your application's configuration on the BB2 Sandbox UI.
22+
23+
Go to local repository base directory and run docker compose as below:
24+
25+
docker-compose -f docker-compose.selenium.yml up --abort-on-container-exit
26+
27+
Note: --abort-on-container-exit will abort client and server containers when selenium tests ends
28+
29+
Note: You may need to clean up already existing Docker containers, if you are having issues or have changed your configuration file.
30+
31+
## Visual trouble shoot
32+
33+
Install VNC viewer and point browser to http://localhost:5900 to monitor web UI interactions

README.md

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ Running the Back-end & Front-end
2525

2626
Once Docker and Python are Installed then do the following:
2727

28-
copy server/src/configs/sample_config.py -> server/src/configs/config.py
29-
30-
Make sure to replace the clientId and clientSecret variables within the config file with
31-
the ones you were provided, for your application, when you created your Blue Button Sandbox account.
28+
cp server/sample-bluebutton-config.json server/.bluebutton-config.json
3229

33-
copy server/src/prestart/env/sandbox.sample.env -> server/src/prestart/env/development.env
30+
Make sure to replace the client_id and client_secret variables within the config file with
31+
the ones you were provided, for your application, when you created your Blue Button Sandbox account,
32+
the supported environments are SANDBOX or PRODUCTION.
3433

3534
docker-compose up -d
3635

@@ -51,27 +50,21 @@ data would be: BBUser29999 (PWD: PW29999!) or BBUser29998 (PWD: PW29998!)
5150

5251
Development
5352
-----------
54-
Read the DEVELOPER NOTES found in the code to understand the application
55-
and where you will need to make adjustments/changes as well as some
56-
suggestions for best practices.
57-
58-
Debugging server component
59-
--------------------------
60-
debugpy remote debugging enabled on port 5678 for server in docker compose, developer can attach to server from IDE e.g. vscode.
53+
Read the comments in the code to understand the application and where
54+
you will need to make adjustments/changes as well as some suggestions
55+
for best practices.
6156

62-
## Run selenium tests in docker
57+
Python SDK
58+
----------
6359

64-
Configure the remote target BB2 instance where the tested app is registered (as described above "Running the Back-end & Front-end")
60+
The sample app utilizes our [Python SDK](https://github.com/CMSgov/cms-bb2-python-sdk).
6561

66-
Go to local repository base directory and run docker compose as below:
62+
Please review our SDK documentation for more information and additional features available for your use.
6763

68-
docker-compose -f docker-compose.selenium.yml up --abort-on-container-exit
6964

70-
Note: --abort-on-container-exit will abort client and server containers when selenium tests ends
71-
72-
## Visual trouble shoot
73-
74-
Install VNC viewer and point browser to http://localhost:5900 to monitor web UI interactions
65+
Debugging server component
66+
--------------------------
67+
debugpy remote debugging enabled on port 5678 for server in docker compose, developer can attach to server from IDE e.g. vscode.
7568

7669
Error Responses and handling:
7770
-----------------------------

docker-compose.selenium.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ services:
2424
build:
2525
context: ./selenium_tests
2626
dockerfile: ./Dockerfile
27-
command: pytest ./src/test_node_sample.py
27+
command: pytest ./src/test_python_sample.py
2828
depends_on:
2929
- chrome
3030
- server
Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
# Generated by Selenium IDE
21
import time
32
from selenium import webdriver
43
from selenium.webdriver.common.by import By
54
from selenium.webdriver.support import expected_conditions as EC
65
from selenium.webdriver.support.wait import WebDriverWait
76

7+
CSS_SEL_FE_ERR_MSG_CONTENT = "tbody .ds-u-text-align--left:nth-child(2)"
8+
89

910
class TestNodeSampleApp():
1011
driver_ready = False
@@ -73,6 +74,13 @@ def _assert_EOB_table_records_present(self, cnt):
7374
elements = self._find_elem_xpath(xpath)
7475
assert len(elements) == cnt
7576

77+
def _assert_EOB_table_error_present(self):
78+
element = self._find_and_return(30,
79+
By.CSS_SELECTOR,
80+
CSS_SEL_FE_ERR_MSG_CONTENT)
81+
assert element is not None
82+
print(element.text)
83+
7684
def _input_user_and_passwd_and_login(self):
7785
self._find_and_sendkey(30, By.ID, "username-textbox", "BBUser10000")
7886
self._find_and_sendkey(30, By.ID, "password-textbox", "PW10000!")
@@ -110,5 +118,26 @@ def test_node_sample_app_deny_access(self):
110118
self._input_user_and_passwd_and_login()
111119
self._find_and_click(30, By.ID, "deny")
112120
time.sleep(5)
113-
self._assert_EOB_table_header_present()
114-
self._assert_EOB_table_records_present(0)
121+
self._assert_EOB_table_error_present()
122+
123+
def test_node_sample_app_grant_followed_by_deny_access(self):
124+
'''
125+
this is to verify that the cached result from previous
126+
authorized eob query is clean up (should not see cached claims)
127+
'''
128+
self.driver.get("http://client:3000/")
129+
self.driver.set_window_size(1500, 1800)
130+
elem = self._find_and_click(30, By.ID, "auth_btn")
131+
assert elem is not None
132+
self._input_user_and_passwd_and_login()
133+
self._find_and_click(30, By.ID, "approve")
134+
time.sleep(5)
135+
self._assert_EOB_table_records_present(10)
136+
# go again
137+
elem = self._find_and_click(30, By.ID, "auth_btn")
138+
assert elem is not None
139+
self._input_user_and_passwd_and_login()
140+
self._find_and_click(30, By.ID, "deny")
141+
time.sleep(5)
142+
# should see error message
143+
self._assert_EOB_table_error_present()

server/Dockerfile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ LABEL description="Demo of a Medicare claims data sample app"
55

66
WORKDIR /server
77

8-
COPY ["./src/configs/sample_config.py", "./src/configs/config.py"]
9-
COPY ["./src/prestart/env/sandbox.sample.env","./src/prestart/env/development.env"]
8+
# COPY ["./src/configs/sample_config.py", "./src/configs/config.py"]
9+
# COPY ["./src/prestart/env/sandbox.sample.env","./src/prestart/env/development.env"]
1010

1111
COPY . .
1212

13-
RUN pip install pipenv
14-
RUN pip install debugpy
13+
RUN pip install pipenv debugpy ./cms_bluebutton_sdk-1.0.0-py3-none-any.whl
1514
RUN pipenv install --system --deploy --ignore-pipfile
1615

17-
ENV ENV "development"
16+
# ENV ENV "development"
1817

1918
EXPOSE 3001
2019

21-
CMD ["sh", "-c", "python -m debugpy --listen 0.0.0.0:5678 run.py --ENV ${ENV}"]
20+
CMD ["sh", "-c", "python -m debugpy --listen 0.0.0.0:5678 app.py"]

server/Pipfile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ name = "pypi"
55

66
[packages]
77
flask = "*"
8-
requests = "*"
9-
argparse = "*"
10-
requests-toolbelt = "*"
11-
python-dotenv = "*"
128

139
[dev-packages]
1410

0 commit comments

Comments
 (0)