def test_to_python_with_base64_decoded_value(self):
        """Testing Base64Field.to_python with Base64DecodedValue"""
        obj = Base64TestModel()
        value = obj._meta.get_field('field').to_python(
            Base64DecodedValue(b'This is a test'))

        self.assertIs(type(value), Base64DecodedValue)
        self.assertEqual(value, b'This is a test')
Exemple #2
0
    def test_get_prep_value_with_base64_decoded_value(self):
        """Testing Base64Field.get_prep_value with Base64DecodedValue value"""
        obj = Base64TestModel()
        value = obj._meta.get_field('field').get_prep_value(
            Base64DecodedValue(b'This is a t\xc3\xa9st'))

        self.assertIs(type(value), six.text_type)
        self.assertEqual(value, 'VGhpcyBpcyBhIHTDqXN0\n')
    def test_create_with_base64_decoded_value(self):
        """Testing Base64Field with setting Base64DecodedValue in
        Model.objects.create()
        """
        obj = Base64TestModel.objects.create(
            field=Base64DecodedValue(b'This is a test'))

        self.assertIs(type(obj.field), Base64DecodedValue)
        self.assertEqual(obj.field, b'This is a test')

        encoded = obj.get_field_base64()
        self.assertIs(type(encoded), bytes)
        self.assertEqual(encoded, b'VGhpcyBpcyBhIHRlc3Q=\n')
    def test_unsaved_obj_with_base64_decoded_value(self):
        """Testing Base64Field with setting Base64DecodedValue on unsaved
        instance
        """
        obj = Base64TestModel()
        obj.field = Base64DecodedValue(b'This is a test')

        self.assertIs(type(obj.field), Base64DecodedValue)
        self.assertEqual(obj.field, b'This is a test')

        encoded = obj.get_field_base64()
        self.assertIs(type(encoded), bytes)
        self.assertEqual(encoded, b'VGhpcyBpcyBhIHRlc3Q=\n')