File: test_url.py

package info (click to toggle)
python-sqlalchemy-utils 0.41.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,252 kB
  • sloc: python: 13,566; makefile: 141
file content (46 lines) | stat: -rw-r--r-- 1,154 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import pytest
import sqlalchemy as sa

from sqlalchemy_utils.compat import _select_args
from sqlalchemy_utils.types import url


@pytest.fixture
def User(Base):
    class User(Base):
        __tablename__ = 'user'
        id = sa.Column(sa.Integer, primary_key=True)
        website = sa.Column(url.URLType)

        def __repr__(self):
            return 'User(%r)' % self.id
    return User


@pytest.fixture
def init_models(User):
    pass


@pytest.mark.skipif('url.furl is None')
class TestURLType:
    def test_color_parameter_processing(self, session, User):
        user = User(
            website=url.furl('www.example.com')
        )

        session.add(user)
        session.commit()

        user = session.query(User).first()
        assert isinstance(user.website, url.furl)

    def test_scalar_attributes_get_coerced_to_objects(self, User):
        user = User(website='www.example.com')

        assert isinstance(user.website, url.furl)

    def test_compilation(self, User, session):
        query = sa.select(*_select_args(User.website))
        # the type should be cacheable and not throw exception
        session.execute(query)