Exemple #1
0
    def testParseProperty(self):

        # Restore BACKSLASH_IN_URI_VALUE after test
        old_state = ParserContext.BACKSLASH_IN_URI_VALUE
        self.addCleanup(setattr, ParserContext, "BACKSLASH_IN_URI_VALUE", old_state)

        # Test with BACKSLASH_IN_URI_VALUE = PARSER_FIX
        ParserContext.BACKSLASH_IN_URI_VALUE = ParserContext.PARSER_FIX
        items = (
            ("URL:http://example.com", "URL:http://example.com"),
            ("URL:http://example.com&abd\\,def", "URL:http://example.com&abd,def"),
        )

        for item, result in items:
            prop = Property.parseText(item)
            test = prop.getText()
            self.assertEqual(test, result + "\r\n", "Failed to parse and re-generate '%s'" % (item,))

        # Test with BACKSLASH_IN_URI_VALUE = PARSER_ALLOW
        ParserContext.BACKSLASH_IN_URI_VALUE = ParserContext.PARSER_ALLOW
        items = (
            ("URL:http://example.com", "URL:http://example.com"),
            ("URL:http://example.com&abd\\,def", "URL:http://example.com&abd\\,def"),
        )

        for item, result in items:
            prop = Property.parseText(item)
            test = prop.getText()
            self.assertEqual(test, result + "\r\n", "Failed to parse and re-generate '%s'" % (item,))
    def testParseProperty(self):

        # Restore BACKSLASH_IN_URI_VALUE after test
        old_state = ParserContext.BACKSLASH_IN_URI_VALUE
        self.addCleanup(setattr, ParserContext, "BACKSLASH_IN_URI_VALUE", old_state)

        # Test with BACKSLASH_IN_URI_VALUE = PARSER_FIX
        ParserContext.BACKSLASH_IN_URI_VALUE = ParserContext.PARSER_FIX
        items = (
            ("URL:http://example.com", "URL:http://example.com"),
            ("URL:http://example.com&abd\\,def", "URL:http://example.com&abd,def"),
        )

        for item, result in items:
            prop = Property.parseText(item)
            test = prop.getText()
            self.assertEqual(test, result + "\r\n", "Failed to parse and re-generate '%s'" % (item,))

        # Test with BACKSLASH_IN_URI_VALUE = PARSER_ALLOW
        ParserContext.BACKSLASH_IN_URI_VALUE = ParserContext.PARSER_ALLOW
        items = (
            ("URL:http://example.com", "URL:http://example.com"),
            ("URL:http://example.com&abd\\,def", "URL:http://example.com&abd\\,def"),
        )

        for item, result in items:
            prop = Property.parseText(item)
            test = prop.getText()
            self.assertEqual(test, result + "\r\n", "Failed to parse and re-generate '%s'" % (item,))
    def testUnknownValueRoundtrip(self):

        data = "X-FOO:Text, not escaped"
        prop = Property.parseText(data)
        self.assertEqual(str(prop), data + "\r\n")

        prop = Property("X-FOO", "Text, not escaped")
        self.assertEqual(str(prop), data + "\r\n")

        data = "X-FOO:Text\\, escaped\\n"
        prop = Property.parseText(data)
        self.assertEqual(str(prop), data + "\r\n")

        prop = Property("X-FOO", "Text\\, escaped\\n")
        self.assertEqual(str(prop), data + "\r\n")
    def testUnknownValueRoundtrip(self):

        data = "X-FOO:Text, not escaped"
        prop = Property.parseText(data)
        self.assertEqual(str(prop), data + "\r\n")

        prop = Property("X-FOO", "Text, not escaped")
        self.assertEqual(str(prop), data + "\r\n")

        data = "X-FOO:Text\\, escaped\\n"
        prop = Property.parseText(data)
        self.assertEqual(str(prop), data + "\r\n")

        prop = Property("X-FOO", "Text\\, escaped\\n")
        self.assertEqual(str(prop), data + "\r\n")
Exemple #5
0
    def test_positiveIntegerOrZero(self):

        props = (
            (
                "SUMMARY:Test",
                False,
            ),
            (
                "REPEAT:0",
                True,
            ),
            (
                "REPEAT:100",
                True,
            ),
            (
                "REPEAT:-1",
                False,
            ),
        )

        for prop, result in props:
            property = Property.parseText(prop)
            self.assertEqual(
                PropertyValueChecks.positiveIntegerOrZero(property), result)
