~charmers/charms/trusty/apache2/trunk

« back to all changes in this revision

Viewing changes to tests/test_balancer_hook.py

  • Committer: Diogo Baeder de Paula Pinto
  • Date: 2013-02-04 22:56:27 UTC
  • mto: (27.2.15 apache2)
  • mto: This revision was merged to the branch mainline in revision 46.
  • Revision ID: diogobaeder@canonical.com-20130204225627-djxtju4uyvto1igm
Covering write_balancer_config

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from pprint import pformat
2
2
import os
 
3
import tempfile
3
4
import yaml
4
5
 
5
6
from testtools import TestCase
8
9
import hooks
9
10
 
10
11
 
 
12
FIXTURES = os.path.join(os.path.dirname(__file__), 'fixtures')
 
13
 
 
14
 
11
15
class BalancerRelationTest(TestCase):
12
16
 
13
17
    def setUp(self):
503
507
        self.assertFalse(service_apache2.called)
504
508
        self.assertFalse(log.called)
505
509
 
 
510
    @patch('hooks.config_get')
 
511
    def test_writes_balancer_config(self, config_get):
 
512
        config_get.return_value = {
 
513
            'lb_balancer_timeout': 123,
 
514
        }
 
515
        tempdir = tempfile.mkdtemp()
 
516
        balancer_config = {
 
517
            'foo': ['10.11.12.13'],
 
518
            'bar': ['10.11.12.14', '10.11.12.15'],
 
519
        }
 
520
        with patch('hooks.default_apache2_config_dir', tempdir):
 
521
            hooks.write_balancer_config(balancer_config)
 
522
        for balancer in balancer_config.keys():
 
523
            basename = '%s.balancer' % balancer
 
524
            exp_path = os.path.join(FIXTURES, basename)
 
525
            res_path = os.path.join(tempdir, basename)
 
526
            with open(exp_path) as exp, open(res_path) as res:
 
527
                self.assertEqual(exp.read(), res.read())
 
528
 
506
529
 
507
530
class HooksTest(TestCase):
508
531
    def setUp(self):