source: main/waeup.ikoba/trunk/src/waeup/ikoba/utils/tests/test_idgen.py @ 12254

Last change on this file since 12254 was 12254, checked in by uli, 10 years ago

Move idgen tests to utils.

File size: 1.4 KB
Line 
1import re
2import unittest
3from zope.component import queryUtility
4from zope.interface.verify import verifyClass, verifyObject
5from waeup.ikoba.testing import FunctionalLayer, FunctionalTestCase
6from waeup.ikoba.idgen import IIDSource, IDSource
7
8
9# format of raw uuids (36 chars including 4 hyphens)
10RE_FORMAT_UUID = re.compile(
11    "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
12    )
13
14# format of hex uuids (32 chars)
15RE_FORMAT_HEX_UUID = re.compile("^[0-9a-f]{32}$")
16
17
18class IDGeneratorTests(unittest.TestCase):
19
20    def test_iface(self):
21        # we fullfill any interface contracts
22        src = IDSource()
23        verifyClass(IIDSource, IDSource)
24        verifyObject(IIDSource, src)
25
26    def test_get_uuid(self):
27        # we can get universally unique identifiers
28        src = IDSource()
29        result = src.get_uuid()
30        assert(RE_FORMAT_UUID.match(result))
31        assert src.get_uuid() != result
32
33    def test_get_hex_uuid(self):
34        # we can get UUIDs as hex strings
35        src = IDSource()
36        result = src.get_hex_uuid()
37        assert (RE_FORMAT_HEX_UUID.match(result))
38        assert src.get_hex_uuid() != result
39
40
41class FunctionalIDSourceTests(FunctionalTestCase):
42
43    layer = FunctionalLayer
44
45    def test_IIDSource_utility_registered(self):
46        # an IIDSource is registered on startup
47        util = queryUtility(IIDSource)
48        assert util is not None
Note: See TracBrowser for help on using the repository browser.