Skip to content

Commit 0ed02d2

Browse files
Merge branch 'develop' into btr-pr-template
2 parents ebcd3a3 + be1b130 commit 0ed02d2

File tree

8 files changed

+93
-5
lines changed

8 files changed

+93
-5
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ COPY setup.py .
77
COPY .streamlit .streamlit
88
COPY defaults defaults
99
COPY src src
10+
COPY st_app.py st_app.py
1011
RUN pip install -q .
1112

1213
CMD ["streamlit", "run", "st_app.py"]

habitat/hooks/run

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/sh
22
export HOME="/hab/svc/chime/config"
3+
# export the parameters file path
4+
export PARAMETERS="${pkg_prefix}/defaults/webapp.cfg"
35
cd "/hab/svc/chime"
46

57
if [ "$(whoami)" = "root" ]; then

habitat/plan.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ do_build() {
6767

6868
do_install() {
6969
cp -pr ${PLAN_CONTEXT}/../src/* "${pkg_prefix}/"
70+
cp -pr ${PLAN_CONTEXT}/../deafults/webapp.cfg "${pkg_prefix}/defaults/"
7071
return $?
7172
}
7273

src/chime_dash/app/services/plotting.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,8 @@ def plot_dataframe(
3333
}
3434
for col in dataframe.columns
3535
],
36-
"layout": {"yaxis": yaxis},
36+
"layout": {
37+
"yaxis": yaxis,
38+
"legend": {"orientation": "h"},
39+
},
3740
}

src/penn_chime/view/spreadsheet.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ def __init__(self, st_obj, secret):
77
# use creds to create a client to interact with the Google Drive API
88
self.scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
99
#secret = 'client_secret.json'
10-
self.creds = ServiceAccountCredentials.from_json(secret)
11-
#self.creds = ServiceAccountCredentials.from_json_keyfile_name(secret, self.scope)
10+
#self.creds = ServiceAccountCredentials.from_json_keyfile_dict(secret)
11+
self.creds = ServiceAccountCredentials.from_json_keyfile_name(secret, self.scope)
1212
self.client = gspread.authorize(self.creds)
1313

1414

src/penn_chime/view/st_display.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,15 @@ def subscribe(st_obj):
444444
affiliation = st_obj.text_input (label="Enter Affiliation", value="", key="na_upper_2")
445445
if st_obj.button (label="Submit", key="ta_submit_1"):
446446
row = [email, name, affiliation]
447-
send_subscription_to_google_sheet(st_obj, row)
447+
send_subscription_to_google_sheet_secret_json(st_obj, row)
448448

449-
def send_subscription_to_google_sheet(st_obj, row):
449+
def send_subscription_to_google_sheet_secret_json(st_obj, row):
450+
json_secret = "/mnt/google-api-creds/client_secret.json"
451+
#print(json_secret)
452+
spr = spreadsheet (st_obj, json_secret)
453+
spr.writeToSheet("CHIME Form Submissions", row)
454+
455+
def send_subscription_to_google_sheet_secret_dict(st_obj, row):
450456
json_secret = readGoogleApiSecretsDict()
451457
#print(json_secret)
452458
spr = spreadsheet(st_obj, json_secret)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
from unittest.mock import patch, MagicMock
2+
3+
import dash_core_components as dcc
4+
import dash_html_components as html
5+
import pytest
6+
from dash import Dash
7+
from dash.dependencies import Input, Output
8+
9+
from src.chime_dash.app.utils.callbacks import (
10+
ChimeCallback,
11+
register_callbacks,
12+
wrap_callbacks,
13+
)
14+
15+
16+
@pytest.mark.parametrize(
17+
"callbacks, new_callbacks, registered_callback_length",
18+
[
19+
([], [], 0),
20+
([], ["ChimeCallback1", "ChimeCallback2", "ChimeCallback3"], 3),
21+
(["ChimeCallback1"], ["ChimeCallback2", "ChimeCallback3"], 3),
22+
(["ChimeCallback1"], [], 1),
23+
],
24+
)
25+
def test_register_callbacks(
26+
callbacks, new_callbacks, registered_callback_length, monkeypatch
27+
):
28+
registered_callbacks = callbacks
29+
monkeypatch.setattr(
30+
"src.chime_dash.app.utils.callbacks.__registered_callbacks",
31+
registered_callbacks,
32+
)
33+
register_callbacks(new_callbacks)
34+
assert len(registered_callbacks) == registered_callback_length
35+
36+
37+
def test_wrap_callbacks(dash_app, monkeypatch):
38+
mock_chime_callback = MagicMock()
39+
monkeypatch.setattr(
40+
"src.chime_dash.app.utils.callbacks.__registered_callbacks",
41+
[mock_chime_callback],
42+
)
43+
wrap_callbacks(dash_app)
44+
mock_chime_callback.wrap.assert_called_once_with(dash_app)
45+
46+
47+
def test_ChimeCallback_wrap(dash_app):
48+
# set up the layout
49+
dash_app.layout = html.Div(
50+
id="root",
51+
children=[
52+
dcc.Input(id="input-id", value="initial value", type="text"),
53+
html.Div(id="output-id"),
54+
],
55+
)
56+
# create a callback for elements in this layout
57+
chime_callback = ChimeCallback(
58+
changed_elements={"input-id": "value"},
59+
callback_fn=lambda *args, **kwargs: ["new value"],
60+
dom_updates={"output-id": "children"},
61+
)
62+
63+
# register the Chime Callback with the layout
64+
chime_callback.wrap(dash_app)
65+
66+
assert list(dash_app.callback_map)[0] == "..output-id.children.."
67+
assert dash_app.callback_map["..output-id.children.."]["inputs"] == [
68+
{"id": "input-id", "property": "value"}
69+
]
70+
assert dash_app.callback_map["..output-id.children.."]["callback"]

tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from datetime import datetime
22

3+
from dash import Dash
34
import pytest
45
import pandas as pd
56

@@ -32,6 +33,10 @@ def just_store_instead_of_rendering(self, inp, *args, **kwargs):
3233
return None
3334

3435

36+
@pytest.fixture()
37+
def dash_app():
38+
return Dash()
39+
3540
@pytest.fixture
3641
def mock_st():
3742
return MockStreamlit()

0 commit comments

Comments
 (0)