def test_make_card(self): expected_card_dict = { "image": self.image.make_dict(), "formattedText": self.formattedText, } card = BasicCard(image=self.image, formattedText=self.formattedText) assert card.make_dict() == expected_card_dict
def setup_method(self): self.session_id = get_random_session_id() self.image = Image(url="http://testserver/img.png", accessibilityText="Hello World") self.card = BasicCard(image=self.image, formattedText="spam ham and eggs") self.result = {"spam": "eggs"}
def test_make_card_with_optionals(self): expected_card_dict = { "image": self.image.make_dict(), "formattedText": self.formattedText, "title": self.title, "subtitle": self.subtitle, } card = BasicCard( image=self.image, formattedText=self.formattedText, title=self.title, subtitle=self.subtitle, ) assert card.make_dict() == expected_card_dict
def setup_method(self): self.session_id = get_random_session_id() self.user = User(board=chess.Board(), color=chess.WHITE) self.result = {"foo": "bar"} self.image = Image(url="http://testserver/img.png", accessibilityText="Hello World") self.card = BasicCard(image=self.image, formattedText="spam ham and eggs")
def setup_method(self): self.session_id = get_random_session_id() self.result = {"foo": "bar"} self.engine_reply = "spam ham and eggs" self.image = Image(url="http://testserver/img.png", accessibilityText="Hello World") self.card = BasicCard(image=self.image, formattedText="spam ham and eggs") self.result_unfinished = None self.result_win = RESPONSES["result_win"] self.result_lose = RESPONSES["result_lose"] self.result_draw = RESPONSES["result_draw"]
def __init__(self, resp: Dict[str, Any]): items = resp["payload"]["google"]["richResponse"]["items"] self.simple_response = SimpleResponse.create( items[0]["simpleResponse"] ) self.simple_response_2 = None self.basic_card = None if len(items) > 1: for item in items: if item.get("simpleResponse"): if not self.simple_response_2: self.simple_response_2 = SimpleResponse.create( item["simpleResponse"] ) else: raise Exception( "There can be at most 2 simple responses in a rich" " response" ) if item.get("basicCard"): if self.basic_card is not None: raise Exception( "Only 1 basic card is allowed in one response" ) card_dict = item["basicCard"] if card_dict.get("image"): card_image_url = card_dict["image"].get("url") card_image_alt_text = card_dict["image"].get( "accessibilityText" ) card_image_width = card_dict["image"].get("width") card_image_height = card_dict["image"].get("height") card_image = Image( card_image_url, card_image_alt_text, card_image_width, card_image_height, ) else: card_image = None card_formatted_text = card_dict.get("formattedText") card_title = card_dict.get("title") card_subtitle = card_dict.get("subtitle") self.basic_card = BasicCard( card_image, card_formatted_text, card_title, card_subtitle, ) self.expect_user_response = resp["payload"]["google"][ "expectUserResponse" ] self.options_list = None if resp["payload"]["google"].get("systemIntent"): if ( resp["payload"]["google"]["systemIntent"]["intent"] == "actions.intent.OPTION" ): title = resp["payload"]["google"]["systemIntent"][ "listSelect" ].get("title") items = resp["payload"]["google"]["systemIntent"][ "listSelect" ]["items"] self.options_list = GoogleOptionsList(items, title)