File: test_shortuuid_field.py

package info (click to toggle)
python-django-extensions 2.1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,396 kB
  • sloc: python: 11,858; makefile: 116
file content (30 lines) | stat: -rw-r--r-- 1,259 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
24
25
26
27
28
29
30
# -*- coding: utf-8 -*-
import six
from django.test import TestCase

from .testapp.models import (
    ShortUUIDTestAgregateModel, ShortUUIDTestManyToManyModel,
    ShortUUIDTestModel_field, ShortUUIDTestModel_pk,
)


class ShortUUIDFieldTest(TestCase):
    def test_UUID_field_create(self):
        j = ShortUUIDTestModel_field.objects.create(a=6, uuid_field=six.u('vytxeTZskVKR7C7WgdSP3d'))
        self.assertEqual(j.uuid_field, six.u('vytxeTZskVKR7C7WgdSP3d'))

    def test_UUID_field_pk_create(self):
        j = ShortUUIDTestModel_pk.objects.create(uuid_field=six.u('vytxeTZskVKR7C7WgdSP3d'))
        self.assertEqual(j.uuid_field, six.u('vytxeTZskVKR7C7WgdSP3d'))
        self.assertEqual(j.pk, six.u('vytxeTZskVKR7C7WgdSP3d'))

    def test_UUID_field_pk_agregate_create(self):
        j = ShortUUIDTestAgregateModel.objects.create(a=6)
        self.assertEqual(j.a, 6)
        self.assertIsInstance(j.pk, six.string_types)
        self.assertTrue(len(j.pk) < 23)

    def test_UUID_field_manytomany_create(self):
        j = ShortUUIDTestManyToManyModel.objects.create(uuid_field=six.u('vytxeTZskVKR7C7WgdSP3e'))
        self.assertEqual(j.uuid_field, six.u('vytxeTZskVKR7C7WgdSP3e'))
        self.assertEqual(j.pk, six.u('vytxeTZskVKR7C7WgdSP3e'))