Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (949 Bytes)

1
import sys
2
from synnefo.webproject.management import utils
3

    
4
# Use backported unittest functionality if Python < 2.7
5
try:
6
    import unittest2 as unittest
7
except ImportError:
8
    if sys.version_info < (2, 7):
9
        raise Exception("The unittest2 package is required for Python < 2.7")
10
    import unittest
11

    
12

    
13
class ParseFiltersTestCase(unittest.TestCase):
14
    def test_parse_empty(self):
15
        res = utils.parse_filters("")
16
        self.assertEqual(res, ({}, {}))
17

    
18
    def test_parse_one(self):
19
        res = utils.parse_filters("x=2")
20
        self.assertEqual(res, ({"x": "2"}, {}))
21
        res = utils.parse_filters("x!=2")
22
        self.assertEqual(res, ({}, {"x": "2"}))
23

    
24
    def test_parse_many(self):
25
        res = utils.parse_filters("x=2,x>=3,y!=4,z<3")
26
        filters = {"x": "2", "x__gte": "3", "z__lt": "3"}
27
        excludes = {"y": "4"}
28
        self.assertEqual(res, (filters, excludes))
29

    
30
if __name__ == '__main__':
31
    unittest.main()