Ticket #5496: django_views_tests_r6360.2.diff

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

Added views for django.views.static views

  • tests/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 tests/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"
  • tests/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 tests/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"
  • tests/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 tests/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"
  • tests/regressiontests/django_views/media/file.txt

     
     1An example media file.
     2 Sin fin-de-línea al final del archivo
  • tests/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
  • tests/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]
  • tests/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        """ Test page_not_found view """
     63        non_existing_urls = ['/django_views/non_existing_url/', # this is in urls.py
     64                             '/django_views/other_non_existing_url/'] # this NOT in urls.py
     65        for url in non_existing_urls:
     66            response = self.client.get(url)
     67            self.assertEquals(response.status_code, 404)
     68
     69    def test_server_error(self):
     70        """ Test server_error view """
     71        response = self.client.get('/django_views/server_error/')
     72        self.assertEquals(response.status_code, 500)
     73
     74
     75class I18NTests(TestCase):
     76    """ Tests django views in django/views/i18n.py """
     77
     78    def test_setlang(self):
     79        """ Test set_language view """
     80        for lang_code, lang_name in settings.LANGUAGES:
     81            response = self.change_language(lang_code, '/django_views/')
     82            self.assertRedirects(response, 'http://testserver/django_views/')
     83            self.assertEquals(self.client.session['django_language'], lang_code)
     84
     85    def test_jsi18n(self):
     86        """ Test javascript_catalog view """
     87        for lang_code in ['es', 'fr', 'en']:
     88            activate(lang_code)
     89            locale_dir = path.join(path.dirname(__file__), 'locale')
     90            catalog = gettext.translation('djangojs', locale_dir, [lang_code])
     91            trans_txt = catalog.ugettext('this is to be translated')
     92            response = self.client.get('/django_views/jsi18n/')
     93            # in response content must to be a line like that:
     94            # catalog['this is to be translated'] = 'same_that_trans_txt'
     95            self.assertContains(response, trans_txt, 1)
     96
     97    def change_language(self, language, next):
     98        post_data = dict(language=language, next=next)
     99        return self.client.post('/django_views/i18n/setlang/', data=post_data)
     100
     101
     102class StaticTests(TestCase):
     103    """ Tests django views in django/views/static.py """
     104
     105    def test_serve(self):
     106        """ Test serve view """
     107        from urls import media_dir
     108        media_files = ['file.txt',]
     109        for filename in media_files:
     110            response = self.client.get('/django_views/site_media/%s' % filename)
     111            file = open(path.join(media_dir, filename))
     112            self.assertEquals(file.read(), response.content)
  • tests/regressiontests/django_views/urls.py

     
     1from os import path
     2
     3from django.conf.urls.defaults import *
     4import views
     5
     6media_dir = path.join(path.dirname(path.abspath(__file__)), 'media')
     7
     8js_info_dict = {
     9    'domain': 'djangojs',
     10    'packages': ('regressiontests.django_views',),
     11}
     12
     13urlpatterns = patterns('',
     14    (r'^$', views.index_page),
     15    (r'^r/(\d+)/(.*)/$', 'django.views.defaults.shortcut'),
     16    (r'^non_existing_url/', 'django.views.defaults.page_not_found'),
     17    (r'^server_error/', 'django.views.defaults.server_error'),
     18    (r'^i18n/', include('django.conf.urls.i18n')),
     19    (r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),
     20    (r'^jsi18n_test/$', views.jsi18n_test),
     21    (r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': media_dir}),
     22)
  • tests/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)
  • tests/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