1 | import re |
---|
2 | import unittest |
---|
3 | from zope.component import queryUtility |
---|
4 | from zope.interface.verify import verifyClass, verifyObject |
---|
5 | from waeup.ikoba.testing import FunctionalLayer, FunctionalTestCase |
---|
6 | from waeup.ikoba.idgen import IIDSource, IDSource |
---|
7 | |
---|
8 | |
---|
9 | # format of raw uuids (36 chars including 4 hyphens) |
---|
10 | RE_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) |
---|
15 | RE_FORMAT_HEX_UUID = re.compile("^[0-9a-f]{32}$") |
---|
16 | |
---|
17 | |
---|
18 | class 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 | |
---|
41 | class 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 |
---|