630
636
self.assertEqual(self.service_names, ['juju-api-agent'])
631
637
self.assertEqual(self.actions, [charmhelpers.START])
633
def test_start_gui(self):
634
ssl_cert_path = '/tmp/certificates/'
635
charmworld_url = 'http://charmworld.example'
637
False, 'This is login help.', True, True, ssl_cert_path,
638
charmworld_url, True, haproxy_path='haproxy',
639
config_js_path='config', use_analytics=True)
640
haproxy_conf = self.files['haproxy']
641
self.assertIn('ca-base {0}'.format(ssl_cert_path), haproxy_conf)
642
self.assertIn('crt-base {0}'.format(ssl_cert_path), haproxy_conf)
643
self.assertIn('ws1 127.0.0.1:{0}'.format(API_PORT), haproxy_conf)
644
self.assertIn('web1 127.0.0.1:{0}'.format(WEB_PORT), haproxy_conf)
645
self.assertIn('ca-file {0}'.format(JUJU_PEM), haproxy_conf)
646
self.assertIn('crt {0}'.format(JUJU_PEM), haproxy_conf)
647
self.assertIn('redirect scheme https', haproxy_conf)
639
def test_compute_build_dir(self):
640
for (in_staging, serve_tests, result) in (
641
(False, False, 'build-prod'),
642
(True, False, 'build-debug'),
643
(False, True, 'build-prod'),
644
(True, True, 'build-prod'),
646
build_dir = compute_build_dir(in_staging, serve_tests)
648
result, build_dir, 'in_staging: {}, serve_tests: {}'.format(
649
in_staging, serve_tests))
651
def test_write_gui_config(self):
653
False, 'This is login help.', True, True, self.charmworld_url,
654
self.build_dir, use_analytics=True, config_js_path='config')
648
655
js_conf = self.files['config']
649
656
self.assertIn('consoleEnabled: false', js_conf)
650
657
self.assertIn('user: "admin"', js_conf)
655
662
self.assertIn('socket_protocol: "wss"', js_conf)
656
663
self.assertIn('charmworldURL: "http://charmworld.example"', js_conf)
657
664
self.assertIn('useAnalytics: true', js_conf)
666
def test_write_haproxy_config(self):
667
write_haproxy_config(self.ssl_cert_path, haproxy_path='haproxy')
668
haproxy_conf = self.files['haproxy']
669
self.assertIn('ca-base {0}'.format(self.ssl_cert_path), haproxy_conf)
670
self.assertIn('crt-base {0}'.format(self.ssl_cert_path), haproxy_conf)
671
self.assertIn('ws1 127.0.0.1:{0}'.format(API_PORT), haproxy_conf)
672
self.assertIn('web1 127.0.0.1:{0}'.format(WEB_PORT), haproxy_conf)
673
self.assertIn('ca-file {0}'.format(JUJU_PEM), haproxy_conf)
674
self.assertIn('crt {0}'.format(JUJU_PEM), haproxy_conf)
675
self.assertIn('redirect scheme https', haproxy_conf)
677
def test_write_apache_config(self):
678
write_apache_config(self.build_dir, serve_tests=True)
658
679
apache_conf = self.files['juju-gui']
659
680
self.assertIn('juju-gui/build-', apache_conf)
660
681
self.assertIn('VirtualHost *:{0}'.format(WEB_PORT), apache_conf)
662
683
'Alias /test {0}/test/'.format(JUJU_GUI_DIR), apache_conf)
664
def test_start_gui_insecure(self):
665
ssl_cert_path = '/tmp/certificates/'
666
charmworld_url = 'http://charmworld.example'
668
False, 'This is login help.', True, True, ssl_cert_path,
669
charmworld_url, True, haproxy_path='haproxy',
670
config_js_path='config', secure=False)
685
def test_write_gui_config_insecure(self):
687
False, 'This is login help.', True, True, self.charmworld_url,
688
self.build_dir, secure=False, config_js_path='config')
671
689
js_conf = self.files['config']
672
690
self.assertIn("socket_url: 'ws://", js_conf)
673
691
self.assertIn('socket_protocol: "ws"', js_conf)
674
haproxy_conf = self.files['haproxy']
693
def test_write_haproxy_config_insecure(self):
694
write_haproxy_config(
695
self.ssl_cert_path, secure=False, haproxy_path='haproxy')
675
696
# The insecure approach eliminates the https redirect.
676
self.assertNotIn('redirect scheme https', haproxy_conf)
697
self.assertNotIn('redirect scheme https', self.files['haproxy'])
678
def test_start_gui_sandbox(self):
679
ssl_cert_path = '/tmp/certificates/'
680
charmworld_url = 'http://charmworld.example'
682
False, 'This is login help.', False, False, ssl_cert_path,
683
charmworld_url, True, haproxy_path='haproxy',
684
config_js_path='config', sandbox=True)
699
def test_write_gui_config_sandbox(self):
701
False, 'This is login help.', False, False, self.charmworld_url,
702
self.build_dir, sandbox=True, config_js_path='config')
685
703
js_conf = self.files['config']
686
704
self.assertIn('sandbox: true', js_conf)
687
705
self.assertIn('user: "admin"', js_conf)
688
706
self.assertIn('password: "admin"', js_conf)
690
def test_start_gui_no_analytics(self):
691
ssl_cert_path = '/tmp/certificates/'
692
charmworld_url = 'http://charmworld.example'
694
False, 'This is login help.', False, False, ssl_cert_path,
695
charmworld_url, True, haproxy_path='haproxy',
696
config_js_path='config', use_analytics=False)
697
js_conf = self.files['config']
698
self.assertIn('useAnalytics: false', js_conf)
700
def test_start_gui_fullscreen(self):
701
ssl_cert_path = '/tmp/certificates/'
702
charmworld_url = 'http://charmworld.example'
704
False, 'This is login help.', False, False, ssl_cert_path,
705
charmworld_url, True, haproxy_path='haproxy',
706
config_js_path='config', sandbox=True,
707
default_viewmode='fullscreen')
708
js_conf = self.files['config']
709
self.assertIn('defaultViewmode: "fullscreen"', js_conf)
711
def test_start_gui_with_button(self):
712
ssl_cert_path = '/tmp/certificates/'
713
charmworld_url = 'http://charmworld.example'
715
False, 'This is login help.', False, False, ssl_cert_path,
716
charmworld_url, True, haproxy_path='haproxy',
717
config_js_path='config', sandbox=True,
718
show_get_juju_button=True)
719
js_conf = self.files['config']
720
self.assertIn('showGetJujuButton: true', js_conf)
708
def test_write_gui_config_no_analytics(self):
710
False, 'This is login help.', False, False, self.charmworld_url,
711
self.build_dir, use_analytics=False, config_js_path='config')
712
self.assertIn('useAnalytics: false', self.files['config'])
714
def test_write_gui_config_fullscreen(self):
716
False, 'This is login help.', False, False, self.charmworld_url,
717
self.build_dir, sandbox=True, default_viewmode='fullscreen',
718
config_js_path='config')
719
self.assertIn('defaultViewmode: "fullscreen"', self.files['config'])
721
def test_write_gui_config_with_button(self):
723
False, 'This is login help.', False, False, self.charmworld_url,
724
self.build_dir, sandbox=True, show_get_juju_button=True,
725
config_js_path='config')
726
self.assertIn('showGetJujuButton: true', self.files['config'])
723
729
class TestNpmCache(unittest.TestCase):