Skip to content

Commit

Permalink
docs(samples): Update previous month logic to avoid zero-index bug in…
Browse files Browse the repository at this point in the history
… webhook_prebuilt_telecom sample (#479)

* fix: Update previous month logic to avoid zer-index bug

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
nicain and gcf-owl-bot[bot] authored Jan 6, 2023
1 parent 454a3c2 commit 22de71d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
1 change: 1 addition & 0 deletions Dialogflow-CX/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
google-cloud-dialogflow-cx==1.14.0
Flask==2.2.2
python-dateutil==2.8.2
11 changes: 7 additions & 4 deletions Dialogflow-CX/webhook_prebuilt_telecom.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ def cxPrebuiltAgentsTelecom(request):
# based on today's date
def get_date_details(bill_state):
from datetime import date
from dateutil.relativedelta import relativedelta

monthNames = [
"January",
Expand All @@ -280,13 +281,15 @@ def get_date_details(bill_state):
]
today = date.today()
# index starts with 0
first_month_name = monthNames[today.month - 1]
first_month_name = monthNames[(today.month - 1)]
firstDay = today.replace(day=1)
first_day_str = str(firstDay)

last_month_name = monthNames[today.month - 2]
last_month_first_day_str = str(today.replace(day=1, month=(today.month - 1)))
second_last_month_name = monthNames[today.month - 3]
last_month_name = monthNames[(today.month - 1) - 1]
last_month_first_day_str = str(
today.replace(day=1, month=(today - relativedelta(months=1)).month)
)
second_last_month_name = monthNames[(today.month - 1) - 2]
if bill_state == "current":
return [first_month_name, first_day_str, last_month_name]
else:
Expand Down
16 changes: 1 addition & 15 deletions Dialogflow-CX/webhook_prebuilt_telecom_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def test_detect_customeranomaly_current(app):

with app.test_request_context(json=request):
res = cxPrebuiltAgentsTelecom(flask.request)
print(res)
assert res["sessionInfo"]["parameters"]["anomaly_detect"] == "true"
assert res["sessionInfo"]["parameters"]["total_bill"] == 1054.34
assert res["sessionInfo"]["parameters"]["first_month"] == str(
Expand Down Expand Up @@ -73,12 +72,11 @@ def test_detect_customeranomaly_other(app):

with app.test_request_context(json=request):
res = cxPrebuiltAgentsTelecom(flask.request)
print(res)
today = date.today()
assert res["sessionInfo"]["parameters"]["anomaly_detect"] == "false"
assert res["sessionInfo"]["parameters"]["total_bill"] == 1054.34
assert res["sessionInfo"]["parameters"]["first_month"] == str(
today.replace(day=1, month=(today.month - 1))
today.replace(day=1, month=1 + ((today.month - 2) % 12))
)


Expand All @@ -98,7 +96,6 @@ def test_validate_phoneline(app):

with app.test_request_context(json=request):
res = cxPrebuiltAgentsTelecom(flask.request)
print(res)
assert res["sessionInfo"]["parameters"]["phone_line_verified"] == "true"


Expand All @@ -118,7 +115,6 @@ def test_invalid_phoneline(app):

with app.test_request_context(json=request):
res = cxPrebuiltAgentsTelecom(flask.request)
print(res)
assert res["sessionInfo"]["parameters"]["phone_line_verified"] == "false"


Expand All @@ -138,7 +134,6 @@ def test_invalid_phoneline2(app):

with app.test_request_context(json=request):
res = cxPrebuiltAgentsTelecom(flask.request)
print(res)
assert res["sessionInfo"]["parameters"]["domestic_coverage"] == "true"


Expand All @@ -156,7 +151,6 @@ def test_cruiseplan_coverage(app):

with app.test_request_context(json=request):
res = cxPrebuiltAgentsTelecom(flask.request)
print(res)
assert res["sessionInfo"]["parameters"]["port_is_covered"] == "true"


Expand All @@ -174,7 +168,6 @@ def test_cruiseplan_notcovered(app):

with app.test_request_context(json=request):
res = cxPrebuiltAgentsTelecom(flask.request)
print(res)
assert res["sessionInfo"]["parameters"]["port_is_covered"] == "false"


Expand All @@ -192,7 +185,6 @@ def test_international_coverage1(app):

with app.test_request_context(json=request):
res = cxPrebuiltAgentsTelecom(flask.request)
print(res)
assert res["sessionInfo"]["parameters"]["coverage"] == "both"


Expand All @@ -210,7 +202,6 @@ def test_international_coverage2(app):

with app.test_request_context(json=request):
res = cxPrebuiltAgentsTelecom(flask.request)
print(res)
assert res["sessionInfo"]["parameters"]["coverage"] == "monthly_only"


Expand All @@ -228,7 +219,6 @@ def test_international_coverage3(app):

with app.test_request_context(json=request):
res = cxPrebuiltAgentsTelecom(flask.request)
print(res)
assert res["sessionInfo"]["parameters"]["coverage"] == "neither"


Expand All @@ -246,7 +236,6 @@ def test_cheapest_plan1(app):

with app.test_request_context(json=request):
res = cxPrebuiltAgentsTelecom(flask.request)
print(res)
assert res["sessionInfo"]["parameters"]["monthly_cost"] == 70
assert res["sessionInfo"]["parameters"]["daily_cost"] == 400
assert res["sessionInfo"]["parameters"]["suggested_plan"] == "monthly"
Expand All @@ -266,7 +255,6 @@ def test_cheapest_plan2(app):

with app.test_request_context(json=request):
res = cxPrebuiltAgentsTelecom(flask.request)
print(res)
assert res["sessionInfo"]["parameters"]["monthly_cost"] == 70
assert res["sessionInfo"]["parameters"]["daily_cost"] == 200
assert res["sessionInfo"]["parameters"]["suggested_plan"] == "monthly"
Expand All @@ -286,7 +274,6 @@ def test_cheapest_plan3(app):

with app.test_request_context(json=request):
res = cxPrebuiltAgentsTelecom(flask.request)
print(res)
assert res["sessionInfo"]["parameters"]["monthly_cost"] == 70
assert res["sessionInfo"]["parameters"]["daily_cost"] == 50
assert res["sessionInfo"]["parameters"]["suggested_plan"] == "daily"
Expand All @@ -306,7 +293,6 @@ def test_cheapest_plan4(app):

with app.test_request_context(json=request):
res = cxPrebuiltAgentsTelecom(flask.request)
print(res)
assert res["sessionInfo"]["parameters"]["suggested_plan"] == "null"


Expand Down

0 comments on commit 22de71d

Please sign in to comment.