Exemple #6
0
    def testParameterEncodingDecoding(self):

        prop = Property("X-FOO", "Test")
        prop.addParameter(Parameter("X-BAR", "\"Check\""))
        self.assertEqual(str(prop), "X-FOO;X-BAR=^'Check^':Test\r\n")

        prop.addParameter(Parameter("X-BAR2", "Check\nThis\tOut\n"))
        self.assertEqual(str(prop), "X-FOO;X-BAR=^'Check^';X-BAR2=Check^nThis\tOut^n:Test\r\n")

        data = "X-FOO;X-BAR=^'Check^':Test"
        prop = Property.parseText(data)
        self.assertEqual(prop.getParameterValue("X-BAR"), "\"Check\"")

        data = "X-FOO;X-BAR=^'Check^';X-BAR2=Check^nThis\tOut^n:Test"
        prop = Property.parseText(data)
        self.assertEqual(prop.getParameterValue("X-BAR"), "\"Check\"")
        self.assertEqual(prop.getParameterValue("X-BAR2"), "Check\nThis\tOut\n")
    def testHash(self):

        hashes = []
        for item in TestProperty.test_data:
            prop = Property.parseText(item)
            hashes.append(hash(prop))
        hashes.sort()
        for i in range(1, len(hashes)):
            self.assertNotEqual(hashes[i - 1], hashes[i])
    def testHash(self):

        hashes = []
        for item in TestProperty.test_data:
            prop = Property.parseText(item)
            hashes.append(hash(prop))
        hashes.sort()
        for i in range(1, len(hashes)):
            self.assertNotEqual(hashes[i - 1], hashes[i])
Exemple #9
0
    def testNewRegistrationValueRoundtrip(self):

        Property.registerDefaultValue("X-SPECIAL-REGISTRATION", Value.VALUETYPE_TEXT)

        data = "X-SPECIAL-REGISTRATION:Text\\, escaped\\n"
        prop = Property.parseText(data)
        self.assertEqual(str(prop), "X-SPECIAL-REGISTRATION:Text\\, escaped\\n\r\n")

        prop = Property("X-SPECIAL-REGISTRATION", "Text, escaped\n")
        self.assertEqual(str(prop), "X-SPECIAL-REGISTRATION:Text\\, escaped\\n\r\n")
    def testParseGenerate(self):

        for data in TestProperty.test_data:
            prop = Property.parseText(data)
            propstr = str(prop).replace("\r\n ", "")
            self.assertEqual(
                propstr[:-2], data, "Failed parse/generate: %s to %s" % (
                    data,
                    propstr,
                ))
Exemple #11
0
    def sample(self):

        if self._allowRecurrence:
            index = self._helperDistribution.sample()
            rrule = self._rrules[index]
            if rrule:
                prop = Property.parseText(rrule)
                return prop

        return None
    def test_stringValue(self):

        props = (
            ("SUMMARY:Test", "Test", True,),
            ("SUMMARY:Test", "TEST", True,),
            ("DTSTART:20110623T174806", "Test", False),
        )

        for prop, test, result in props:
            property = Property.parseText(prop)
            self.assertEqual(PropertyValueChecks.stringValue(test, property), result)
Exemple #13
0
    def testParseProperty(self):

        items = (
            ("GEO:-12.345;67.890", "GEO:-12.345;67.89"),
            ("GEO:-12.345\\;67.890", "GEO:-12.345;67.89"),
        )

        for item, result in items:
            prop = Property.parseText(item)
            test = prop.getText()
            self.assertEqual(test, result + "\r\n", "Failed to parse and re-generate '%s'" % (item,))
