Example #1
0
    def test_elements_fields(self):
        options = adapters.ResourceAdapter(Book())._meta

        assert ([
            'title', 'isbn', 'num_pages', 'rrp', 'genre', 'published',
            'authors', 'publisher'
        ] == [f.name for f in options.element_fields])
Example #2
0
    def test_include_fields(self):
        book = Book(title="Foo", rrp=123.45, num_pages=10, fiction=True)

        target = adapters.ResourceAdapter(book, include=('title', 'rrp'))

        self.assertListEqual(['rrp', 'title'],
                             sorted(target._meta.field_map.keys()))
Example #3
0
    def test_field_proxy(self):
        target = adapters.ResourceAdapter(Book(title="Foo"))

        self.assertEqual(
            'Foo',
            target.title,
        )
Example #4
0
    def test_exclude_fields(self):
        book = Book(title="Foo", rrp=123.45, num_pages=10, fiction=True)

        target = adapters.ResourceAdapter(book, exclude=('title', 'rrp'))

        assert ([
            'authors', 'fiction', 'genre', 'isbn', 'num_pages', 'published',
            'publisher'
        ] == sorted(target._meta.field_map.keys()))
Example #5
0
    def test_iter(self):
        book = Book(title="Foo",
                    isbn='abc123',
                    rrp=123.45,
                    num_pages=10,
                    fiction=True)
        target = adapters.ResourceAdapter(book)

        actual = list((f.name, str(v)) for f, v in field_iter_items(target))
        assert [('title', 'Foo'), ('isbn', 'abc123'), ('num_pages', '10'),
                ('rrp', '123.45'), ('fiction', 'True'), ('genre', 'None'),
                ('published', '[]'), ('authors', '[]'),
                ('publisher', 'None')] == actual
Example #6
0
    def test_to_dict(self):
        publisher = Publisher()
        book = Book(title="Foo",
                    isbn='abc123',
                    rrp=123.45,
                    num_pages=10,
                    fiction=True,
                    publisher=publisher)
        target = adapters.ResourceAdapter(book)

        assert {
            'authors': [],
            'fiction': True,
            'genre': None,
            'num_pages': 10,
            'published': [],
            'publisher': publisher,
            'rrp': 123.45,
            'isbn': 'abc123',
            'title': 'Foo'
        } == target.to_dict()
Example #7
0
    def test_repr(self):
        options = adapters.ResourceAdapter(Book())._meta

        assert '<Options Adapter for library.Book>' == repr(options)
Example #8
0
    def test_repr(self):
        target = adapters.ResourceAdapter(Book(title="Foo"))

        assert '<ResourceAdapter: library.Book resource adapter>' == repr(
            target)
Example #9
0
    def test_field_proxy(self):
        target = adapters.ResourceAdapter(Book(title="Foo"))

        assert 'Foo' == target.title
Example #10
0
    def test_attribute_proxying(self):
        options = adapters.ResourceAdapter(Book())._meta

        assert "Book" == options.verbose_name
Example #11
0
    def test_attribute_fields(self):
        options = adapters.ResourceAdapter(Book())._meta

        assert ['fiction'] == [f.name for f in options.attribute_fields]
Example #12
0
    def test_repr(self):
        options = adapters.ResourceAdapter(Book())._meta

        self.assertEqual('<Options Adapter for library.Book>', repr(options))
Example #13
0
    def test_repr(self):
        target = adapters.ResourceAdapter(Book(title="Foo"))

        self.assertEqual('<ResourceAdapter: library.Book resource adapter>',
                         repr(target))
Example #14
0
    def test_attribute_proxying(self):
        options = adapters.ResourceAdapter(Book())._meta

        self.assertEqual("Book", options.verbose_name)
Example #15
0
    def test_attribute_fields(self):
        options = adapters.ResourceAdapter(Book())._meta

        self.assertListEqual(['fiction'],
                             [f.name for f in options.attribute_fields])