cubicweb/test/unittest_utils.py
branch3.24
changeset 11917 c38e13988c10
parent 11715 760d5c0ae08f
child 12032 c16c1805e973
equal deleted inserted replaced
11909:244cd7f407b8 11917:c38e13988c10
     1 # copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # copyright 2003-2017 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 #
     3 #
     4 # This file is part of CubicWeb.
     4 # This file is part of CubicWeb.
     5 #
     5 #
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
    25 try:
    25 try:
    26     from unittest2 import TestCase
    26     from unittest2 import TestCase
    27 except ImportError:  # Python3
    27 except ImportError:  # Python3
    28     from unittest import TestCase
    28     from unittest import TestCase
    29 
    29 
       
    30 from six import PY2
    30 from six.moves import range
    31 from six.moves import range
    31 
    32 
    32 from cubicweb import Binary
    33 from cubicweb import Binary, Unauthorized
    33 from cubicweb.devtools.testlib import CubicWebTC
    34 from cubicweb.devtools.testlib import CubicWebTC
    34 from cubicweb.utils import (make_uid, UStringIO, RepeatList, HTMLHead,
    35 from cubicweb.utils import (make_uid, UStringIO, RepeatList, HTMLHead,
    35                             QueryCache, parse_repo_uri)
    36                             QueryCache, parse_repo_uri)
    36 from cubicweb.entity import Entity
    37 from cubicweb.entity import Entity
    37 
    38 
    38 try:
    39 try:
    39     from cubicweb.utils import CubicWebJsonEncoder, json
    40     from cubicweb.utils import CubicWebJsonEncoder, json
    40 except ImportError:
    41 except ImportError:
    41     json = None
    42     json = None
       
    43 
    42 
    44 
    43 class MakeUidTC(TestCase):
    45 class MakeUidTC(TestCase):
    44     def test_1(self):
    46     def test_1(self):
    45         self.assertNotEqual(make_uid('xyz'), make_uid('abcd'))
    47         self.assertNotEqual(make_uid('xyz'), make_uid('abcd'))
    46         self.assertNotEqual(make_uid('xyz'), make_uid('xyz'))
    48         self.assertNotEqual(make_uid('xyz'), make_uid('xyz'))
   323             self.assertEqual(result, expected)
   325             self.assertEqual(result, expected)
   324         finally:
   326         finally:
   325             self.config.global_set_option('concat-resources', True)
   327             self.config.global_set_option('concat-resources', True)
   326 
   328 
   327 
   329 
       
   330 def UnauthorizedTC(TestCase):
       
   331 
       
   332     def _test(self, func):
       
   333         self.assertEqual(func(Unauthorized()),
       
   334                          'You are not allowed to perform this operation')
       
   335         self.assertEqual(func(Unauthorized('a')),
       
   336                          'a')
       
   337         self.assertEqual(func(Unauthorized('a', 'b')),
       
   338                          'You are not allowed to perform a operation on b')
       
   339         self.assertEqual(func(Unauthorized('a', 'b', 'c')),
       
   340                          'a b c')
       
   341 
       
   342     def test_str(self):
       
   343         self._test(str)
       
   344 
       
   345     if PY2:
       
   346         def test_unicode(self):
       
   347             self._test(unicode)
       
   348 
       
   349 
   328 def load_tests(loader, tests, ignore):
   350 def load_tests(loader, tests, ignore):
   329     import cubicweb.utils
   351     import cubicweb.utils
   330     tests.addTests(doctest.DocTestSuite(cubicweb.utils))
   352     tests.addTests(doctest.DocTestSuite(cubicweb.utils))
   331     return tests
   353     return tests
   332 
   354