Exemplo n.º 1
0
 def to_python(self, value):
     if value is None:
         return None
     if isinstance(value, self.of):
         return value
     if isinstance(value, dict):
         return create_resource_from_dict(value, self.of._meta.resource_name)
     msg = self.error_messages['invalid'] % self.of
     raise exceptions.ValidationError(msg)
Exemplo n.º 2
0
 def to_python(self, value):
     if value is None:
         return None
     if isinstance(value, self.of):
         return value
     if isinstance(value, dict):
         return create_resource_from_dict(value, self.of._meta.resource_name)
     msg = self.error_messages['invalid'] % self.of
     raise exceptions.ValidationError(msg)
Exemplo n.º 3
0
    def test_create_resource_from_dict(self):
        actual = create_resource_from_dict(
            {
                'title': '1984',
                'isbn': '1234567',
                'num_pages': 1
            }, BookProxy)

        assert actual.title == '1984'
Exemplo n.º 4
0
    def test_create_resource_from_dict__with_proxy(self):
        book = create_resource_from_dict(
            {
                "title": "Foo",
                "num_pages": 42,
                "rrp": 10000.99,
                "fiction": True
            },
            BookProxy,
            full_clean=False,
            default_to_not_provided=True)

        assert dict(
            title="Foo",
            isbn=NotProvided,
            num_pages=42,
            rrp=20.4,
        ) == book.to_dict()
Exemplo n.º 5
0
    def test_create_resource_from_dict_with_default_to_not_supplied(self):
        book = create_resource_from_dict({
            "title": "Foo",
            "num_pages": 42
        },
                                         Book,
                                         full_clean=False,
                                         default_to_not_provided=True)

        assert dict(title="Foo",
                    isbn=NotProvided,
                    num_pages=42,
                    rrp=NotProvided,
                    fiction=NotProvided,
                    genre=NotProvided,
                    published=NotProvided,
                    authors=NotProvided,
                    publisher=NotProvided) == book.to_dict()
Exemplo n.º 6
0
 def __next__(self):
     return create_resource_from_dict(csv.DictReader.__next__(self), self.resource, copy_dict=False)
Exemplo n.º 7
0
 def __next__(self):
     return create_resource_from_dict(csv.DictReader.__next__(self),
                                      self.resource,
                                      copy_dict=False)
Exemplo n.º 8
0
    def test_create_resource_from_dict(self):
        actual = create_resource_from_dict({'title': '1984', 'isbn': '1234567', 'num_pages': 1}, BookProxy)

        assert actual.title == '1984'
Exemplo n.º 9
0
 def __next__(self):
     return create_resource_from_dict(
         csv.DictReader.__next__(self),
         self.resources._meta.resource_name
     )