Skip to content

Commit cd000e7

Browse files
committed
Updates to make new local stack run
1 parent 47dffd5 commit cd000e7

File tree

2 files changed

+71
-52
lines changed

2 files changed

+71
-52
lines changed

apps/testclient/management/commands/create_test_user_and_application.py

Lines changed: 70 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,38 +26,37 @@ def create_group(name="BlueButton"):
2626

2727
def create_user(group, usr):
2828
u_name = "fred"
29-
first_name = "Fred"
29+
first_name = "Fred"
3030
last_name = "Flinstone"
3131
3232
password = "foobarfoobarfoobar"
3333
user_type = "BEN"
34-
34+
3535
if usr is not None:
3636
u_name = usr
37-
first_name = "{}{}".format(usr, "First")
37+
first_name = "{}{}".format(usr, "First")
3838
last_name = "{}{}".format(usr, "Last")
3939
email = "{}.{}@example.com".format(first_name, last_name)
4040
user_type = "DEV"
4141

42-
4342
if User.objects.filter(username=u_name).exists():
4443
User.objects.filter(username=u_name).delete()
4544

4645
u = None
4746

4847
if usr is not None:
4948
u = User.objects.create_user(username=u_name,
50-
first_name=first_name,
51-
last_name=last_name,
52-
email=email)
49+
first_name=first_name,
50+
last_name=last_name,
51+
email=email)
5352
u.set_unusable_password()
5453
else:
5554
# create a sample user 'fred' for dev local that has a usable password
5655
u = User.objects.create_user(username=u_name,
57-
first_name=first_name,
58-
last_name=last_name,
59-
email=email,
60-
password=password,)
56+
first_name=first_name,
57+
last_name=last_name,
58+
email=email,
59+
password=password,)
6160

