def test_jinja_env_globals_raises_exception_if_no_ga_config(self):
        # given
        app = Mock()
        self.create_globals_mock(app)
        self.create_config_mock(app)

        # when
        initializer = AppInitializer(app)
        initializer.set_jinja_global_variables()

        # then
        self.assertFalse(self._globals['has_ga_infos'])
    def test_jinja_env_globals_raises_exception_if_no_ga_config(self):
        # given
        app = Mock()
        self.create_globals_mock(app)
        self.create_config_mock(app)

        # when
        initializer = AppInitializer(app)
        initializer.set_jinja_global_variables()

        # then
        self.assertFalse(self._globals['has_ga_infos'])
    def test_jinja_env_globals_raises_exception_if_domain_missing(self):
        # given
        app = Mock()
        self.create_globals_mock(app)

        self._config['GOOGLE_ANALYTICS_KEY'] = 'key'

        self.create_config_mock(app)

        # when
        initializer = AppInitializer(app)
        initializer.set_jinja_global_variables()

        # then
        self.assertFalse(self._globals['has_ga_infos'])
    def test_jinja_env_globals_raises_exception_if_domain_missing(self):
        # given
        app = Mock()
        self.create_globals_mock(app)

        self._config['GOOGLE_ANALYTICS_KEY'] = 'key'

        self.create_config_mock(app)

        # when
        initializer = AppInitializer(app)
        initializer.set_jinja_global_variables()

        # then
        self.assertFalse(self._globals['has_ga_infos'])
    def test_jinja_env_globals_has_correct_info_when_config_correct(self):
        # given
        app = Mock()
        self.create_globals_mock(app)

        self._config['GOOGLE_ANALYTICS_KEY'] = 'key'
        self._config['GOOGLE_ANALYTICS_DOMAIN'] = 'domain'

        self.create_config_mock(app)

        # when
        initializer = AppInitializer(app)
        initializer.set_jinja_global_variables()

        # then
        self.assertEquals(self._globals, {'has_ga_infos': True,
                                          'ga_key': 'key',
                                          'ga_domain': 'domain'
                                          })
    def test_jinja_env_globals_has_correct_info_when_config_correct(self):
        # given
        app = Mock()
        self.create_globals_mock(app)

        self._config['GOOGLE_ANALYTICS_KEY'] = 'key'
        self._config['GOOGLE_ANALYTICS_DOMAIN'] = 'domain'

        self.create_config_mock(app)

        # when
        initializer = AppInitializer(app)
        initializer.set_jinja_global_variables()

        # then
        self.assertEquals(self._globals, {
            'has_ga_infos': True,
            'ga_key': 'key',
            'ga_domain': 'domain'
        })