"""This module holds admin tests for ``themes`` app."""

from mtp.apps.common.tests.test_cases import MTPTestCase
from mtp.apps.themes.models import Theme

from ..admin import duplicate


class ThemeAdminTestCase(MTPTestCase):
    """Test the admin class for ``theme`` model."""

    def test_duplicate(self):
        """Test the ``duplicate`` action."""

        # We should have only one theme
        self.assertEqual(Theme.objects.count(), 1)

        # We duplicate our theme
        duplicate(None, None, [self.theme])

        themes = Theme.objects.all()

        # We should have 2 themes now
        self.assertEqual(themes.count(), 2)

        # We check the new theme is a duplicate of first theme
        self.assertEqual(themes[1].name, "%s (2)" % themes[0].name)
        self.assertEqual(themes[1].main, themes[0].main)

        # We duplicate again our theme
        duplicate(None, None, [self.theme])

        themes = Theme.objects.all()

        # We should have 3 themes now
        self.assertEqual(themes.count(), 3)

        # We check the new theme is a duplicate of first theme
        self.assertEqual(themes[2].name, "%s (3)" % themes[0].name)
        self.assertEqual(themes[2].main, themes[0].main)
