File: test_manager_context.py

package info (click to toggle)
python-django-postgres-extra 2.0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,096 kB
  • sloc: python: 9,057; makefile: 17; sh: 7; sql: 1
file content (20 lines) | stat: -rw-r--r-- 639 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
from django.db import models

from psqlextra.util import postgres_manager

from .fake_model import get_fake_model


def test_manager_context():
    """Tests whether the :see:postgres_manager context manager can be used to
    get access to :see:PostgresManager on a model that does not use it directly
    or inherits from :see:PostgresModel."""

    model = get_fake_model(
        {"myfield": models.CharField(max_length=255, unique=True)}, models.Model
    )

    with postgres_manager(model) as manager:
        manager.upsert(conflict_target=["myfield"], fields=dict(myfield="beer"))

        assert manager.first().myfield == "beer"