File: test_uuid_length.py

package info (click to toggle)
python-django-guid 3.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 664 kB
  • sloc: python: 1,267; makefile: 16
file content (30 lines) | stat: -rw-r--r-- 972 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
from django.conf import settings as django_settings
from django.test import override_settings

import pytest

from django_guid.utils import generate_guid


def test_uuid_length():
    """
    Make sure passing uuid_length works.
    """
    for i in range(33):
        guid = generate_guid(uuid_length=i)
        assert len(guid) == i


@pytest.mark.parametrize('maximum_range,uuid_format,expected_type', [(33, 'hex', str), (37, 'string', str)])
def test_uuid_length_setting(maximum_range, uuid_format, expected_type):
    """
    Make sure that the settings value is used as a default.
    """
    mocked_settings = django_settings.DJANGO_GUID
    mocked_settings['UUID_FORMAT'] = uuid_format
    for uuid_lenght in range(33):
        mocked_settings['UUID_LENGTH'] = uuid_lenght
        with override_settings(DJANGO_GUID=mocked_settings):
            guid = generate_guid()
            assert isinstance(guid, expected_type)
            assert len(guid) == uuid_lenght