Skip to content

Commit

Permalink
BB2-2818 Update batch create users and apps command
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharon Su committed Nov 30, 2023
1 parent 16ba198 commit e0468ca
Show file tree
Hide file tree
Showing 5 changed files with 30,042 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
'capability-a', 'capability-b']
APPLICATION_SCOPES_NON_DEMOGRAPHIC = ['patient/ExplanationOfBenefit.read',
'patient/Coverage.read', 'capability-a', 'capability-b']
DEFAULT_BENE_COUNT = 100
DEFAULT_DEV_COUNT = 150
DEFAULT_MAX_APPS_PER_DEV = 5


def create_group(name="BlueButton"):
Expand All @@ -44,9 +47,10 @@ def create_group(name="BlueButton"):
return g


def create_dev_users_apps_and_bene_crosswalks(group):
def create_dev_users_apps_and_bene_crosswalks(group, bene_count, dev_count, app_max):
#
# generate dev users dev0001 - dev1000, with password, email, security questions, etc.
# generate dev users dev0001, dev0002, dev0003 etc, with password, email, security questions, etc.
# Counts are based on the inputs, but if undefined,will default to the defaults defined above
# each dev user can have 1 to many applications: dev0001-app01, dev0001-app02
# generate crosswalk bene users with FHIR-ID. HICN-HASH, MBI-HASH etc
#
Expand Down Expand Up @@ -101,7 +105,7 @@ def create_dev_users_apps_and_bene_crosswalks(group):
synthetic_bene_cnt += 1
print(".", end="", flush=True)
time.sleep(.05)
if count > 100:
if count > bene_count:
break
bene_rif.close()
file_cnt += 1
Expand All @@ -111,10 +115,10 @@ def create_dev_users_apps_and_bene_crosswalks(group):

scope_all = ' '.join(APPLICATION_SCOPES_FULL)
scope_no_demo = ' '.join(APPLICATION_SCOPES_NON_DEMOGRAPHIC)
# create 100 dev users
# create dev users according dev-count parameter, default to 100
# generate access tokens + refresh tokens + archived tokens for random picked benes for each app
app_index = 0
for i in range(150):
for i in range(dev_count):
dev_u_fn = "DevUserFN{}".format(i)
dev_u_ln = "DevUserLN{}".format(i)
u = User.objects.create_user(username="{}.{}".format(dev_u_fn, dev_u_ln),
Expand All @@ -134,7 +138,7 @@ def create_dev_users_apps_and_bene_crosswalks(group):
password_reset_answer_3='Bentley')
u.groups.add(group)
# 1-5 apps per DEV user
app_cnt = randint(1, 5)
app_cnt = randint(1, app_max)
print(">>>>generating apps for user={}".format(u.username))
for i in range(app_cnt):
app_index += 1
Expand Down Expand Up @@ -267,8 +271,19 @@ class Command(BaseCommand):
' apps for each of them, create 30k bene users from s3 bucket '
'synthetic data and crosswalk for each bene.')

def add_arguments(self, parser):
parser.add_argument("-b", "--bene-count", default=DEFAULT_BENE_COUNT, help="Total number of bene to be created.")
parser.add_argument("-d", "--dev-count", default=DEFAULT_DEV_COUNT, help="Total number of devs to be created.")
parser.add_argument("-a", "--app-max", default=DEFAULT_MAX_APPS_PER_DEV, help="Maximum number of apps per dev.")

def handle(self, *args, **options):
bene_count = int(options["bene_count"])
dev_count = int(options["dev_count"])
app_max = int(options["app_max"])
g = create_group()
create_dev_users_apps_and_bene_crosswalks(g)
create_dev_users_apps_and_bene_crosswalks(g,
bene_count,
dev_count,
app_max)
# update grants
update_grants()
30 changes: 17 additions & 13 deletions docker-compose/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ docker-compose up -d
Or equivalently:

```
docker-compose up -d web
docker-compose up -d --profile web
```

To startup the Docker containerized BB2 server using msls:

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

To shutdown the Docker containerized BB2 server (this is needed when switching between SLSx and MSLS modes):
Expand Down Expand Up @@ -112,7 +112,7 @@ docker images # This should now show an empty list.
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:

```
source venv/bin/activate (unless already done)
source venv/Scripts/activate (unless already done)
pip install pre-commit
pre-commit install
```
Expand Down Expand Up @@ -218,30 +218,37 @@ Running migrations:
## Populate BB2 Django models with large number of records

Run migrate.sh will in turn execute a django command among other things:

```
python manage.py create_test_user_and_application
```

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

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
is a command to help with that:

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 is a command to help with that:
```
python manage.py create_test_users_and_applications_batch
```

which generates 50 dev users, each has 1-5 apps, and 30k bene users which have following relations:
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:
```
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>
```
These are also listed when specifying `--help` on the command.

The generated users and apps have the following relations:

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

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

<bb2_local_repo_base>/synthetic-data/

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

## Running tests from your host

Expand Down Expand Up @@ -282,7 +289,6 @@ convertion using the following command:

```
git config --global core.autocrlf true
```

in case, with above git core.autocrlf setting, some steps e.g. migrate.sh still chokes (file not found etc.),
Expand Down Expand Up @@ -358,14 +364,12 @@ Get Pateint FHIR Resource json

```
curl --header "Authorization: Bearer ${ACCESS_TOKEN}" "${HOST}/v1/fhir/Patient/${BENE_ID}"
```

Get ExplanationOfBenefit FHIR Resource json

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

## Developing and Running Integration Tests in Local Development
Expand Down
Loading

0 comments on commit e0468ca

Please sign in to comment.