from ckan.tests import helpers as test_helpers, factories
from ckan import plugins

from ckanext.tayside import helpers as tayside_helpers


class ActionBase(object):
    @classmethod
    def setup_class(self):
        if not plugins.plugin_loaded('tayside'):
            plugins.load('tayside')

    def setup(self):
        test_helpers.reset_db()

    @classmethod
    def teardown_class(self):
        if plugins.plugin_loaded('tayside'):
            plugins.unload('tayside')


class TestHelpers(ActionBase):
    def test_get_groups(self):
        group1 = factories.Group()
        group2 = factories.Group()

        for i in range(1):
            dataset = factories.Dataset(groups=[{'id': group1.get('id')}])

        for i in range(3):
            dataset = factories.Dataset(groups=[{'id': group2.get('id')}])

        groups = tayside_helpers.get_groups()

        assert groups[0].get('id') == group2.get('id')
        assert groups[1].get('id') == group1.get('id')
        assert groups[0].get('package_count') > groups[1].get('package_count')

@@ -75,16 +75,47 @@
  plugins
+%0Afrom ckan.common import config
 %0A%0Afrom c
@@ -1082,8 +1082,595 @@
 count')%0A
+%0A    def test_get_footer_logos(self):%0A        config%5B'footer_logo_1_image_url'%5D = 'http://example.com/image.png'%0A        config%5B'footer_logo_1_link_url'%5D = 'http://google.com'%0A        config%5B'footer_logo_1_text'%5D = 'some text'%0A%0A        logos = tayside_helpers.get_footer_logos()%0A%0A        assert len(logos) == 1%0A        assert logos%5B0%5D.get('logo_image_url') ==%5C%0A            config%5B'footer_logo_1_image_url'%5D%0A        assert logos%5B0%5D.get('logo_link_url') ==%5C%0A            config%5B'footer_logo_1_link_url'%5D%0A        assert logos%5B0%5D.get('logo_text') ==%5C%0A            config%5B'footer_logo_1_text'%5D%0A

Add test for footer logos