コード例 #1
0
    def test__get_int_strict(self):
        from kayako.core.lib import NodeParser

        assert NodeParser._get_int(self._etree_with_data("123"), required=False, strict=True) == 123
        assert NodeParser._get_int(None, required=False, strict=True) == None
        assert NodeParser._get_int(self._etree_with_data(""), required=False, strict=True) == None
        self.assertRaises(ValueError, NodeParser._get_int, self._etree_with_data("abc"), required=False, strict=True)
コード例 #2
0
    def test__get_int_optional(self):
        from kayako.core.lib import NodeParser

        assert NodeParser._get_int(self._etree_with_data("123"), required=False, strict=False) == 123
        assert NodeParser._get_int(None, required=False, strict=False) == None
        assert NodeParser._get_int(self._etree_with_data(""), required=False, strict=False) == None
        assert NodeParser._get_int(self._etree_with_data("abc"), required=False, strict=False) == None
コード例 #3
0
    def test__get_int_optional(self):
        from kayako.core.lib import NodeParser

        assert NodeParser._get_int(self._etree_with_data('123'),
                                   required=False,
                                   strict=False) == 123
        assert NodeParser._get_int(None, required=False, strict=False) == None
        assert NodeParser._get_int(self._etree_with_data(''),
                                   required=False,
                                   strict=False) == None
        assert NodeParser._get_int(self._etree_with_data('abc'),
                                   required=False,
                                   strict=False) == None
コード例 #4
0
    def test__get_int_strict(self):
        from kayako.core.lib import NodeParser

        assert NodeParser._get_int(self._etree_with_data('123'),
                                   required=False,
                                   strict=True) == 123
        assert NodeParser._get_int(None, required=False, strict=True) == None
        assert NodeParser._get_int(self._etree_with_data(''),
                                   required=False,
                                   strict=True) == None
        self.assertRaises(ValueError,
                          NodeParser._get_int,
                          self._etree_with_data('abc'),
                          required=False,
                          strict=True)
コード例 #5
0
    def test__get_int_required(self):
        from kayako.core.lib import NodeParser

        assert NodeParser._get_int(self._etree_with_data("123"), required=True) == 123
        self.assertRaises(AttributeError, NodeParser._get_int, None, required=True)
        self.assertRaises(TypeError, NodeParser._get_int, self._etree_with_data(""), required=True)
        self.assertRaises(ValueError, NodeParser._get_int, self._etree_with_data("abc"), required=True)
コード例 #6
0
 def _get_int(node, required=True, strict=True):
     try:
         return NodeParser._get_int(node, required=required, strict=strict)
     except Exception as error:
         raise KayakoResponseError(
             'There was an error parsing the response (_get_int(%s, required=%s, strict=%s):\n\t%s'
             % (node, required, strict, error))
コード例 #7
0
    def test__get_int_required(self):
        from kayako.core.lib import NodeParser

        assert NodeParser._get_int(self._etree_with_data('123'),
                                   required=True) == 123
        self.assertRaises(AttributeError,
                          NodeParser._get_int,
                          None,
                          required=True)
        self.assertRaises(TypeError,
                          NodeParser._get_int,
                          self._etree_with_data(''),
                          required=True)
        self.assertRaises(ValueError,
                          NodeParser._get_int,
                          self._etree_with_data('abc'),
                          required=True)
コード例 #8
0
ファイル: object.py プロジェクト: nagyv/python-api-library
 def _get_int(node, required=True, strict=True):
     try:
         return NodeParser._get_int(node, required=required, strict=strict)
     except Exception as error:
         raise KayakoResponseError('There was an error parsing the response (_get_int(%s, required=%s, strict=%s):\n\t%s' % (node, required, strict, error))