File: test_table_name.py

package info (click to toggle)
python-sqlalchemy-utils 0.30.12-2~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 1,056 kB
  • sloc: python: 10,350; makefile: 160
file content (26 lines) | stat: -rw-r--r-- 776 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
import sqlalchemy as sa

from sqlalchemy_utils import table_name
from tests import TestCase


class TestTableName(TestCase):
    def create_models(self):
        class Building(self.Base):
            __tablename__ = 'building'
            id = sa.Column(sa.Integer, primary_key=True)
            name = sa.Column(sa.Unicode(255))

        self.Building = Building

    def test_class(self):
        assert table_name(self.Building) == 'building'
        del self.Building.__tablename__
        assert table_name(self.Building) == 'building'

    def test_attribute(self):
        assert table_name(self.Building.id) == 'building'
        assert table_name(self.Building.name) == 'building'

    def test_target(self):
        assert table_name(self.Building()) == 'building'