6261
UserProfile.objects.create(user=u,
6362
user_type=user_type,
@@ -72,29 +71,60 @@ def create_user(group, usr):
7271
u.groups.add(group)
7372

7473
if usr is None:
75-
c, g_o_c = Crosswalk.objects.get_or_create(user=u,
76-
fhir_id_v2=settings.DEFAULT_SAMPLE_FHIR_ID_V2,
77-
_user_id_hash="ee78989d1d9ba0b98f3cfbd52479f10c7631679c17563186f70fbef038cc9536")
74+
if not Crosswalk.objects.filter(_user_id_hash="ee78989d1d9ba0b98f3cfbd52479f10c7631679c17563186f70fbef038cc9536").exists():
75+
c, g_o_c = Crosswalk.objects.get_or_create(user=u,
76+
fhir_id_v2=settings.DEFAULT_SAMPLE_FHIR_ID_V2,
77+
_user_id_hash="ee78989d1d9ba0b98f3cfbd52479f10c7631679c17563186f70fbef038cc9536")
78+
else:
79+
print("Skipping crosswalk creation; already exists.")
7880
return u
7981

8082

81-
def create_application(user, group, app, redirect):
82-
app_name = "TestApp" if app is None else app
83-
Application.objects.filter(name=app_name).delete()
84-
redirect_uri = "{}{}".format(settings.HOSTNAME_URL, settings.TESTCLIENT_REDIRECT_URI)
83+
# def create_application(user, group, app, redirect):
84+
# app_name = "TestApp" if app is None else app
85+
# Application.objects.filter(name=app_name).delete()
86+
# redirect_uri = "{}{}".format(settings.HOSTNAME_URL, settings.TESTCLIENT_REDIRECT_URI)
87+
88+
# if redirect:
89+
# redirect_uri = redirect
90+
91+
# if not (redirect_uri.startswith("http://") or redirect_uri.startswith("https://")):
92+
# redirect_uri = "https://" + redirect_uri
93+
94+
# a = Application.objects.create(name=app_name,
95+
# redirect_uris=redirect_uri,
96+
# user=user,
97+
# data_access_type="THIRTEEN_MONTH",
98+
# client_type="confidential",
99+
# authorization_grant_type="authorization-code")
85100

86-
if redirect:
87-
redirect_uri = redirect
101+
# titles = ["My Medicare and supplemental coverage information.",
102+
# "My Medicare claim information.",
103+
# "My general patient and demographic information.",
104+
# "Profile information including name and email."
105+
# ]
88106

89-
if not(redirect_uri.startswith("http://") or redirect_uri.startswith("https://")):
90-
redirect_uri = "https://" + redirect_uri
107+
# for t in titles:
108+
# c = ProtectedCapability.objects.get(title=t)
109+
# a.scope.add(c)
110+
# return a
91111

92-
a = Application.objects.create(name=app_name,
93-
redirect_uris=redirect_uri,
94-
user=user,
95-
data_access_type="THIRTEEN_MONTH",
96-
client_type="confidential",
97-
authorization_grant_type="authorization-code")
112+
def create_application(user):
113+
app_name = "TestApp"
114+
if Application.objects.filter(name=app_name).exists():
115+
return Application.objects.get(name=app_name)
116+
117+
# If the app doesn't exist, create the test app.
118+
119+
Application.objects.filter(name=app_name).delete()
120+
redirect_uri = "{}{}".format(settings.HOSTNAME_URL, settings.TESTCLIENT_REDIRECT_URI)
121+
122+
the_app = Application.objects.create(name=app_name,
123+
redirect_uris=redirect_uri,
124+
user=user,
125+
data_access_type="THIRTEEN_MONTH",
126+
client_type="confidential",
127+
authorization_grant_type="authorization-code",)
98128

99129
titles = ["My Medicare and supplemental coverage information.",
100130
"My Medicare claim information.",
@@ -104,8 +134,9 @@ def create_application(user, group, app, redirect):
104134

105135
for t in titles:
106136
c = ProtectedCapability.objects.get(title=t)
107-
a.scope.add(c)
108-
return a
137+
the_app.scope.add(c)
138+
139+
return the_app
109140

110141

111142
def create_test_token(user, application):
@@ -118,10 +149,13 @@ def create_test_token(user, application):
118149
for s in scopes:
119150
scope.append(s.slug)
120151

121-
t = AccessToken.objects.create(user=user, application=application,
122-
token="sample-token-string",
123-
expires=expires,
124-
scope=' '.join(scope))
152+
if AccessToken.objects.filter(token="sample-token-string").exists():
153+
t = AccessToken.objects.get(token="sample-token-string")
154+
else:
155+
t = AccessToken.objects.create(user=user, application=application,
156+
token="sample-token-string",
157+
expires=expires,
158+
scope=' '.join(scope))
125159
return t
126160

127161

@@ -140,7 +174,7 @@ def handle(self, *args, **options):
140174

141175
g = create_group()
142176
u = create_user(g, usr)
143-
a = create_application(u, g, app, redirect)
177+
a = create_application(u) # a = create_application(u, g, app, redirect)
144178
t = None
145179
if usr is None and app is None:
146180
t = create_test_token(u, a)
@@ -149,4 +183,4 @@ def handle(self, *args, **options):
149183
print("client_id:", a.client_id)
150184
print("client_secret:", a.client_secret)
151185
print("access_token:", t.token if t else "None")
152-
print("redirect_uri:", a.redirect_uris)
186+
print("redirect_uri:", a.redirect_uris)

dev-local/utility-functions.bash

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,7 @@ check_valid_env () {
2424
echo "Exiting."
2525
return -2
2626
fi
27-
28-
29-
if [[ "${bfd}" == "local" && "${auth}" == "live" ]]; then
30-
echo "⚠️ ${bfd}/${auth} may work for SLSX testing, but not for BFD calls."
31-
fi
32-
33-
if [[ "${bfd}" == "test" && "${auth}" == "mock" ]]; then
34-
echo "${bfd}/${auth} is not a valid combination. Exiting."
35-
return -3
36-
fi
37-
38-
if [[ "${bfd}" == "sbx" && "${auth}" == "mock" ]]; then
39-
echo "${bfd}/${auth} is not a valid combination. Exiting."
40-
return -4
41-
fi
42-
27+
4328
echo "✅ check_valid_env"
4429
}
4530

0 commit comments

Comments
 (0)