Ticket #5496: django_views_tests_r6360.diff

File django_views_tests_r6360.diff, 10.9 KB (added by Manuel Saelices, 17 years ago)

Completing tests with django.views.defaults views

  • regressiontests/django_views/locale/en/LC_MESSAGES/djangojs.po

    No se puede mostrar: el archivo está marcado como binario.
    svn:mime-type = application/octet-stream
    
    Cambios de propiedades en regressiontests/django_views/locale/en/LC_MESSAGES/djangojs.mo
    ___________________________________________________________________
    Nombre: svn:mime-type
       + application/octet-stream
    
     
     1# SOME DESCRIPTIVE TITLE.
     2# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
     3# This file is distributed under the same license as the PACKAGE package.
     4# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
     5#
     6#, fuzzy
     7msgid ""
     8msgstr ""
     9"Project-Id-Version: PACKAGE VERSION\n"
     10"Report-Msgid-Bugs-To: \n"
     11"POT-Creation-Date: 2007-09-15 16:45+0200\n"
     12"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
     13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     14"Language-Team: LANGUAGE <LL@li.org>\n"
     15"MIME-Version: 1.0\n"
     16"Content-Type: text/plain; charset=UTF-8\n"
     17"Content-Transfer-Encoding: 8bit\n"
     18
     19msgid "this is to be translated"
     20msgstr "this is to be translated in english"
  • regressiontests/django_views/locale/es/LC_MESSAGES/djangojs.po

    No se puede mostrar: el archivo está marcado como binario.
    svn:mime-type = application/octet-stream
    
    Cambios de propiedades en regressiontests/django_views/locale/es/LC_MESSAGES/djangojs.mo
    ___________________________________________________________________
    Nombre: svn:mime-type
       + application/octet-stream
    
     
     1# SOME DESCRIPTIVE TITLE.
     2# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
     3# This file is distributed under the same license as the PACKAGE package.
     4# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
     5#
     6#, fuzzy
     7msgid ""
     8msgstr ""
     9"Project-Id-Version: PACKAGE VERSION\n"
     10"Report-Msgid-Bugs-To: \n"
     11"POT-Creation-Date: 2007-09-15 16:45+0200\n"
     12"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
     13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     14"Language-Team: LANGUAGE <LL@li.org>\n"
     15"MIME-Version: 1.0\n"
     16"Content-Type: text/plain; charset=UTF-8\n"
     17"Content-Transfer-Encoding: 8bit\n"
     18
     19#: media/js/translate.js:1
     20msgid "this is to be translated"
     21msgstr "esto tiene que ser traducido"
  • regressiontests/django_views/locale/fr/LC_MESSAGES/djangojs.po

    No se puede mostrar: el archivo está marcado como binario.
    svn:mime-type = application/octet-stream
    
    Cambios de propiedades en regressiontests/django_views/locale/fr/LC_MESSAGES/djangojs.mo
    ___________________________________________________________________
    Nombre: svn:mime-type
       + application/octet-stream
    
     
     1# SOME DESCRIPTIVE TITLE.
     2# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
     3# This file is distributed under the same license as the PACKAGE package.
     4# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
     5#
     6#, fuzzy
     7msgid ""
     8msgstr ""
     9"Project-Id-Version: PACKAGE VERSION\n"
     10"Report-Msgid-Bugs-To: \n"
     11"POT-Creation-Date: 2007-09-15 19:15+0200\n"
     12"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
     13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     14"Language-Team: LANGUAGE <LL@li.org>\n"
     15"MIME-Version: 1.0\n"
     16"Content-Type: text/plain; charset=UTF-8\n"
     17"Content-Transfer-Encoding: 8bit\n"
     18
     19msgid "this is to be translated"
     20msgstr "il faut le traduire"
  • regressiontests/django_views/views.py

     
     1from django.http import HttpResponse
     2from django.template import RequestContext
     3from django.shortcuts import render_to_response
     4
     5
     6def index_page(request):
     7    """ Dummy index page """
     8    return HttpResponse('<html><body>Dummy page</body></html>')
     9
     10
     11def jsi18n_test(request):
     12    """ View for testing javascript message files """
     13    return render_to_response('js_i18n.html', {})
     14 Sin fin-de-línea al final del archivo
  • regressiontests/django_views/fixtures/testdata.json

     
     1[
     2    {
     3        "pk": 1,
     4        "model": "django_views.article",
     5        "fields": {
     6            "author": 1,
     7            "title": "Un articulo"
     8        }
     9    },
     10    {
     11        "pk": 1,
     12        "model": "django_views.author",
     13        "fields": {
     14            "name": "Amparo"
     15        }
     16    },
     17    {
     18        "pk": 1,
     19        "model": "sites.site",
     20        "fields": {
     21            "domain": "testserver",
     22            "name": "testserver"
     23        }
     24    }
     25]
  • regressiontests/django_views/models.py

     
     1"""
     2Regression tests for Django Views
     3"""
     4
     5from os import path
     6import gettext
     7
     8from django.conf import settings
     9from django.http import Http404
     10from django.test import Client, TestCase
     11from django.contrib.sessions.models import Session
     12from django.contrib.contenttypes.models import ContentType
     13from django.utils.translation import activate
     14
     15from django.db import models
     16from django.conf import settings
     17
     18
     19##########################
     20# Models for testing
     21
     22class Author(models.Model):
     23    name = models.CharField(max_length=100)
     24
     25    def __unicode__(self):
     26        return self.name
     27
     28    def get_absolute_url(self):
     29        return '/django_views/authors/%s/' % self.id
     30
     31
     32class Article(models.Model):
     33    title = models.CharField(max_length=100)
     34    author = models.ForeignKey(Author)
     35
     36    def __unicode__(self):
     37        return self.title
     38
     39
     40##########################
     41# Tests suites
     42
     43class DefaultsTests(TestCase):
     44    fixtures = ['testdata.json']
     45    """ Test django views in django/views/defaults.py """
     46
     47    def test_shorcut(self):
     48        """ Test shorcut view """
     49        content_types = ContentType.objects.all()
     50        for ct in content_types:
     51            model = ct.model_class()
     52            for obj in model.objects.all():
     53                short_url = '/django_views/r/%s/%s/' % (ct.id, obj.pk)
     54                response = self.client.get(short_url)
     55                if hasattr(obj, 'get_absolute_url'):
     56                    self.assertRedirects(response, 'http://testserver%s' % obj.get_absolute_url(),
     57                                         target_status_code=404)
     58                else:
     59                    self.assertEquals(response.status_code, 404)
     60
     61    def test_page_not_found(self):
     62        non_existing_urls = ['/django_views/non_existing_url/', # this is in urls.py
     63                             '/django_views/other_non_existing_url/'] # this NOT in urls.py
     64        for url in non_existing_urls:
     65            response = self.client.get(url)
     66            self.assertEquals(response.status_code, 404)
     67
     68    def test_server_error(self):
     69        response = self.client.get('/django_views/server_error/')
     70        self.assertEquals(response.status_code, 500)
     71
     72
     73class I18NTests(TestCase):
     74    """ Tests django views in django/views/i18n.py """
     75
     76    def test_setlang(self):
     77        """ Test set_language view """
     78        for lang_code, lang_name in settings.LANGUAGES:
     79            response = self.change_language(lang_code, '/django_views/')
     80            self.assertRedirects(response, 'http://testserver/django_views/')
     81            self.assertEquals(self.client.session['django_language'], lang_code)
     82
     83    def test_jsi18n(self):
     84        """ Test javascript_catalog view """
     85        for lang_code in ['es', 'fr', 'en']:
     86            activate(lang_code)
     87            locale_dir = path.join(path.dirname(__file__), 'locale')
     88            catalog = gettext.translation('djangojs', locale_dir, [lang_code])
     89            trans_txt = catalog.ugettext('this is to be translated')
     90            response = self.client.get('/django_views/jsi18n/')
     91            # in response content must to be a line like that:
     92            # catalog['this is to be translated'] = 'same_that_trans_txt'
     93            self.assertContains(response, trans_txt, 1)
     94
     95    def change_language(self, language, next):
     96        post_data = dict(language=language, next=next)
     97        return self.client.post('/django_views/i18n/setlang/', data=post_data)
  • regressiontests/django_views/urls.py

     
     1from django.conf.urls.defaults import *
     2import views
     3
     4js_info_dict = {
     5    'domain': 'djangojs',
     6    'packages': ('regressiontests.django_views',),
     7}
     8
     9
     10urlpatterns = patterns('',
     11    (r'^$', views.index_page),
     12    (r'^r/(\d+)/(.*)/$', 'django.views.defaults.shortcut'),
     13    (r'^non_existing_url/', 'django.views.defaults.page_not_found'),
     14    (r'^server_error/', 'django.views.defaults.server_error'),
     15    (r'^i18n/', include('django.conf.urls.i18n')),
     16    (r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),
     17    (r'^jsi18n_test/$', views.jsi18n_test),
     18)
  • urls.py

     
    1111
    1212    # test urlconf for {% url %} template tag
    1313    (r'^url_tag/', include('regressiontests.templates.urls')),
     14   
     15    # django views tests urls
     16    (r'^django_views/', include('regressiontests.django_views.urls')),
    1417)
  • templates/js_i18n.html

     
     1{% extends "base.html" %}
     2{% load i18n %}
     3{% block title %}{% trans "Js Tests" %}{% endblock %}
     4{% block content %}
     5
     6{% endblock %}
Back to Top