~charmers/charms/trusty/apache2/trunk

« back to all changes in this revision

Viewing changes to hooks/tests/test_balancer_hook.py

  • Committer: Marco Ceppi
  • Date: 2014-01-16 13:46:52 UTC
  • mfrom: (50.1.1 apache2-cs-jjo)
  • Revision ID: marco@ceppi.net-20140116134652-vaofgo4xqh3np65t
[jjo] support apache 2.4 config filenames

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from pprint import pformat
2
2
import os
3
3
import shutil
4
 
from StringIO import StringIO
5
4
import tempfile
6
5
import yaml
7
6
 
438
437
        self.assertFalse(service_apache2.called)
439
438
        self.assertFalse(log.called)
440
439
 
 
440
    @patch('subprocess.call')
 
441
    @patch('hooks.is_apache24')
441
442
    @patch('hooks.config_get')
442
443
    @patch('hooks.log')
443
 
    def test_writes_balancer_config(self, log, config_get):
 
444
    def test_writes_balancer_config(self, log, config_get,
 
445
                                    is_apache24, mock_call):
444
446
        config_get.return_value = {
445
447
            'lb_balancer_timeout': 123,
446
448
        }
448
450
            'foo': ['10.11.12.13'],
449
451
            'bar': ['10.11.12.14', '10.11.12.15'],
450
452
        }
451
 
        with patch('hooks.default_apache2_config_dir', self.tempdir):
 
453
        # Apache 2.4:
 
454
        mock_call.return_value = 0
 
455
        is_apache24.return_value = True
 
456
        with patch('hooks.default_apache24_config_dir', self.tempdir):
 
457
            hooks.write_balancer_config(balancer_config)
 
458
        for balancer in balancer_config.keys():
 
459
            basename = '%s.balancer' % balancer
 
460
            exp_path = os.path.join(FIXTURES, basename)
 
461
            res_path = os.path.join(self.tempdir, "{}.conf".format(basename))
 
462
            with open(exp_path) as exp, open(res_path) as res:
 
463
                self.assertEqual(exp.read(), res.read())
 
464
        mock_call.assert_called_with(['/usr/sbin/a2enconf', basename])
 
465
 
 
466
        # Apache 2.2:
 
467
        mock_call.reset_mock()
 
468
        is_apache24.return_value = False
 
469
        with patch('hooks.default_apache22_config_dir', self.tempdir):
452
470
            hooks.write_balancer_config(balancer_config)
453
471
        for balancer in balancer_config.keys():
454
472
            basename = '%s.balancer' % balancer
456
474
            res_path = os.path.join(self.tempdir, basename)
457
475
            with open(exp_path) as exp, open(res_path) as res:
458
476
                self.assertEqual(exp.read(), res.read())
 
477
        # assert no external commands called
 
478
        self.assertItemsEqual(mock_call.call_args_list, [])
459
479
 
460
480
 
461
481
class HooksTest(TestCase):