def test_offset_bad_datatype(self, mock):
     result = 80
     try:
         result = generate_helpstring_result(ALIASES, "", "", 0, "bad")
     except TypeError:
         pass
     self.assertEqual(result, 80)
 def test_limit_in_bounds(self, mock):
     result = generate_helpstring_result(ALIASES, "", "the80s", 3)
     self.check_data_structure(result)
     self.check_available_count(result, 10)
     the80s = [line for line in result.get("helpstrings") if line['pack'] == "the80s"]
     self.assertEqual(len(the80s), 3)
     self.assertEqual(the80s[0].get("display"), "Come with me if you want to live")
 def test_filtering_bad_dataype(self, mock):
     result = 80
     try:
         result = generate_helpstring_result(ALIASES, 44)
     except TypeError:
         pass
     self.assertEqual(result, 80)
 def test_offset_negative_out_of_bounds(self, mock):
     result = generate_helpstring_result(ALIASES, "", "the80s", 0, -1)
     self.check_data_structure(result)
     self.check_available_count(result, 10)
     the80s = [line for line in result.get("helpstrings") if line['pack'] == "the80s"]
     self.assertEqual(len(the80s), 10)
     self.assertEqual(the80s[0].get("display"), "Come with me if you want to live")
 def test_offset_in_bounds(self, mock):
     result = generate_helpstring_result(ALIASES, "", "the80s", 0, 6)
     self.check_data_structure(result)
     self.check_available_count(result, 10)
     the80s = result.get("helpstrings").get("the80s")
     self.assertEqual(len(the80s), 4)
     self.assertEqual(the80s[0].get("display"), "He's just like his {{relation}}.")
 def test_filtering_no_arg(self, mock):
     result = generate_helpstring_result(ALIASES)
     self.check_data_structure(result)
     self.check_available_count(result, 10)
     the80s = result.get("helpstrings").get("the80s")
     self.assertEqual(len(the80s), 10)
     self.assertEqual(the80s[0].get("display"), "Come with me if you want to live")
 def test_offset_negative_out_of_bounds(self, mock):
     result = generate_helpstring_result(ALIASES, "", "the80s", 0, -1)
     self.check_data_structure(result)
     self.check_available_count(result, 10)
     the80s = result.get("helpstrings").get("the80s")
     self.assertEqual(len(the80s), 10)
     self.assertEqual(the80s[0].get("display"), "Come with me if you want to live")
 def test_offset_in_bounds(self, mock):
     result = generate_helpstring_result(ALIASES, "", "the80s", 0, 6)
     self.check_data_structure(result)
     self.check_available_count(result, 10)
     the80s = [line for line in result.get("helpstrings") if line['pack'] == "the80s"]
     self.assertEqual(len(the80s), 4)
     self.assertEqual(the80s[0].get("display"), "He's just like his {{relation}}.")
 def test_offset_bad_datatype(self, mock):
     result = 80
     try:
         result = generate_helpstring_result(ALIASES, "", "", 0, "bad")
     except TypeError:
         pass
     self.assertEqual(result, 80)
 def test_filtering_no_arg(self, mock):
     result = generate_helpstring_result(ALIASES)
     self.check_data_structure(result)
     self.check_available_count(result, 10)
     the80s = [line for line in result.get("helpstrings") if line['pack'] == "the80s"]
     self.assertEqual(len(the80s), 10)
     self.assertEqual(the80s[0].get("display"), "Come with me if you want to live")
 def test_filtering_bad_dataype(self, mock):
     result = 80
     try:
         result = generate_helpstring_result(ALIASES, 44)
     except TypeError:
         pass
     self.assertEqual(result, 80)
 def test_filtering_match(self, mock):
     result = generate_helpstring_result(ALIASES, "you")
     self.check_data_structure(result)
     self.check_available_count(result, 4)
     the80s = result.get("helpstrings").get("the80s")
     self.assertEqual(len(the80s), 4)
     self.assertEqual(the80s[0].get("display"),
                      "Come with me if you want to live")
 def test_limit_in_bounds(self, mock):
     result = generate_helpstring_result(ALIASES, "", "the80s", 3)
     self.check_data_structure(result)
     self.check_available_count(result, 10)
     the80s = result.get("helpstrings").get("the80s")
     self.assertEqual(len(the80s), 3)
     self.assertEqual(the80s[0].get("display"),
                      "Come with me if you want to live")
