Skip to content

Commit 3e9e635

Browse files
authored
BB2-2818 Update batch create users and apps command (#1149)
1 parent 6f223fa commit 3e9e635

File tree

5 files changed

+30053
-27
lines changed

5 files changed

+30053
-27
lines changed

apps/testclient/management/commands/create_test_users_and_applications_batch.py

+22-7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
'capability-a', 'capability-b']
3333
APPLICATION_SCOPES_NON_DEMOGRAPHIC = ['patient/ExplanationOfBenefit.read',
3434
'patient/Coverage.read', 'capability-a', 'capability-b']
35+
DEFAULT_BENE_COUNT = 100
36+
DEFAULT_DEV_COUNT = 150
37+
DEFAULT_MAX_APPS_PER_DEV = 5
3538

3639

3740
def create_group(name="BlueButton"):
@@ -44,9 +47,10 @@ def create_group(name="BlueButton"):
4447
return g
4548

4649

47-
def create_dev_users_apps_and_bene_crosswalks(group):
50+
def create_dev_users_apps_and_bene_crosswalks(group, bene_count, dev_count, app_max):
4851
#
49-
# generate dev users dev0001 - dev1000, with password, email, security questions, etc.
52+
# generate dev users dev0001, dev0002, dev0003 etc, with password, email, security questions, etc.
53+
# Counts are based on the inputs, but if undefined,will default to the defaults defined above
5054
# each dev user can have 1 to many applications: dev0001-app01, dev0001-app02
5155
# generate crosswalk bene users with FHIR-ID. HICN-HASH, MBI-HASH etc
5256
#
@@ -101,7 +105,7 @@ def create_dev_users_apps_and_bene_crosswalks(group):
101105
synthetic_bene_cnt += 1
102106
print(".", end="", flush=True)
103107
time.sleep(.05)
104-
if count > 100:
108+
if count > bene_count:
105109
break
106110
bene_rif.close()
107111
file_cnt += 1
@@ -111,10 +115,10 @@ def create_dev_users_apps_and_bene_crosswalks(group):
111115

112116
scope_all = ' '.join(APPLICATION_SCOPES_FULL)
113117
scope_no_demo = ' '.join(APPLICATION_SCOPES_NON_DEMOGRAPHIC)
114-
# create 100 dev users
118+
# create dev users according dev-count parameter, default to 100
115119
# generate access tokens + refresh tokens + archived tokens for random picked benes for each app
116120
app_index = 0
117-
for i in range(150):
121+
for i in range(dev_count):
118122
dev_u_fn = "DevUserFN{}".format(i)
119123
dev_u_ln = "DevUserLN{}".format(i)
120124
u = User.objects.create_user(username="{}.{}".format(dev_u_fn, dev_u_ln),
@@ -134,7 +138,7 @@ def create_dev_users_apps_and_bene_crosswalks(group):
134138
password_reset_answer_3='Bentley')
135139
u.groups.add(group)
136140
# 1-5 apps per DEV user
137-
app_cnt = randint(1, 5)
141+
app_cnt = randint(1, app_max)
138142
print(">>>>generating apps for user={}".format(u.username))
139143
for i in range(app_cnt):
140144
app_index += 1
@@ -267,8 +271,19 @@ class Command(BaseCommand):
267271
' apps for each of them, create 30k bene users from s3 bucket '
268272
'synthetic data and crosswalk for each bene.')
269273

274+
def add_arguments(self, parser):
275+
parser.add_argument("-b", "--bene-count", default=DEFAULT_BENE_COUNT, help="Total number of bene to be created.")
276+
parser.add_argument("-d", "--dev-count", default=DEFAULT_DEV_COUNT, help="Total number of devs to be created.")
277+
parser.add_argument("-a", "--app-max", default=DEFAULT_MAX_APPS_PER_DEV, help="Maximum number of apps per dev.")
278+
270279
def handle(self, *args, **options):
280+
bene_count = int(options["bene_count"])
281+
dev_count = int(options["dev_count"])
282+
app_max = int(options["app_max"])
271283
g = create_group()
272-
create_dev_users_apps_and_bene_crosswalks(g)
284+
create_dev_users_apps_and_bene_crosswalks(g,
285+
bene_count,
286+
dev_count,
287+
app_max)
273288
# update grants
274289
update_grants()

docker-compose/readme.md

+28-20
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ docker-compose up -d
7171
Or equivalently:
7272

7373
```
74-
docker-compose up -d web
74+
docker-compose --profile web up -d
7575
```
7676

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

7979
```
80-
docker-compose up -d web_msls
80+
docker-compose --profile web_msls up -d
8181
```
8282

8383
To shutdown the Docker containerized BB2 server (this is needed when switching between SLSx and MSLS modes):
@@ -112,7 +112,7 @@ docker images # This should now show an empty list.
112112
Precommit config has been setup inside the repo which will make sure that the code is properly formatted prior to commiting. To setup run as follows:
113113

