"""
Unittests for the opal.templatetags.plugins module
"""
from mock import patch, MagicMock

from opal.core import plugins
from opal.core.test import OpalTestCase
from opal.templatetags import plugins as opalplugins

class TestPlugin(plugins.OpalPlugin):
    javascripts = {
        'opal.test': ['js/test/notreal.js']
    }
    stylesheets = ['css/test/notreal.css']
    head_extra = ['notareal_template.html']
    menuitems =[ { 'display': 'test' } ]
    angular_module_deps = ['js/test.angular.mod.js']


class PluginJavascriptsTestCase(OpalTestCase):

    @patch('opal.templatetags.plugins.plugins.plugins')
    def test_plugin_javascripts(self, plugins):
        plugins.return_value = [TestPlugin]
        result = opalplugins.plugin_javascripts('opal.test')
        javascripts = [j for j in result['javascripts']()]
        expected = [
            'js/test/notreal.js'
        ]
        self.assertEqual(expected, javascripts)


class PluginStylesheetsTestCase(OpalTestCase):

    @patch('opal.templatetags.plugins.plugins.plugins')
    def test_plugin_stylesheets(self, plugins):
        plugins.return_value = [TestPlugin]
        css = list(opalplugins.plugin_stylesheets()['styles']())
        self.assertIn('css/test/notreal.css', css)


class PluginHeadExtraTestCase(OpalTestCase):

    @patch('opal.templatetags.plugins.plugins.plugins')
    def test_plugin_head_extra(self, plugins):
        plugins.return_value = [TestPlugin]
        context = opalplugins.plugin_head_extra({})
        templates = list(context['head_extra']())
        self.assertEqual(['notareal_template.html'], templates)


class MenuItemOrderingTest(OpalTestCase):
    def test_with_fields_some_with_index(self):
        td = [
            dict(display="a", index=10),
            dict(display="b", index=10),
            dict(display="c", index=9),
            dict(display="d"),
        ]
        self.assertEqual(opalplugins.sort_menu_items(td), [td[2], td[0], td[1], td[3]])


class PluginMenuitemsTestCase(OpalTestCase):

    @patch('opal.templatetags.plugins.plugins.plugins')
    def test_plugin_menuitems(self, plugins):
        plugins.return_value = [TestPlugin]
        menuitems = opalplugins.plugin_menuitems()['items']
        expected = [{'display': 'test'}]
        self.assertEqual(expected, menuitems)


class PluginAngularDepsTestCase(OpalTestCase):

    @patch('opal.templatetags.plugins.plugins.plugins')
    def test_plugin_angular_deps(self, plugins):
        plugins.return_value = [TestPlugin]
        deps = list(opalplugins.plugin_opal_angular_deps()['deps']())
        expected = ['js/test.angular.mod.js']
        self.assertEqual(expected, deps)

@@ -2660,8 +2660,595 @@
 , deps)%0A
+%0Aclass PluginOPALAngularTrackingExcludeTestCase(OpalTestCase):%0A%0A    @patch('opal.templatetags.plugins.plugins.plugins')%0A    def test_prefixes(self, plugins):%0A        plugins.return_value = %5BTestPlugin%5D%0A        expected_prefix = %5B%5D%0A        expected_qs = %5B%0A            %22/search%22,%0A            %22/extract%22,%0A        %5D%0A        context = opalplugins.plugin_opal_angular_tracking_exclude()%0A        prefixes = list(context%5B'excluded_tracking_prefix'%5D)%0A        qs = list(context%5B'excluded_tracking_qs'%5D)%0A        self.assertEqual(expected_prefix, prefixes)%0A        self.assertEqual(expected_qs, qs)%0A

Add tests to analytics exclude paths templatetag