def test__get_date_strict(self):
        import time
        from datetime import datetime
        from kayako.core.lib import NodeParser, FOREVER

        timestamp = int(time.mktime(datetime.now().timetuple()))
        now = datetime.fromtimestamp(timestamp)

        assert NodeParser._get_date(self._etree_with_data(timestamp), required=False, strict=True) == now
        assert NodeParser._get_date(self._etree_with_data("0"), required=True) == FOREVER
        assert NodeParser._get_date(None, required=False, strict=True) == None
        assert NodeParser._get_date(self._etree_with_data(""), required=False, strict=True) == None
        self.assertRaises(ValueError, NodeParser._get_date, self._etree_with_data("abc"), required=False, strict=True)
示例#2
0
 def _get_date(node, required=True, strict=True):
     try:
         return NodeParser._get_date(node, required=required, strict=strict)
     except Exception as error:
         raise KayakoResponseError(
             'There was an error parsing the response (_get_date(%s, required=%s, strict=%s):\n\t%s'
             % (node, required, strict, error))
示例#3
0
    def test__get_date_optional(self):
        import time
        from datetime import datetime
        from kayako.core.lib import NodeParser, FOREVER

        timestamp = int(time.mktime(datetime.now().timetuple()))
        now = datetime.fromtimestamp(timestamp)

        assert NodeParser._get_date(self._etree_with_data(timestamp),
                                    required=False,
                                    strict=False) == now
        assert NodeParser._get_date(self._etree_with_data('0'),
                                    required=True) == FOREVER
        assert NodeParser._get_date(None, required=False, strict=False) == None
        assert NodeParser._get_date(self._etree_with_data(''),
                                    required=False,
                                    strict=False) == None
        assert NodeParser._get_date(self._etree_with_data('abc'),
                                    required=False,
                                    strict=False) == None
示例#4
0
    def test__get_date_required(self):
        import time
        from datetime import datetime
        from kayako.core.lib import NodeParser, FOREVER

        timestamp = int(time.mktime(datetime.now().timetuple()))
        now = datetime.fromtimestamp(timestamp)

        assert NodeParser._get_date(self._etree_with_data(timestamp),
                                    required=True) == now
        assert NodeParser._get_date(self._etree_with_data('0'),
                                    required=True) == FOREVER
        self.assertRaises(AttributeError,
                          NodeParser._get_date,
                          None,
                          required=True)
        self.assertRaises(TypeError,
                          NodeParser._get_date,
                          self._etree_with_data(''),
                          required=True)
        self.assertRaises(ValueError,
                          NodeParser._get_date,
                          self._etree_with_data('abc'),
                          required=True)
示例#5
0
 def _get_date(node, required=True, strict=True):
     try:
         return NodeParser._get_date(node, required=required, strict=strict)
     except Exception as error:
         raise KayakoResponseError('There was an error parsing the response (_get_date(%s, required=%s, strict=%s):\n\t%s' % (node, required, strict, error))