114114
```
115-
source venv/bin/activate (unless already done)
115+
source venv/Scripts/activate (unless already done)
116116
pip install pre-commit
117117
pre-commit install
118118
```
@@ -218,30 +218,37 @@ Running migrations:
218218
## Populate BB2 Django models with large number of records
219219

220220
Run migrate.sh will in turn execute a django command among other things:
221-
221+
```
222222
python manage.py create_test_user_and_application
223+
```
223224

224225
this will populate BB2 Django models User, UserProfile, Application, Crosswalk, AccessToken with:
225226

226-
one user 'fred', one app 'TestApp', one access token, and one corresponding crosswalk entry, which can be used for minimum test, for local tests that require large number of users, applications, etc. there
227-
is a command to help with that:
228-
227+
one user 'fred', one app 'TestApp', one access token, and one corresponding crosswalk entry, which can be used for minimum test, for local tests that require large number of users, applications, etc.
228+
There is a command to help with that:
229+
```
229230
python manage.py create_test_users_and_applications_batch
231+
```
232+
233+
which by default, generates 150 dev users, each having 1-5 apps, and 100 bene users. To change the number of users and apps generated, use the `-d`, `-a` and `-b` flags:
234+
```
235+
python manage.py create_test_users_and_applications_batch -d <number of dev users> -b <number of bene users> -a <maximum number of apps per dev user>
236+
```
237+
These are also listed when specifying `--help` on the command.
230238

231-
which generates 50 dev users, each has 1-5 apps, and 30k bene users which have following relations:
239+
The generated users and apps have the following relations:
232240

233241
1. dev users and apps created date are spread over past 700 days randomly
234242
2. each bene sign up (grant access) with 1-3 apps by aproximately: 70% 1 app, 25% 2 apps, 5% 3 apps and
235243
3. among these sign up (access token grants): 80% with demographic scopes, 20% deny demo access
236244
4. benes sign up dates are randomized and set to a date approximately 10 days after apps created date
237245
5. apps' client type, grant type, opt in/out of demographic info access are also randomly generated per a percent distribution
238246

239-
the data generation command assumes that the 30k synthetic beneficiary records in rif files are present
247+
The data generation command assumes that the number of synthetic beneficiary records desired are in the rif files
240248
under BB2 local repo base directory:
241249

242250
<bb2_local_repo_base>/synthetic-data/
243251

244-
for detailed info about the synthetic data and how to fetch them, refer to: https://github.com/CMSgov/beneficiary-fhir-data/blob/master/apps/bfd-model/bfd-model-rif-samples/dev/design-sample-data-sets.md
245252

246253
## Running tests from your host
247254

@@ -282,7 +289,6 @@ convertion using the following command:
282289

283290
```
284291
git config --global core.autocrlf true
285-
286292
```
287293

288294
in case, with above git core.autocrlf setting, some steps e.g. migrate.sh still chokes (file not found etc.),
@@ -354,18 +360,16 @@ export HOST="http://localhost:8000"
354360
355361
```
356362

357-
Get Pateint FHIR Resource json
363+
Get Patient FHIR Resource json
358364

359365
```
360366
curl --header "Authorization: Bearer ${ACCESS_TOKEN}" "${HOST}/v1/fhir/Patient/${BENE_ID}"
361-
362367
```
363368

364369
Get ExplanationOfBenefit FHIR Resource json
365370

366371
```
367372
curl -k -v --header "Authorization: Bearer ${ACCESS_TOKEN}" "${HOST}/v1/fhir/ExplanationOfBenefit/?Patient=${BENE_ID}"
368-
369373
```
370374

371375
## Developing and Running Integration Tests in Local Development
@@ -483,10 +487,14 @@ You can run selenium tests against a local bb2 server by following below steps:
483487

484488
You can run selenium tests against a remote bb2 server by following below steps:
485489

486-
1. From the base directory of the local repo run:
487-
2. ./docker-compose/run_selenium_tests_remote.sh SBX (run selenium tests against bb2 server on SBX)
488-
3. ./docker-compose/run_selenium_tests_remote.sh -d SBX (run selenium tests in debug against bb2 server on SBX)
489-
4. the argument can be the remote ENV's name, it can also be the URL alternatively
490-
5. ./docker-compose/run_selenium_tests_remote.sh https://sandbox.bluebutton.cms.gov/
491-
6. ./docker-compose/run_selenium_tests_remote.sh -d https://sandbox.bluebutton.cms.gov/
490+
From the base directory of the local repo run:
491+
```
492+
./docker-compose/run_selenium_tests_remote.sh SBX (run selenium tests against bb2 server on SBX)
493+
./docker-compose/run_selenium_tests_remote.sh -d SBX (run selenium tests in debug against bb2 server on SBX)
494+
```
495+
The argument can be the remote ENV's name, it can also be the URL alternatively:
496+
```
497+
./docker-compose/run_selenium_tests_remote.sh https://sandbox.bluebutton.cms.gov/
498+
./docker-compose/run_selenium_tests_remote.sh -d https://sandbox.bluebutton.cms.gov/
499+
```
492500

0 commit comments

Comments
 (0)