Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions users/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,12 @@ def test_session_started(self, mock_country_code, client):

response = client.post(
reverse("start_device_configuration"),
data={"phone_number": phone_number, "gps_location": gps_location, "cc_device_id": "device_id"},
data={
"phone_number": phone_number,
"gps_location": gps_location,
"cc_device_id": "device_id",
"include_toggles": True,
},
HTTP_CC_INTEGRITY_TOKEN="token",
HTTP_CC_REQUEST_HASH="hash",
)
Expand All @@ -1200,6 +1205,7 @@ def test_session_started(self, mock_country_code, client):
assert session.gps_location == gps_location
assert not session.is_phone_validated
assert session.device_id == "device_id"
assert "toggles" in response.json()

@skip_app_integrity_check
@patch("users.models.ConfigurationSession.country_code", new_callable=PropertyMock)
Expand All @@ -1215,10 +1221,11 @@ def test_can_start_multiple_sessions(self, mock_country_code, client):
assert response.status_code == 200
token1 = response.json().get("token")
session1 = ConfigurationSession.objects.get(key=token1)
assert "toggles" not in response.json()

response = client.post(
reverse("start_device_configuration"),
data={"phone_number": phone_number, "gps_location": "0 0"},
data={"phone_number": phone_number, "gps_location": "0 0", "include_toggles": True},
HTTP_CC_INTEGRITY_TOKEN="token",
HTTP_CC_REQUEST_HASH="hash",
)
Expand All @@ -1228,6 +1235,7 @@ def test_can_start_multiple_sessions(self, mock_country_code, client):

assert session1.key != session2.key
assert session1.phone_number == session2.phone_number
assert "toggles" in response.json()

@skip_app_integrity_check
@patch("users.models.ConfigurationSession.country_code", new_callable=PropertyMock)
Expand Down
3 changes: 3 additions & 0 deletions users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from oauth2_provider.views.mixins import ClientProtectedResourceMixin
from rest_framework.decorators import api_view, authentication_classes, permission_classes
from rest_framework.views import APIView
from waffle.models import Switch

from services.ai.ocs import OpenChatStudio
from utils import get_ip, get_sms_sender, send_sms
Expand Down Expand Up @@ -112,6 +113,8 @@ def start_device_configuration(request):
"demo_user": is_demo_user,
"token": token_session.key,
}
if data.get("include_toggles", False):
response_data["toggles"] = {s.name: s.active for s in Switch.objects.all()}

if request.version == settings.API_VERSION.V1:
response_data["sms_method"] = SMSMethods.PERSONAL_ID if request.invited_user else SMSMethods.FIREBASE
Expand Down