summaryrefslogtreecommitdiffstats
path: root/askbot/tests/skin_tests.py
blob: ecbea77da925890d58cd78b90f401c8601c48f53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import os
import shutil
from django.test import TestCase
from django.core.files.uploadedfile import UploadedFile
from django.conf import settings as django_settings
from askbot.conf import settings as askbot_settings
from askbot.utils.path import mkdir_p
from askbot.skins import utils as skin_utils
import askbot

class SkinTests(TestCase):

    def setUp(self):
        #create dummy skin
        skin_image_dir = os.path.join(
                            askbot.get_install_directory(),
                            'skins',
                            'test_skin',
                            'media',
                            'images'
                        )
        mkdir_p(skin_image_dir)
        test_image_file = os.path.join(
                            askbot.get_install_directory(),
                            'tests',
                            'images',
                            'logo.gif'
                        )
        shutil.copy(test_image_file, skin_image_dir)

    def tearDown(self):
        #delete the dummy skin
        test_skin_dir = os.path.join(
                            askbot.get_install_directory(),
                            'skins',
                            'test_skin'
                        )
        shutil.rmtree(test_skin_dir)
        askbot_settings.update('ASKBOT_DEFAULT_SKIN', 'default')

    def assert_default_logo_in_skin(self, skin_name):
        url = skin_utils.get_media_url(askbot_settings.SITE_LOGO_URL)
        self.assertTrue('/' + skin_name + '/' in url)
        response = self.client.get(url)
        self.assertTrue(response.status_code == 200)

    def test_default_skin_logo(self):
        """make sure that default logo
        is where it is expected
        """
        self.assert_default_logo_in_skin('default')

    def test_switch_to_custom_skin_logo(self):
        askbot_settings.update('ASKBOT_DEFAULT_SKIN', 'test_skin')
        self.assert_default_logo_in_skin('test_skin')

    def test_uploaded_logo(self):
        logo_src = os.path.join(
                            askbot.get_install_directory(),
                            'tests',
                            'images',
                            'logo.gif'
                        )
        logo_file = open(logo_src, 'r')
        new_logo = UploadedFile(file = logo_file)
        askbot_settings.update('SITE_LOGO_URL', new_logo)
        logo_url = askbot_settings.SITE_LOGO_URL
        self.assertTrue(logo_url.startswith(django_settings.MEDIA_URL))
        response = self.client.get(logo_url)
        self.assertTrue(response.status_code == 200)