Esempio n. 1
0
    def test_parse(self):
        @dataclass
        class TestHandler(XmlHandler):
            def parse(self, source: Any) -> Any:
                return Books()

        self.parser.handler = TestHandler
        self.assertEqual(Books(), self.parser.parse([], Books))
Esempio n. 2
0
    def test_bind_wildcard_with_derived_element(self):
        var = XmlVar(
            any_type=True,
            name="a",
            qname="a",
            types=[object],
        )
        actual = DerivedElement(qname="a",
                                value=Books(book=[]),
                                substituted=True)
        data = {"qname": "a", "value": {"book": []}, "substituted": True}

        self.assertEqual(actual, self.parser.bind_value(var, data))
Esempio n. 3
0
def make_books(how_many: int):
    return Books(book=[
        BookForm(
            author="Arne Dahl",
            title="Misterioso: A Crime Novel",
            genre="Thrillers & Suspense",
            price=15.95,
            pub_date=XmlDate(1999, 10, 5),
            review=(
                "Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
                "Integer at erat sagittis, accumsan mauris eu, egestas "
                "quam. Nam tristique felis justo, vel iaculis ipsum cursus "
                "at. Praesent varius enim ac nunc interdum placerat. "
                "Integer porttitor, nibh at viverra vehicula, leo dui "
                "suscipit nisi, ornare laoreet eros neque nec mi. Proin."),
            id="9788831796781",
        ) for _ in range(how_many)
    ])
Esempio n. 4
0
    def setUp(self):
        super().setUp()
        self.books = Books(book=[
            BookForm(
                id="bk001",
                author="Hightower, Kim",
                title="The First Book",
                genre="Fiction",
                price=44.95,
                pub_date=XmlDate.from_string("2000-10-01"),
                review="An amazing story of nothing.",
            ),
            BookForm(
                id="bk002",
                author="Nagata, Suanne",
                title="Becoming Somebody",
                genre="Biography",
                review="A masterpiece of the fine art of gossiping.",
            ),
        ])

        self.expected = {
            "book": [
                {
                    "author": "Hightower, Kim",
                    "genre": "Fiction",
                    "id": "bk001",
                    "lang": "en",
                    "price": 44.95,
                    "pub_date": "2000-10-01",
                    "review": "An amazing story of nothing.",
                    "title": "The First Book",
                },
                {
                    "author": "Nagata, Suanne",
                    "genre": "Biography",
                    "id": "bk002",
                    "lang": "en",
                    "review": "A masterpiece of the fine art of gossiping.",
                    "title": "Becoming Somebody",
                },
            ]
        }
Esempio n. 5
0
 def setUp(self):
     super(XmlSerializerTests, self).setUp()
     self.books = Books(book=[
         BookForm(
             id="bk001",
             author="Hightower, Kim",
             title="The First Book",
             genre="Fiction",
             price=44.95,
             pub_date="2000-10-01",
             review="An amazing story of nothing.",
         ),
         BookForm(
             id="bk002",
             author="Nagata, Suanne",
             title="Becoming Somebody",
             genre="Biography",
             review="A masterpiece of the fine art of gossiping.",
         ),
     ])
Esempio n. 6
0
from tests.fixtures.books import Books, BookForm
from xsdata.models.datatype import XmlDate

books = Books(book=[
    BookForm(
        id="bk001",
        author="Hightower, Kim",
        title="The First Book",
        genre="Fiction",
        price=44.95,
        pub_date=XmlDate(2000, 10, 1),
        review="An amazing story of nothing.",
    ),
    BookForm(
        id="bk002",
        author="Nagata, Suanne",
        title="Becoming Somebody",
        genre="Biography",
        price=33.95,
        pub_date=XmlDate(2001, 1, 10),
        review="A masterpiece of the fine art of gossiping.",
    ),
])
events = [('start-ns', 'brk', 'urn:books'),
          ('start', '{urn:books}books', {}, {
              'brk': 'urn:books'
          }),
          ('start', 'book', {
              'id': 'bk001',
              'lang': 'en'
          }, {
Esempio n. 7
0
 def parse(self, source: Any) -> Any:
     return Books()