File: test_syncdb.py

package info (click to toggle)
python-django-pgtrigger 4.15.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 956 kB
  • sloc: python: 4,412; makefile: 114; sh: 8; sql: 2
file content (23 lines) | stat: -rw-r--r-- 911 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import pytest
from django.db import connection

import pgtrigger.tests.syncdb_app.models as syncdb_models
from pgtrigger.tests import utils


@pytest.mark.django_db
def test_create_model_creates_triggers():
    """
    Tests trigger installation with syncdb

    `DatabaseSchemaEditorMixin.create_model` is called when the django app doesn't
    have a migrations module. `DatabaseSchemaEditorMixin.create_model` is also called
    during a `CreateTable` migration operation but as the triggers aren't stored with
    the `CreateTable operation`, the specific code that creates triggers in
    `DatabaseSchemaEditorMixin.create_model` isn't executed.
    """
    with connection.schema_editor() as editor:
        editor.create_model(syncdb_models.NoMigrationModel)

    with utils.raises_trigger_error(match="no no no!"):
        syncdb_models.NoMigrationModel.objects.create(field="misc_insert", int_field=1)