Skip to content

Commit

Permalink
Merge branch 'develop': v 1.1.7. Add flags attr to meta, add and fi…
Browse files Browse the repository at this point in the history
…x tests
  • Loading branch information
mahenzon committed Sep 12, 2018
2 parents e285116 + e9e736a commit 028eae4
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 11 deletions.
2 changes: 1 addition & 1 deletion aioalice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())


__version__ = '1.1.6'
__version__ = '1.1.7'
1 change: 1 addition & 0 deletions aioalice/types/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ class Meta(AliceObject):
locale = attrib(type=str)
timezone = attrib(type=str)
client_id = attrib(type=str)
flags = attrib(factory=list)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
if sys.version_info < MINIMAL_PY_VERSION:
raise RuntimeError('aioAlice works only with Python {}+'.format('.'.join(map(str, MINIMAL_PY_VERSION))))

__version__ = '1.1.6'
__version__ = '1.1.7'


def get_description():
Expand Down
26 changes: 25 additions & 1 deletion tests/_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@
"title": CARD_TITLE,
"description": CARD_DESCR,
"button": deepcopy(MEDIA_BUTTON),
"footer": deepcopy(FOOTER)
}


Expand Down Expand Up @@ -202,3 +201,28 @@
"session": BASE_SESSION,
"version": "1.0"
}


DATA_FROM_STATION = {
'meta': {
'client_id': 'ru.yandex.quasar.services/1.0 (Yandex Station; android 6.0.1)',
'flags': [
'no_cards_support'
],
'locale': 'ru-RU',
'timezone': 'Europe/Moscow'
},
'request': {
'command': '',
'original_utterance': 'запусти навык qwerty',
'type': 'SimpleUtterance'
},
'session': {
'message_id': 0,
'new': True,
'session_id': '618709-bb99dd92-82c4f626-442a4',
'skill_id': '94d16-a32f-4932-9f5e-354d31f71998',
'user_id': 'CFC516B0EC123B86C78532BCEC1C33CBF05D54EF15C8001B52628EF49F580'
},
'version': '1.0'
}
22 changes: 14 additions & 8 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
EXPECTED_CARD_ITEMS_LIST_JSON, RESPONSE_TEXT, \
RESPONSE_BUTTON, \
EXPECTED_ALICE_RESPONSE_BIG_IMAGE_WITH_BUTTON, \
EXPECTED_ALICE_RESPONSE_ITEMS_LIST_WITH_BUTTON
EXPECTED_ALICE_RESPONSE_ITEMS_LIST_WITH_BUTTON, \
DATA_FROM_STATION


class TestAliceTypes(unittest.TestCase):
Expand All @@ -28,6 +29,8 @@ def _test_meta(self, meta, dct):
self.assertEqual(meta.locale, dct['locale'])
self.assertEqual(meta.timezone, dct['timezone'])
self.assertEqual(meta.client_id, dct['client_id'])
if 'flags' in dct:
self.assertEqual(meta.flags, dct['flags'])

def test_meta(self):
meta = types.Meta(**META)
Expand All @@ -44,7 +47,8 @@ def _test_request(self, req, dct):
self.assertEqual(req.command, dct['command'])
self.assertEqual(req.original_utterance, dct['original_utterance'])
self.assertEqual(req.type, dct['type'])
self.assertEqual(req.payload, dct['payload'])
if 'payload' in dct:
self.assertEqual(req.payload, dct['payload'])
if 'markup' in dct:
self._test_markup(req.markup, dct['markup'])

Expand Down Expand Up @@ -123,10 +127,15 @@ def _test_alice_request(self, arq, dct):
self._test_request(arq.request, dct['request'])
self._test_meta(arq.meta, dct['meta'])

def _test_alice_request_from_dct(self, dct):
alice_request = types.AliceRequest(**dct)
self._test_alice_request(alice_request, dct)

def test_alice_request(self):
alice_request = types.AliceRequest(**ALICE_REQUEST)
self.assertEqual(alice_request.to_json(), ALICE_REQUEST)
self._test_alice_request(alice_request, ALICE_REQUEST)
self._test_alice_request_from_dct(ALICE_REQUEST)

def test_alice_request_from_station(self):
self._test_alice_request_from_dct(DATA_FROM_STATION)

def _test_alice_response(self, arp, dct):
self.assertEqual(arp.version, dct['version'])
Expand Down Expand Up @@ -159,7 +168,6 @@ def test_response_big_image_from_request(self):
alice_response = alice_request.response_big_image(
RESPONSE_TEXT, IMAGE_ID, CARD_TITLE, CARD_DESCR,
types.MediaButton(BUTTON_TEXT, URL, MB_PAYLOAD),
types.CardFooter(FOOTER_TEXT, MEDIA_BUTTON),
buttons=[RESPONSE_BUTTON]
)
self._assert_payload(alice_response, EXPECTED_ALICE_RESPONSE_BIG_IMAGE_WITH_BUTTON)
Expand Down Expand Up @@ -225,15 +233,13 @@ def test_card_big_image(self):
title=CARD_TITLE,
description=CARD_DESCR,
button=types.MediaButton(BUTTON_TEXT, URL, MB_PAYLOAD),
footer=types.CardFooter(FOOTER_TEXT, MEDIA_BUTTON)
)
self._assert_payload(card_big_image, EXPECTED_CARD_BIG_IMAGE_JSON)

def test_card_big_image_card_method(self):
card_big_image = types.Card.big_image(
IMAGE_ID, CARD_TITLE, CARD_DESCR,
types.MediaButton(BUTTON_TEXT, URL, MB_PAYLOAD),
types.CardFooter(FOOTER_TEXT, MEDIA_BUTTON)
)
self._assert_payload(card_big_image, EXPECTED_CARD_BIG_IMAGE_JSON)

Expand Down

0 comments on commit 028eae4

Please sign in to comment.