test_Design.py :  » Content-Management-Systems » PyLucid » PyLucid_standalone » pylucid_project » apps » pylucid » tests » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Content Management Systems » PyLucid 
PyLucid » PyLucid_standalone » pylucid_project » apps » pylucid » tests » test_Design.py
#!/usr/bin/env python
# coding: utf-8

"""
    PyLucid unittests
    ~~~~~~~~~~~~~~~~~
    
    TODO: Test colorscheme stuff
    
    :copyleft: 2010 by the django-weave team, see AUTHORS for more details.
    :license: GNU GPL v3 or above, see LICENSE for more details.
"""

import os

if __name__ == "__main__":
    # run all unittest directly
    os.environ['DJANGO_SETTINGS_MODULE'] = "pylucid_project.settings"

from pylucid_project.tests.test_tools import basetest
from pylucid_project.tests.test_tools.scrapping import HTMLscrapper
from pylucid_project.apps.pylucid.models import EditableHtmlHeadFile,ColorScheme



class DesignTestCase(basetest.BaseUnittest):
    STYLES = ['initial_site_style/main.css', 'pygments.css'] # used on the index page

    def _pre_setup(self, *args, **kwargs):
        super(DesignTestCase, self)._pre_setup(*args, **kwargs)

        self.colorscheme = ColorScheme.objects.get(id=1) # used in index page

        self.headfiles = []
        for style_path in self.STYLES:
            headfile = EditableHtmlHeadFile.on_site.get(filepath=style_path)
            self.headfiles.append(headfile)

    def get_headlinks(self, response):
        data = HTMLscrapper().grab(response.content, tags=("link",), attrs=("href",))
        return [url for url in data["href"] if "headfile" in url]

    def assertHeadfiles(self, urls):
        for url in urls:
            response = self.client.get(url)
            self.assertStatusCode(response, 200)
            self.failUnlessEqual(response["content-type"], "text/css")

    def check_headfile(self, headfile, colorscheme):
        url = headfile.get_absolute_url(colorscheme)
        self.assertHeadfiles([url])


class DesignTest(DesignTestCase):

    def test_index_styles(self):
        """ grab style links from index page and test if they can be requested """
        response = self.client.get("/")
        urls = self.get_headlinks(response)
        self.failUnless(len(urls) == 2)
        self.assertHeadfiles(urls)

    def test_cache(self):
        """ Test cached and non cache requests """
        # Create the cache file, if not exist
        for headfile in self.headfiles:
            cachepath = headfile.get_cachepath(self.colorscheme)
            if os.path.isfile(cachepath):
                # remove cache file
                os.remove(cachepath)
                self.failIf(os.path.isfile(cachepath), "Can't delete %r ?!?!" % cachepath)

            # Check if headfile.get_absolute_url can be requested
            self.check_headfile(headfile, self.colorscheme)

            headfile.save() # The save method should create the cache file

            # Check if file exist
            self.failUnless(os.path.isfile(cachepath), "Cache file %r doesn't not exist?!?!" % cachepath)

            # Check if headfile.get_absolute_url can be requested
            self.check_headfile(headfile, self.colorscheme)



if __name__ == "__main__":
    # Run all unittest directly
    from django.core import management
    management.call_command('test', __file__, verbosity=1)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.