Esempio n. 1
0
 def test_repr(self):
     """Test correct class representation.
     """
     it = Parameters(parameter1='Value1')
     self.assertTrue(
         re.match("Parameters\({u?'PARAMETER1': 'Value1'}\)", str(it))
     )
    def test_parameters_class(self):

        # Simple parameter:value pair
        p = Parameters(parameter1='Value1')
        self.assertEqual(p.to_ical(), b'PARAMETER1=Value1')

        # keys are converted to upper
        self.assertEqual(list(p.keys()), ['PARAMETER1'])

        # Parameters are case insensitive
        self.assertEqual(p['parameter1'], 'Value1')
        self.assertEqual(p['PARAMETER1'], 'Value1')

        # Parameter with list of values must be seperated by comma
        p = Parameters({'parameter1': ['Value1', 'Value2']})
        self.assertEqual(p.to_ical(), b'PARAMETER1=Value1,Value2')

        # Multiple parameters must be seperated by a semicolon
        p = Parameters({'RSVP': 'TRUE', 'ROLE': 'REQ-PARTICIPANT'})
        self.assertEqual(p.to_ical(), b'ROLE=REQ-PARTICIPANT;RSVP=TRUE')

        # Parameter values containing ',;:' must be double quoted
        p = Parameters({'ALTREP': 'http://www.wiz.org'})
        self.assertEqual(p.to_ical(), b'ALTREP="http://www.wiz.org"')

        # list items must be quoted seperately
        p = Parameters({'MEMBER': ['MAILTO:[email protected]',
                                   'MAILTO:[email protected]']})
        self.assertEqual(
            p.to_ical(),
            b'MEMBER="MAILTO:[email protected]","MAILTO:[email protected]"'
        )

        # Now the whole sheebang
        p = Parameters({'parameter1': 'Value1',
                        'parameter2': ['Value2', 'Value3'],
                        'ALTREP': ['http://www.wiz.org', 'value4']})
        self.assertEqual(
            p.to_ical(),
            (b'ALTREP="http://www.wiz.org",value4;PARAMETER1=Value1;'
             b'PARAMETER2=Value2,Value3')
        )

        # We can also parse parameter strings
        self.assertEqual(
            Parameters.from_ical('PARAMETER1=Value 1;param2=Value 2'),
            Parameters({'PARAMETER1': 'Value 1', 'PARAM2': 'Value 2'})
        )

        # Including empty strings
        self.assertEqual(Parameters.from_ical('param='),
                         Parameters({'PARAM': ''}))

        # We can also parse parameter strings
        self.assertEqual(
            Parameters.from_ical(
                'MEMBER="MAILTO:[email protected]","MAILTO:[email protected]"'
            ),
            Parameters({'MEMBER': ['MAILTO:[email protected]',
                                   'MAILTO:[email protected]']})
        )

        # We can also parse parameter strings
        self.assertEqual(
            Parameters.from_ical('ALTREP="http://www.wiz.org",value4;'
                                 'PARAMETER1=Value1;PARAMETER2=Value2,Value3'),
            Parameters({'PARAMETER1': 'Value1',
                        'ALTREP': ['http://www.wiz.org', 'value4'],
                        'PARAMETER2': ['Value2', 'Value3']})
        )
Esempio n. 3
0
    def test_parameters_class(self):

        # Simple parameter:value pair
        p = Parameters(parameter1="Value1")
        self.assertEqual(p.to_ical(), b"PARAMETER1=Value1")

        # keys are converted to upper
        self.assertEqual(list(p.keys()), ["PARAMETER1"])

        # Parameters are case insensitive
        self.assertEqual(p["parameter1"], "Value1")
        self.assertEqual(p["PARAMETER1"], "Value1")

        # Parameter with list of values must be seperated by comma
        p = Parameters({"parameter1": ["Value1", "Value2"]})
        self.assertEqual(p.to_ical(), b"PARAMETER1=Value1,Value2")

        # Multiple parameters must be seperated by a semicolon
        p = Parameters({"RSVP": "TRUE", "ROLE": "REQ-PARTICIPANT"})
        self.assertEqual(p.to_ical(), b"ROLE=REQ-PARTICIPANT;RSVP=TRUE")

        # Parameter values containing ',;:' must be double quoted
        p = Parameters({"ALTREP": "http://www.wiz.org"})
        self.assertEqual(p.to_ical(), b'ALTREP="http://www.wiz.org"')

        # list items must be quoted seperately
        p = Parameters({"MEMBER": ["MAILTO:[email protected]", "MAILTO:[email protected]"]})
        self.assertEqual(p.to_ical(), b'MEMBER="MAILTO:[email protected]","MAILTO:[email protected]"')

        # Now the whole sheebang
        p = Parameters(
            {"parameter1": "Value1", "parameter2": ["Value2", "Value3"], "ALTREP": ["http://www.wiz.org", "value4"]}
        )
        self.assertEqual(
            p.to_ical(), (b'ALTREP="http://www.wiz.org",value4;PARAMETER1=Value1;' b"PARAMETER2=Value2,Value3")
        )

        # We can also parse parameter strings
        self.assertEqual(
            Parameters.from_ical("PARAMETER1=Value 1;param2=Value 2"),
            Parameters({"PARAMETER1": "Value 1", "PARAM2": "Value 2"}),
        )

        # Including empty strings
        self.assertEqual(Parameters.from_ical("param="), Parameters({"PARAM": ""}))

        # We can also parse parameter strings
        self.assertEqual(
            Parameters.from_ical('MEMBER="MAILTO:[email protected]","MAILTO:[email protected]"'),
            Parameters({"MEMBER": ["MAILTO:[email protected]", "MAILTO:[email protected]"]}),
        )

        # We can also parse parameter strings
        self.assertEqual(
            Parameters.from_ical('ALTREP="http://www.wiz.org",value4;' "PARAMETER1=Value1;PARAMETER2=Value2,Value3"),
            Parameters(
                {"PARAMETER1": "Value1", "ALTREP": ["http://www.wiz.org", "value4"], "PARAMETER2": ["Value2", "Value3"]}
            ),
        )