Skip to content

Commit

Permalink
feat: Сборка окончания связки аккаунтов
Browse files Browse the repository at this point in the history
  • Loading branch information
KrapivinAndrey committed May 4, 2022
1 parent 61e7f8a commit 2ee70c4
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 20 deletions.
59 changes: 39 additions & 20 deletions alicefluentcheck/AliceRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(
self._state_application = {}
self._interfaces = {}
self._access_token = None
self._account_linking_complete_event = False
if has_screen:
self._interfaces["screen"] = {}
if has_payments:
Expand Down Expand Up @@ -80,6 +81,10 @@ def add_to_state_application(self, name: str, value):
def from_scene(self, scene: str):
self.add_to_state_session("scene", scene)

@chained
def account_linking_complete(self):
self._account_linking_complete_event = True

def build(self):
def meta():
return {
Expand All @@ -104,25 +109,39 @@ def session(new=False):

return temp

req = {
"meta": meta(),
"session": session(self._new_session),
"request": {
"command": self._command,
"original_utterance": self._original_utterance,
"nlu": {
"tokens": self._nlu_tokens,
"entities": self._entities,
"intents": self._intents,
if self._account_linking_complete_event:
req = {
"meta": meta(),
"session": session(self._new_session),
"account_linking_complete_event": {},
"version": "1.0",
"state": {
"session": self._state_sessions,
"user": self._state_user,
"applications": self._state_application,
},
"markup": {"dangerous_context": False},
"type": "SimpleUtterance",
},
"version": "1.0",
"state": {
"session": self._state_sessions,
"user": self._state_user,
"applications": self._state_application,
},
}
}

else:
req = {
"meta": meta(),
"session": session(self._new_session),
"request": {
"command": self._command,
"original_utterance": self._original_utterance,
"nlu": {
"tokens": self._nlu_tokens,
"entities": self._entities,
"intents": self._intents,
},
"markup": {"dangerous_context": False},
"type": "SimpleUtterance",
},
"version": "1.0",
"state": {
"session": self._state_sessions,
"user": self._state_user,
"applications": self._state_application,
},
}
return req
28 changes: 28 additions & 0 deletions tests/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,34 @@ def test_create_token(self):
}
assert test == control

def test_acount_link(self):
test = AliceRequest().account_linking_complete().access_token("000").build()
control = {
"meta": {
"locale": "ru-RU",
"timezone": "UTC",
"client_id": "AliceMock",
"interfaces": {},
},
"session": {
"message_id": 3,
"session_id": "d825cbef-e7d6-4af9-9810-3ff3f358ac16",
"skill_id": "3308dc06-b901-4f7e-8882-beb1b84c0753",
"user": {"user_id": "000", "access_token": "000"},
"application": {"application_id": "000"},
"user_id": "000",
"new": False,
},
"account_linking_complete_event": {},
"version": "1.0",
"state": {
"session": {},
"user": {},
"applications": {},
},
}
assert test == control

def test_add_entity(self):
fio = AliceEntity().fio("Фамилия", "Имя", "Отчество")
test = AliceRequest().command("Фамилия Имя Отчество").add_entity(fio).build()
Expand Down

0 comments on commit 2ee70c4

Please sign in to comment.