1
2 """NDG XACML functions unit tests
3
4 NERC DataGrid
5 """
6 __author__ = "P J Kershaw"
7 __date__ = "26/03/10"
8 __copyright__ = "(C) 2010 Science and Technology Facilities Council"
9 __contact__ = "Philip.Kershaw@stfc.ac.uk"
10 __license__ = "BSD - see LICENSE file in top-level directory"
11 __contact__ = "Philip.Kershaw@stfc.ac.uk"
12 __revision__ = "$Id: test_functions.py 8020 2012-02-23 12:35:19Z pjkersha $"
13 import unittest
14 import logging
15 logging.basicConfig(level=logging.DEBUG)
16
17 from ndg.xacml.core.functions import FunctionMap, AbstractFunction
18 from ndg.xacml.core.functions.v2.regexp_match import RegexpMatchBase
19 from ndg.xacml.core.context.exceptions import XacmlContextTypeError
20
21
23 class CustomFunctionAbstractFunction(AbstractFunction):
24 FUNCTION_NS = 'urn:ndg:xacml:test:integer-square'
25 def evaluate(self, num):
26 """square an integer
27
28 @param num: number to square
29 @type num: int
30 @rtype: int
31 @raise TypeError: incorrect type for input
32 """
33 if not isinstance(num, int):
34 raise XacmlContextTypeError('%r function expecting "int" type; '
35 'got %r' %
36 (self.__class__.FUNCTION_NS,
37 type(num)))
38
39 return num * num
40
41 if function_ns == CustomFunctionAbstractFunction.FUNCTION_NS:
42 return CustomFunctionAbstractFunction
43 else:
44 return None
45
46
48 """Test XACML functions implementation
49
50 The log output gives an indication of the XACML functions which are not
51 implemented yet"""
52
54 funcMap = FunctionMap()
55 funcMap.loadAllCore()
56 anyUriMatchNs = \
57 'urn:oasis:names:tc:xacml:2.0:function:anyURI-regexp-match'
58
59 self.assert_(issubclass(funcMap.get(anyUriMatchNs), RegexpMatchBase))
60
69
70 if __name__ == "__main__":
71 unittest.main()
72