test/unittest_utils.py
changeset 7762 a3f9ba4d44eb
parent 7569 02c338197322
child 7791 31bb51ea5485
equal deleted inserted replaced
7761:46a8cf85d186 7762:a3f9ba4d44eb
   157 
   157 
   158     def test_encoding_unknown_stuff(self):
   158     def test_encoding_unknown_stuff(self):
   159         self.assertEqual(self.encode(TestCase), 'null')
   159         self.assertEqual(self.encode(TestCase), 'null')
   160 
   160 
   161 class HTMLHeadTC(CubicWebTC):
   161 class HTMLHeadTC(CubicWebTC):
       
   162 
       
   163     def htmlhead(self, datadir_url):
       
   164         req = self.request()
       
   165         base_url = u'http://test.fr/data/'
       
   166         req.datadir_url = base_url
       
   167         head = HTMLHead(req)
       
   168         return head
       
   169 
   162     def test_concat_urls(self):
   170     def test_concat_urls(self):
   163         base_url = u'http://test.fr/data/'
   171         base_url = u'http://test.fr/data/'
   164         head = HTMLHead(base_url)
   172         head = self.htmlhead(base_url)
   165         urls = [base_url + u'bob1.js',
   173         urls = [base_url + u'bob1.js',
   166                 base_url + u'bob2.js',
   174                 base_url + u'bob2.js',
   167                 base_url + u'bob3.js']
   175                 base_url + u'bob3.js']
   168         result = head.concat_urls(urls)
   176         result = head.concat_urls(urls)
   169         expected = u'http://test.fr/data/??bob1.js,bob2.js,bob3.js'
   177         expected = u'http://test.fr/data/??bob1.js,bob2.js,bob3.js'
   170         self.assertEqual(result, expected)
   178         self.assertEqual(result, expected)
   171 
   179 
   172     def test_group_urls(self):
   180     def test_group_urls(self):
   173         base_url = u'http://test.fr/data/'
   181         base_url = u'http://test.fr/data/'
   174         head = HTMLHead(base_url)
   182         head = self.htmlhead(base_url)
   175         urls_spec = [(base_url + u'bob0.js', None),
   183         urls_spec = [(base_url + u'bob0.js', None),
   176                      (base_url + u'bob1.js', None),
   184                      (base_url + u'bob1.js', None),
   177                      (u'http://ext.com/bob2.js', None),
   185                      (u'http://ext.com/bob2.js', None),
   178                      (u'http://ext.com/bob3.js', None),
   186                      (u'http://ext.com/bob3.js', None),
   179                      (base_url + u'bob4.css', 'all'),
   187                      (base_url + u'bob4.css', 'all'),
   194                     ]
   202                     ]
   195         self.assertEqual(list(result), expected)
   203         self.assertEqual(list(result), expected)
   196 
   204 
   197     def test_getvalue_with_concat(self):
   205     def test_getvalue_with_concat(self):
   198         base_url = u'http://test.fr/data/'
   206         base_url = u'http://test.fr/data/'
   199         head = HTMLHead(base_url)
   207         head = self.htmlhead(base_url)
   200         head.add_js(base_url + u'bob0.js')
   208         head.add_js(base_url + u'bob0.js')
   201         head.add_js(base_url + u'bob1.js')
   209         head.add_js(base_url + u'bob1.js')
   202         head.add_js(u'http://ext.com/bob2.js')
   210         head.add_js(u'http://ext.com/bob2.js')
   203         head.add_js(u'http://ext.com/bob3.js')
   211         head.add_js(u'http://ext.com/bob3.js')
   204         head.add_css(base_url + u'bob4.css')
   212         head.add_css(base_url + u'bob4.css')
   222 </head>
   230 </head>
   223 """
   231 """
   224         self.assertEqual(result, expected)
   232         self.assertEqual(result, expected)
   225 
   233 
   226     def test_getvalue_without_concat(self):
   234     def test_getvalue_without_concat(self):
   227         base_url = u'http://test.fr/data/'
   235         self.config.global_set_option('concat-resources', False)
   228         head = HTMLHead()
   236         try:
   229         head.add_js(base_url + u'bob0.js')
   237             base_url = u'http://test.fr/data/'
   230         head.add_js(base_url + u'bob1.js')
   238             head = self.htmlhead(base_url)
   231         head.add_js(u'http://ext.com/bob2.js')
   239             head.add_js(base_url + u'bob0.js')
   232         head.add_js(u'http://ext.com/bob3.js')
   240             head.add_js(base_url + u'bob1.js')
   233         head.add_css(base_url + u'bob4.css')
   241             head.add_js(u'http://ext.com/bob2.js')
   234         head.add_css(base_url + u'bob5.css')
   242             head.add_js(u'http://ext.com/bob3.js')
   235         head.add_css(base_url + u'bob6.css', 'print')
   243             head.add_css(base_url + u'bob4.css')
   236         head.add_css(base_url + u'bob7.css', 'print')
   244             head.add_css(base_url + u'bob5.css')
   237         head.add_ie_css(base_url + u'bob8.css')
   245             head.add_css(base_url + u'bob6.css', 'print')
   238         head.add_ie_css(base_url + u'bob9.css', 'print', u'[if lt IE 7]')
   246             head.add_css(base_url + u'bob7.css', 'print')
   239         result = head.getvalue()
   247             head.add_ie_css(base_url + u'bob8.css')
   240         expected = u"""<head>
   248             head.add_ie_css(base_url + u'bob9.css', 'print', u'[if lt IE 7]')
       
   249             result = head.getvalue()
       
   250             expected = u"""<head>
   241 <link rel="stylesheet" type="text/css" media="all" href="http://test.fr/data/bob4.css"/>
   251 <link rel="stylesheet" type="text/css" media="all" href="http://test.fr/data/bob4.css"/>
   242 <link rel="stylesheet" type="text/css" media="all" href="http://test.fr/data/bob5.css"/>
   252 <link rel="stylesheet" type="text/css" media="all" href="http://test.fr/data/bob5.css"/>
   243 <link rel="stylesheet" type="text/css" media="print" href="http://test.fr/data/bob6.css"/>
   253 <link rel="stylesheet" type="text/css" media="print" href="http://test.fr/data/bob6.css"/>
   244 <link rel="stylesheet" type="text/css" media="print" href="http://test.fr/data/bob7.css"/>
   254 <link rel="stylesheet" type="text/css" media="print" href="http://test.fr/data/bob7.css"/>
   245 <!--[if lt IE 8]>
   255 <!--[if lt IE 8]>
   251 <script type="text/javascript" src="http://test.fr/data/bob1.js"></script>
   261 <script type="text/javascript" src="http://test.fr/data/bob1.js"></script>
   252 <script type="text/javascript" src="http://ext.com/bob2.js"></script>
   262 <script type="text/javascript" src="http://ext.com/bob2.js"></script>
   253 <script type="text/javascript" src="http://ext.com/bob3.js"></script>
   263 <script type="text/javascript" src="http://ext.com/bob3.js"></script>
   254 </head>
   264 </head>
   255 """
   265 """
   256         self.assertEqual(result, expected)
   266             self.assertEqual(result, expected)
       
   267         finally:
       
   268             self.config.global_set_option('concat-resources', True)
   257 
   269 
   258 class DocTest(DocTest):
   270 class DocTest(DocTest):
   259     from cubicweb import utils as module
   271     from cubicweb import utils as module
   260 
   272 
   261 if __name__ == '__main__':
   273 if __name__ == '__main__':