File: test_custom_base_class.py

package info (click to toggle)
sqlalchemy-i18n 1.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 396 kB
  • sloc: python: 2,164; makefile: 157
file content (38 lines) | stat: -rw-r--r-- 1,062 bytes parent folder | download | duplicates (4)
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
# -*- coding: utf-8 -*-

import sqlalchemy as sa

from sqlalchemy_i18n import Translatable, translation_base
from tests import DeclarativeTestCase


class Suite(object):
    def test_translatable_dict_copied_to_each_child_class(self):
        assert issubclass(self.ArticleTranslation, self.TranslationBase)


class TestDeclarative(Suite, DeclarativeTestCase):
    def create_models(self):
        class Base(self.Model):
            __abstract__ = True
            __versioned__ = {}

        class Article(self.Model, Translatable):
            __tablename__ = 'article'
            id = sa.Column(
                sa.Integer, primary_key=True
            )

        class ArticleTranslation(
            translation_base(Article, base_class_factory=lambda cls: Base)
        ):
            __tablename__ = 'article_translation'

            name = sa.Column(sa.Unicode(255))

        self.TranslationBase = Base
        self.Article = Article
        self.ArticleTranslation = ArticleTranslation


# This is the common case in Classic mapping, no test needed