Changeset 1061 in main


Ignore:
Timestamp:
04/27/12 10:33:53 (7 years ago)
Author:
pcosquer
Message:

tests: add possibility to test translated views

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/openPLM/plmapp/tests/views.py

    r1056 r1061  
    2626This module contains some tests for openPLM. 
    2727""" 
     28 
     29import os 
    2830import datetime 
     31 
     32from django.conf import settings 
    2933from django.contrib.auth.models import User 
    3034from django.core import mail 
     
    3236from django.core.files.base import File 
    3337from django.contrib import messages 
     38from django.utils.translation import ugettext as _ 
     39from django.utils import translation 
    3440 
    3541from openPLM.plmapp import forms 
     
    4753    DATA = {} 
    4854    REFERENCE = "Part1" 
     55    LANGUAGE = "en" 
    4956 
    5057    def setUp(self): 
    5158        super(CommonViewTest, self).setUp() 
    5259        self.client.post("/login/", {'username' : 'user', 'password' : 'password'}) 
     60        self.client.post("/i18n/setlang/", {"language" : self.LANGUAGE}) 
    5361        self.controller = self.CONTROLLER.create(self.REFERENCE, self.TYPE, "a", 
    5462                                                 self.user, self.DATA) 
     
    17641772        attributes = dict((x.capitalize(), y) for (x,y) in  
    17651773                          response.context["object_attributes"]) 
    1766         self.assertEqual(attributes["E-mail address"], self.user.email) 
     1774 
     1775        old_lang = translation.get_language() 
     1776        translation.activate(self.LANGUAGE) 
     1777        key = _("e-mail address") 
     1778        translation.activate(old_lang) 
     1779        del old_lang 
     1780 
     1781        self.assertEqual(attributes[key.capitalize()], self.user.email) 
    17671782        self.assertTrue(response.context["is_owner"]) 
    17681783 
     
    18501865            url = self.user_url + "delegation/delegate/sign/%s/" % str(level) 
    18511866            response = self.get(url, link=True, page="delegation") 
    1852             role = unicode(response.context["role"]) 
    1853             self.assertTrue(role.startswith("signer")) 
    1854             self.assertTrue(level in role) 
     1867            if self.LANGUAGE == "en": 
     1868                role = unicode(response.context["role"]) 
     1869                self.assertTrue(role.startswith("signer")) 
     1870                self.assertTrue(level in role) 
    18551871 
    18561872    def test_delegate_post(self): 
     
    25822598    REFERENCE = u"Pa *-\xc5\x93\xc3\xa9'" 
    25832599 
     2600# also test translations if asked 
     2601if os.environ.get("TEST_TRANS") == "on": 
     2602    test_cases = [] 
     2603    def find_test_cases(base, r): 
     2604        r.append(base) 
     2605        for c in base.__subclasses__(): 
     2606            find_test_cases(c, r) 
     2607    find_test_cases(CommonViewTest, test_cases) 
     2608    tpl = """class %(base)s__%(language)s(%(base)s): 
     2609        LANGUAGE = "%(language)s" 
     2610    """ 
     2611    for language, language_name in settings.LANGUAGES: 
     2612        if language != "en": 
     2613            for base in test_cases: 
     2614                exec (tpl % (dict(base=base.__name__, language=language))) 
     2615 
Note: See TracChangeset for help on using the changeset viewer.