コード例 #1
0
    def test_validation(self):
        """Article validation; blacklisted fields should be removed, others should be added"""
        expected = {'Subject': 'This Article only has Subject',
                    'Body': 'and Body and needs to be completed.'}

        expected_validated = {'Subject': 'This Article only has Subject',
                              'Body': 'and Body and needs to be completed.',
                              'TimeUnit': 0,
                              'MimeType': 'text/plain',
                              'Charset': 'UTF8'}

        art = Article({'Subject': 'This Article only has Subject',
                       'Body': 'and Body and needs to be completed.'})

        self.assertIsInstance(art, Article)
        self.assertDictEqual(art.to_dct(), expected)

        art.validate()
        self.assertDictEqual(art.to_dct(), expected_validated)
コード例 #2
0
    def test_validation_custom(self):
        """Article validation; blacklisted fields should be removed, others should be added"""

        custom_validation = {"Body": "API created Article Body",
                             "Charset": "UTF8",
                             "SpecialField": "SpecialValue",
                             "MimeType": "text/plain",
                             "Subject": "API created Article",
                             "TimeUnit": 0}

        expected_validated = {'Subject': 'This Article only has Subject',
                              'Body': 'and Body and needs to be completed.',
                              'TimeUnit': 0,
                              'MimeType': 'text/plain',
                              'Charset': 'UTF8',
                              'SpecialField': 'SpecialValue'}

        art = Article({'Subject': 'This Article only has Subject',
                       'Body': 'and Body and needs to be completed.'})

        art.validate(validation_map=custom_validation)
        self.assertDictEqual(art.to_dct(), expected_validated)