File: test_shortuuid_field.py

package info (click to toggle)
python-django-extensions 4.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,812 kB
  • sloc: python: 18,601; javascript: 7,354; makefile: 108; xml: 17
file content (36 lines) | stat: -rw-r--r-- 1,232 bytes parent folder | download | duplicates (2)
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
# -*- coding: utf-8 -*-

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="vytxeTZskVKR7C7WgdSP3d"
        )
        self.assertEqual(j.uuid_field, "vytxeTZskVKR7C7WgdSP3d")

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

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

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