Example #1
0
from rethinkmodel.manage import manage
from rethinkmodel.model import Model

from tests.utils import clean

DB_NAME = "test_feed"


class FeededUser(Model):
    """A simple user."""

    name: str
    pointer: Optional[str]


clean(DB_NAME)


class FeedTest(TestCase):
    """Make some test on feed."""

    def setUp(self) -> None:
        """Manage table."""
        config(dbname=DB_NAME)
        manage(__name__)
        return super().setUp()

    def test_feed_get(self):
        """Test to detect table change."""
        first_call_name = "first"
        second_call_name = "second"
Example #2
0
class Gallery(Model):
    """A Gallery with linked User."""

    name: Type[str]
    contributors: List[User]


class Image(Model):
    """Image is linked to a Gallery."""

    name: Type[str]
    gallery: Type[Gallery]


utils.clean("tests_one_to_many")


class TestOneToMany(TestCase):
    """Test one to many relations."""
    def setUp(self) -> None:
        """Configure DB and create tables."""
        config(dbname="tests_one_to_many")
        manage(__name__)
        return super().setUp()

    def test_relations(self):
        """Test to create a Galley with images."""
        users = []
        for i in range(2):
            user = User(name=f"User{i}")
Example #3
0
from rethinkmodel import config, db
from rethinkmodel.db import connect
from rethinkmodel.manage import introspect
from rethinkmodel.model import Model

from tests import utils


class ManagedTable(Model):
    """To check if the table is well created."""

    name: str


utils.clean("test_manage")


class ManageTest(unittest.TestCase):
    """Test the manage module."""
    def setUp(self) -> None:
        """Confugure database."""
        config(dbname="test_manage")
        return super().setUp()

    def test_introspect(self):
        """Test the module introspection from path."""
        introspect(__file__)
        rdb, conn = connect()
        tables = rdb.db(db.DB_NAME).table_list().run(conn)
        conn.close()
Example #4
0
        logging.getLogger(LOGGER_NAME).info("event deleted")

    def on_modified(self):
        """Call on modified."""
        logging.getLogger(LOGGER_NAME).info("event modified")


class SimpleType(Model):
    """Simple type linked to User."""

    user: User
    name: str
    age: int


utils.clean("test_generic")


class GenericTest(unittest.TestCase):
    """Make som generic tests."""
    def setUp(self) -> None:
        """Configure database and create tables."""
        config(dbname="test_generic")
        manage(__name__)
        return super().setUp()

    def test_generate_tablename_numeric(self):
        """Check if table name ended by a number is not changed."""
        foo = ANumericEnded1(foo="test")
        self.assertEqual(foo.tablename, "anumericended1")