Skip to content

Commit d708e3a

Browse files
code style pass
1 parent e2f94b4 commit d708e3a

File tree

1 file changed

+56
-56
lines changed

1 file changed

+56
-56
lines changed

apps/testclient/management/commands/create_test_users_and_applications_batch.py

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@
3939
DEFAULT_MAX_APPS_PER_DEV = 5
4040

4141

42-
def create_group(name="BlueButton"):
42+
def create_group(name='BlueButton'):
4343

4444
g, created = Group.objects.get_or_create(name=name)
4545
if created:
46-
print("%s group created" % (name))
46+
print('%s group created' % (name))
4747
else:
48-
print("%s group pre-existing. Create skipped." % (name))
48+
print('%s group pre-existing. Create skipped.' % (name))
4949
return g
5050

5151
# To avoid naming collisions when running this command more than once
@@ -84,10 +84,10 @@ def create_dev_users_apps_and_bene_crosswalks(
8484
count = 0
8585
file_cnt = 0
8686
synthetic_bene_cnt = 0
87-
begin_number = get_first_available_number("bene")
87+
begin_number = get_first_available_number('bene')
8888

8989
for f in files:
90-
print("file={}".format(f))
90+
print('file={}'.format(f))
9191
bene_rif = open('./synthetic-data/{}'.format(f), 'r')
9292
while True:
9393
if count == bene_count:
@@ -102,8 +102,8 @@ def create_dev_users_apps_and_bene_crosswalks(
102102
fhir_id = flds[1]
103103
mbi = flds[14]
104104
hicn = flds[18]
105-
fn = "bene{}".format(count + begin_number)
106-
ln = "user{}".format(count + begin_number)
105+
fn = 'bene{}'.format(count + begin_number)
106+
ln = 'user{}'.format(count + begin_number)
107107

108108
# skip fred
109109
if fhir_id != '-20140000008325':
@@ -129,34 +129,34 @@ def create_dev_users_apps_and_bene_crosswalks(
129129
bene_pk_list.append(u.pk)
130130
synthetic_bene_cnt += 1
131131
count += 1
132-
print(".", end="", flush=True)
132+
print('.', end='', flush=True)
133133
time.sleep(.05)
134134
except ValidationError:
135135
# If there is something wrong during 'create_beneficiary_record'
136136
# i.e. 'user already exists', just try the next .rif record
137137
continue
138138
bene_rif.close()
139139
file_cnt += 1
140-
print("RIF file processed = {}, synthetic bene generated = {}".format(file_cnt, synthetic_bene_cnt))
140+
print('RIF file processed = {}, synthetic bene generated = {}'.format(file_cnt, synthetic_bene_cnt))
141141
if file_cnt >= 1:
142142
break
143143

144144
# create dev users according dev-count parameter, default to 100
145145
# generate access tokens + refresh tokens + archived tokens for random picked benes for each app
146146
app_index = 0
147-
begin_number = get_first_available_number("DevUserFN")
147+
begin_number = get_first_available_number('DevUserFN')
148148
for i in range(dev_count):
149-
dev_u_fn = "DevUserFN{}".format(i + begin_number)
150-
dev_u_ln = "DevUserLN{}".format(i + begin_number)
151-
u = User.objects.create_user(username="{}.{}".format(dev_u_fn, dev_u_ln),
149+
dev_u_fn = 'DevUserFN{}'.format(i + begin_number)
150+
dev_u_ln = 'DevUserLN{}'.format(i + begin_number)
151+
u = User.objects.create_user(username='{}.{}'.format(dev_u_fn, dev_u_ln),
152152
first_name=dev_u_fn,
153153
last_name=dev_u_ln,
154154
email='{}.{}@example.com'.format(dev_u_fn, dev_u_ln),
155-
password="THEP@ssw0rd{}".format(i),)
155+
password='THEP@ssw0rd{}'.format(i),)
156156
UserProfile.objects.create(user=u,
157-
user_type="DEV",
157+
user_type='DEV',
158158
create_applications=True,
159-
organization_name=u.username + "ACME Inc.",
159+
organization_name=u.username + 'ACME Inc.',
160160
password_reset_question_1='1',
161161
password_reset_answer_1='blue',
162162
password_reset_question_2='2',
@@ -166,22 +166,22 @@ def create_dev_users_apps_and_bene_crosswalks(
166166
u.groups.add(group)
167167
# apps per DEV user
168168
app_cnt = randint(1, app_max) if app_max > 0 else 0
169-
print(">>>>generating apps for user={}".format(u.username))
169+
print('>>>>generating apps for user={}'.format(u.username))
170170
for i in range(app_cnt):
171171
app_index += 1
172-
app_name = "app{}_{}".format(i, u)
173-
redirect_uri = "{}/testclient_{}/callback".format(settings.HOSTNAME_URL, app_name)
174-
if not(redirect_uri.startswith("http://") or redirect_uri.startswith("https://")):
175-
redirect_uri = "https://" + redirect_uri
172+
app_name = 'app{}_{}'.format(i, u)
173+
redirect_uri = '{}/testclient_{}/callback'.format(settings.HOSTNAME_URL, app_name)
174+
if not(redirect_uri.startswith('http://') or redirect_uri.startswith('https://')):
175+
redirect_uri = 'https://' + redirect_uri
176176
# 2% inactive, 5% opt out demo scopes
177177
# 10% public/implicit 90% confidential/authorization-code
178178

179-
cl_type = "confidential"
180-
auth_grant_type = "authorization-code"
179+
cl_type = 'confidential'
180+
auth_grant_type = 'authorization-code'
181181

182182
if app_index % 10 == 0:
183-
cl_type = "public"
184-
auth_grant_type = "implicit"
183+
cl_type = 'public'
184+
auth_grant_type = 'implicit'
185185

186186
a = Application.objects.create(name=app_name,
187187
redirect_uris=redirect_uri,
@@ -196,16 +196,16 @@ def create_dev_users_apps_and_bene_crosswalks(
196196
u.save()
197197
a.save()
198198
titles = [
199-
"My Medicare and supplemental coverage information.",
200-
"My Medicare claim information.",
201-
"My general patient and demographic information.",
202-
"Profile information including name and email."
199+
'My Medicare and supplemental coverage information.',
200+
'My Medicare claim information.',
201+
'My general patient and demographic information.',
202+
'Profile information including name and email.'
203203
]
204204

205205
for t in titles:
206206
c = ProtectedCapability.objects.get(title=t)
207207
a.scope.add(c)
208-
print("<<<<<generated apps for user={}".format(u.username))
208+
print('<<<<<generated apps for user={}'.format(u.username))
209209

210210
# go through benes: each bene sign up to 1, 2, 3 apps
211211
# most 70% 1 app, 25% 2 apps, 5% 3 apps
@@ -274,14 +274,14 @@ def create_test_access_refresh_archived_objects(
274274
scope=scope)
275275
at.created = date_created.replace(tzinfo=pytz.utc)
276276
at.save()
277-
print("<<< access token created for " + user.username + "/" + application.name)
277+
print('<<< access token created for ' + user.username + '/' + application.name)
278278

279279
for i in range(refresh_count):
280280
rt = RefreshToken.objects.create(user=user, application=application,
281281
token=uuid.uuid4().hex)
282282
rt.created = at.created
283283
rt.save()
284-
print("<<< " + user.username + " refresh token " + str(i) + " generated")
284+
print('<<< ' + user.username + ' refresh token ' + str(i) + ' generated')
285285

286286
# archived token: created, updated, archived_at datetime fields
287287
for i in range(archived_token_count):
@@ -297,7 +297,7 @@ def create_test_access_refresh_archived_objects(
297297
date_archived = ot.created + timedelta(days=10)
298298
ot.archived_at = date_archived.replace(tzinfo=pytz.utc)
299299
ot.save()
300-
print("<<< " + user.username + " archived token " + str(i) + " generated")
300+
print('<<< ' + user.username + ' archived token ' + str(i) + ' generated')
301301

302302
past_date = timezone.now() - timedelta(days=2)
303303
for i in range(archived_grant_count):
@@ -308,7 +308,7 @@ def create_test_access_refresh_archived_objects(
308308
archived_at=past_date)
309309
past_date = past_date - timedelta(days=2)
310310
adag.save()
311-
print("<<< " + user.username + "archived grant " + str(i) + " generated")
311+
print('<<< ' + user.username + 'archived grant ' + str(i) + ' generated')
312312

313313

314314
class Command(BaseCommand):
@@ -317,30 +317,30 @@ class Command(BaseCommand):
317317
'synthetic data and crosswalk for each bene.')
318318

319319
def add_arguments(self, parser):
320-
parser.add_argument("-b", "--bene-count", default=DEFAULT_BENE_COUNT,
321-
help="Total number of bene to be created. "
322-
"If none, defaults to {}.".format(DEFAULT_BENE_COUNT))
323-
parser.add_argument("-d", "--dev-count", default=DEFAULT_DEV_COUNT,
324-
help="Total number of devs to be created. "
325-
"If none, defaults to {}.". format(DEFAULT_DEV_COUNT))
326-
parser.add_argument("-a", "--app-max", default=DEFAULT_MAX_APPS_PER_DEV,
327-
help="Maximum number of apps per dev. "
328-
"If none, defaults to {}.".format(DEFAULT_MAX_APPS_PER_DEV))
329-
parser.add_argument("-r", "--refresh-tokens", default=1,
330-
help="Refresh tokens per bene user. If none, defaults to 1.")
331-
parser.add_argument("-t", "--archived-tokens", default=1,
332-
help="Archived tokens per bene user. If none, defaults to 1.")
333-
parser.add_argument("-g", "--archived-access-grants", default=0,
334-
help="Archived access grants per user/app combination. "
335-
"If none, defaults to 0.")
320+
parser.add_argument('-b', '--bene-count', default=DEFAULT_BENE_COUNT,
321+
help='Total number of bene to be created. '
322+
'If none, defaults to {}.'.format(DEFAULT_BENE_COUNT))
323+
parser.add_argument('-d', '--dev-count', default=DEFAULT_DEV_COUNT,
324+
help='Total number of devs to be created. '
325+
'If none, defaults to {}.'. format(DEFAULT_DEV_COUNT))
326+
parser.add_argument('-a', '--app-max', default=DEFAULT_MAX_APPS_PER_DEV,
327+
help='Maximum number of apps per dev. '
328+
'If none, defaults to {}.'.format(DEFAULT_MAX_APPS_PER_DEV))
329+
parser.add_argument('-r', '--refresh-tokens', default=1,
330+
help='Refresh tokens per bene user. If none, defaults to 1.')
331+
parser.add_argument('-t', '--archived-tokens', default=1,
332+
help='Archived tokens per bene user. If none, defaults to 1.')
333+
parser.add_argument('-g', '--archived-access-grants', default=0,
334+
help='Archived access grants per user/app combination. '
335+
'If none, defaults to 0.')
336336

337337
def handle(self, *args, **options):
338-
bene_count = int(options["bene_count"])
339-
dev_count = int(options["dev_count"])
340-
app_max = int(options["app_max"])
341-
refresh_tokens = int(options["refresh_tokens"])
342-
archived_tokens = int(options["archived_tokens"])
343-
archived_grants = int(options["archived_access_grants"])
338+
bene_count = int(options['bene_count'])
339+
dev_count = int(options['dev_count'])
340+
app_max = int(options['app_max'])
341+
refresh_tokens = int(options['refresh_tokens'])
342+
archived_tokens = int(options['archived_tokens'])
343+
archived_grants = int(options['archived_access_grants'])
344344
g = create_group()
345345
create_dev_users_apps_and_bene_crosswalks(
346346
g,

0 commit comments

Comments
 (0)