Exemple #14
0
    def testParseProperty(self):

        items = (
            ("GEO:-12.345;67.890", "GEO:-12.345;67.89"),
            ("GEO:-12.345\\;67.890", "GEO:-12.345;67.89"),
        )

        for item, result in items:
            prop = Property.parseText(item)
            test = prop.getText()
            self.assertEqual(test, result + "\r\n",
                             "Failed to parse and re-generate '%s'" % (item, ))
    def test_alwaysUTC(self):

        props = (
            ("SUMMARY:Test", False,),
            ("DTSTART:20110623T174806", False),
            ("DTSTART;VALUE=DATE:20110623", False),
            ("DTSTART:20110623T174806Z", True),
        )

        for prop, result in props:
            property = Property.parseText(prop)
            self.assertEqual(PropertyValueChecks.alwaysUTC(property), result)
    def test_positiveIntegerOrZero(self):

        props = (
            ("SUMMARY:Test", False,),
            ("REPEAT:0", True,),
            ("REPEAT:100", True,),
            ("REPEAT:-1", False,),
        )

        for prop, result in props:
            property = Property.parseText(prop)
            self.assertEqual(PropertyValueChecks.positiveIntegerOrZero(property), result)
    def testParseProperty(self):

        items = (
            "REQUEST-STATUS:2.0;Success",
            "REQUEST-STATUS:2.0;Success\;here",
            "REQUEST-STATUS:2.0;Success;Extra",
            "REQUEST-STATUS:2.0;Success\;here;Extra",
            "REQUEST-STATUS:2.0;Success;Extra\;here",
            "REQUEST-STATUS:2.0;Success\;here;Extra\;here too",
        )

        for item in items:
            req = Property.parseText(item)
            self.assertEqual(req.getText(), item + "\r\n", "Failed to parse and re-generate '%s'" % (item,))
    def test_numericRange(self):

        props = (
            ("SUMMARY:Test", 0, 100, False,),
            ("PERCENT-COMPLETE:0", 0, 100, True,),
            ("PERCENT-COMPLETE:100", 0, 100, True,),
            ("PERCENT-COMPLETE:50", 0, 100, True,),
            ("PERCENT-COMPLETE:200", 0, 100, False,),
            ("PERCENT-COMPLETE:-1", 0, 100, False,),
        )

        for prop, low, high, result in props:
            property = Property.parseText(prop)
            self.assertEqual(PropertyValueChecks.numericRange(low, high, property), result)
Exemple #19
0
    def test_alwaysUTC(self):

        props = (
            (
                "SUMMARY:Test",
                False,
            ),
            ("DTSTART:20110623T174806", False),
            ("DTSTART;VALUE=DATE:20110623", False),
            ("DTSTART:20110623T174806Z", True),
        )

        for prop, result in props:
            property = Property.parseText(prop)
            self.assertEqual(PropertyValueChecks.alwaysUTC(property), result)
Exemple #20
0
    def test_numericRange(self):

        props = (
            (
                "SUMMARY:Test",
                0,
                100,
                False,
            ),
            (
                "PERCENT-COMPLETE:0",
                0,
                100,
                True,
            ),
            (
                "PERCENT-COMPLETE:100",
                0,
                100,
                True,
            ),
            (
                "PERCENT-COMPLETE:50",
                0,
                100,
                True,
            ),
            (
                "PERCENT-COMPLETE:200",
                0,
                100,
                False,
            ),
            (
                "PERCENT-COMPLETE:-1",
                0,
                100,
                False,
            ),
        )

        for prop, low, high, result in props:
            property = Property.parseText(prop)
            self.assertEqual(
                PropertyValueChecks.numericRange(low, high, property), result)
Exemple #21
0
    def test_stringValue(self):

        props = (
            (
                "SUMMARY:Test",
                "Test",
                True,
            ),
            (
                "SUMMARY:Test",
                "TEST",
                True,
            ),
            ("DTSTART:20110623T174806", "Test", False),
        )

        for prop, test, result in props:
            property = Property.parseText(prop)
            self.assertEqual(PropertyValueChecks.stringValue(test, property),
                             result)
    def testGEOValueRoundtrip(self):

        data = "GEO:123.456;789.101"
        prop = Property.parseText(data)
        self.assertEqual(str(prop), data + "\r\n")
Exemple #23
0
    def testEquality(self):

        for data in TestProperty.test_data:
            prop1 = Property.parseText(data)
            prop2 = Property.parseText(data)
            self.assertEqual(prop1, prop2, "Failed equality: %s" % (data,))
    def testEquality(self):

        for data in TestProperty.test_data:
            prop1 = Property.parseText(data)
            prop2 = Property.parseText(data)
            self.assertEqual(prop1, prop2, "Failed equality: %s" % (data, ))
Exemple #25
0
    def testGEOValueRoundtrip(self):

        data = "GEO:123.456;789.101"
        prop = Property.parseText(data)
        self.assertEqual(str(prop), data + "\r\n")
Exemple #26
0
    def testParseGenerate(self):

        for data in TestProperty.test_data:
            prop = Property.parseText(data)
            propstr = str(prop).replace("\r\n ", "")
            self.assertEqual(propstr[:-2], data, "Failed parse/generate: %s to %s" % (data, propstr,))