示例#14
0
    def help(self, filter, pack, limit, offset, **kwargs):
        """
            Get available help strings for action aliases.

            Handles requests:
                GET /actionalias/help
        """
        try:
            aliases_resp = super(ActionAliasController, self)._get_all(**kwargs)
            aliases = [ActionAliasAPI(**alias) for alias in aliases_resp.json]
            return generate_helpstring_result(aliases, filter, pack, int(limit), int(offset))
        except (TypeError) as e:
            LOG.exception('Helpstring request contains an invalid data type: %s.', six.text_type(e))
            return abort(http_client.BAD_REQUEST, six.text_type(e))
示例#15
0
    def help(self, filter, pack, limit, offset, **kwargs):
        """
            Get available help strings for action aliases.

            Handles requests:
                GET /actionalias/help
        """
        try:
            aliases_resp = super(ActionAliasController, self)._get_all(**kwargs)
            aliases = [ActionAliasAPI(**alias) for alias in aliases_resp.json]
            return generate_helpstring_result(aliases, filter, pack, int(limit), int(offset))
        except (TypeError) as e:
            LOG.exception('Helpstring request contains an invalid data type: %s.', six.text_type(e))
            return abort(http_client.BAD_REQUEST, six.text_type(e))
示例#16
0
文件: actionalias.py 项目: peak6/st2
    def help(self, action_alias_help_api, **kwargs):
        """
            Get available help strings for action aliases.

            Handles requests:
                POST /actionalias/help
        """
        filter_ = action_alias_help_api.filter
        pack = action_alias_help_api.pack
        limit = action_alias_help_api.limit
        offset = action_alias_help_api.offset

        try:
            aliases = super(ActionAliasController, self)._get_all(**kwargs)
            return generate_helpstring_result(aliases, filter_, pack, limit, offset)
        except (TypeError) as e:
            LOG.exception('Helpstring request contains an invalid data type: %s.', str(e))
            pecan.abort(http_client.BAD_REQUEST, str(e))
示例#17
0
    def help(self, action_alias_help_api, **kwargs):
        """
            Get available help strings for action aliases.

            Handles requests:
                POST /actionalias/help
        """
        filter_ = action_alias_help_api.filter
        pack = action_alias_help_api.pack
        limit = action_alias_help_api.limit
        offset = action_alias_help_api.offset

        try:
            aliases = super(ActionAliasController, self)._get_all(**kwargs)
            return generate_helpstring_result(aliases, filter_, pack, limit,
                                              offset)
        except (TypeError) as e:
            LOG.exception(
                'Helpstring request contains an invalid data type: %s.',
                str(e))
            pecan.abort(http_client.BAD_REQUEST, str(e))
 def test_pack_bad_datatype(self, mock):
     result = generate_helpstring_result(ALIASES, "", {})
     self.check_data_structure(result)
     self.check_available_count(result, 0)
     self.assertEqual(result.get("helpstrings"), {})
 def test_pack_no_match(self, mock):
     result = generate_helpstring_result(ALIASES, "", "you_will_not_find_this_string")
     self.check_data_structure(result)
     self.check_available_count(result, 0)
     self.assertEqual(result.get("helpstrings"), {})
 def test_offset_positive_out_of_bounds(self, mock):
     result = generate_helpstring_result(ALIASES, "", "the80s", 0, 30)
     self.check_data_structure(result)
     self.check_available_count(result, 10)
     self.assertEqual(result.get("helpstrings"), {})
 def test_offset_positive_out_of_bounds(self, mock):
     result = generate_helpstring_result(ALIASES, "", "the80s", 0, 30)
     self.check_data_structure(result)
     self.check_available_count(result, 10)
     self.assertEqual(result.get("helpstrings"), [])
 def test_pack_bad_datatype(self, mock):
     result = generate_helpstring_result(ALIASES, "", {})
     self.check_data_structure(result)
     self.check_available_count(result, 0)
     self.assertEqual(result.get("helpstrings"), {})
 def test_pack_no_match(self, mock):
     result = generate_helpstring_result(ALIASES, "", "you_will_not_find_this_string")
     self.check_data_structure(result)
     self.check_available_count(result, 0)
     self.assertEqual(result.get("helpstrings"), [])