Statistics
| Branch: | Tag: | Revision:

root / snf-webproject / synnefo / webproject / management / tests.py @ d63a86d6

History | View | Annotate | Download (949 Bytes)

1 225cea18 Christos Stavrakakis
import sys
2 d3f6994d Christos Stavrakakis
from synnefo.webproject.management import utils
3 225cea18 Christos Stavrakakis
4 225cea18 Christos Stavrakakis
# Use backported unittest functionality if Python < 2.7
5 225cea18 Christos Stavrakakis
try:
6 225cea18 Christos Stavrakakis
    import unittest2 as unittest
7 225cea18 Christos Stavrakakis
except ImportError:
8 225cea18 Christos Stavrakakis
    if sys.version_info < (2, 7):
9 225cea18 Christos Stavrakakis
        raise Exception("The unittest2 package is required for Python < 2.7")
10 225cea18 Christos Stavrakakis
    import unittest
11 225cea18 Christos Stavrakakis
12 225cea18 Christos Stavrakakis
13 225cea18 Christos Stavrakakis
class ParseFiltersTestCase(unittest.TestCase):
14 225cea18 Christos Stavrakakis
    def test_parse_empty(self):
15 d3f6994d Christos Stavrakakis
        res = utils.parse_filters("")
16 225cea18 Christos Stavrakakis
        self.assertEqual(res, ({}, {}))
17 225cea18 Christos Stavrakakis
18 225cea18 Christos Stavrakakis
    def test_parse_one(self):
19 d3f6994d Christos Stavrakakis
        res = utils.parse_filters("x=2")
20 225cea18 Christos Stavrakakis
        self.assertEqual(res, ({"x": "2"}, {}))
21 d3f6994d Christos Stavrakakis
        res = utils.parse_filters("x!=2")
22 225cea18 Christos Stavrakakis
        self.assertEqual(res, ({}, {"x": "2"}))
23 225cea18 Christos Stavrakakis
24 225cea18 Christos Stavrakakis
    def test_parse_many(self):
25 d3f6994d Christos Stavrakakis
        res = utils.parse_filters("x=2,x>=3,y!=4,z<3")
26 225cea18 Christos Stavrakakis
        filters = {"x": "2", "x__gte": "3", "z__lt": "3"}
27 225cea18 Christos Stavrakakis
        excludes = {"y": "4"}
28 225cea18 Christos Stavrakakis
        self.assertEqual(res, (filters, excludes))
29 d3f6994d Christos Stavrakakis
30 d3f6994d Christos Stavrakakis
if __name__ == '__main__':
31 d3f6994d Christos Stavrakakis
    unittest.main()