示例#1
0
 def testSignal(self):
     entry = Entry(author_id=1, language='de', is_active=False)
     self.assertEqual(entry.pinging, entry.SLEEPING)
     entry.save()
     self.assertEqual(entry.pinging, entry.SLEEPING)
     entry.is_active = True
     entry.save()
     self.assertEqual(entry.pinging, entry.QUEUED)
示例#2
0
    def testModel(self):
        # Make sure the Entry has a blogping extension
        entry = Entry()
        self.assertTrue(hasattr(entry, 'pinging'))
        self.assertTrue(hasattr(entry, 'SLEEPING'))
        self.assertTrue(hasattr(entry, 'QUEUED'))
        self.assertTrue(hasattr(entry, 'SENT'))
        self.assertTrue(hasattr(entry, 'UNKNOWN'))

        self.assertEqual(entry.SLEEPING, 10)
        self.assertEqual(entry.pinging, entry.SLEEPING)
 def testEnvironment(self):
     # Make sure the Entry has no translation attribute
     entry = Entry()
     self.assertFalse(hasattr(entry, 'language'))
     self.assertFalse(hasattr(entry, 'translation_of'))
     entries = Entry.objects.order_by('pk')
     entry = entries[0]
     self.assertEqual(entry.pk, 1)
     self.assertEqual(entry.title, u'Entry 1')
     entry = entries[1]
     self.assertEqual(entry.pk, 2)
     self.assertEqual(entry.title, u'Eintrag 1')
示例#4
0
    def test_permalink_equality(self):
        urls = []
        for tzinfo in (pytz.timezone("America/Chicago"),
                       pytz.timezone("Europe/Moscow")):
            published_date = datetime.datetime(year=2012,
                                               month=3,
                                               day=3,
                                               hour=1,
                                               minute=30,
                                               tzinfo=tzinfo)
            entry = Entry.objects.create(is_active=True,
                                         author=self.author,
                                         slug='test-entry',
                                         published_on=published_date)
            urls.append(entry.get_absolute_url())
            entry.delete()
        url_chicago, url_moscow = urls
        self.assertNotEqual(url_chicago, url_moscow)
        urls = []
        for tzinfo, day, hour in [(pytz.timezone("America/Chicago"), 2, 15),
                                  (pytz.timezone("Europe/Moscow"), 3, 1)]:
            published_date = datetime.datetime(year=2012,
                                               month=3,
                                               day=day,
                                               hour=hour,
                                               minute=30,
                                               tzinfo=tzinfo)
            entry = Entry.objects.create(is_active=True,
                                         author=self.author,
                                         slug='test-entry',
                                         published_on=published_date)
            urls.append(entry.get_absolute_url())
            entry.delete()
        url_chicago, url_moscow = urls
        self.assertEqual(url_chicago, url_moscow)

        # Make sure the translation extension is not loaded for this test.
        entry = Entry()
        self.assertFalse(hasattr(entry, 'language'))
    def testTranslation(self):
        # Make sure the Entry has a translation extension
        entry = Entry()
        self.assertTrue(hasattr(entry, 'language'))
        self.assertTrue(hasattr(entry, 'translation_of'))
        # define the language of entry 2
        entries = Entry.objects.order_by('pk')
        entry1 = entries[0]
        self.assertEqual(entry1.pk, 1)
        self.assertEqual(entry1.title, u'Entry 1')
        entry1.language = 'en'
        entry1.save()
        entry2 = entries[1]
        self.assertEqual(entry2.pk, 2)
        self.assertEqual(entry2.title, u'Eintrag 1')
        entry2.language = 'de'
        entry2.translation_of = entry1
        entry2.save()
        entry3 = entries[2]
        entry4 = entries[3]
        self.assertEqual(entry3.language, 'zh-cn')
        self.assertEqual(entry4.language, 'zh-tw')

        entry = Entry.objects.get(language='de')
        self.assertEqual(entry.title, u'Eintrag 1')

        with translation.override('de'):
            c = Client()
            self.assertEqual(short_language_code(), 'de')
            # Test Archive URL
            response = c.get('/blog/', HTTP_ACCEPT_LANGUAGE='de')
            self.assertEqual(len(response.context['object_list']), 1)
            self.assertEqual(response.status_code, 200)
            self.assertNotContains(response, u'Entry 1')
            self.assertContains(response, u'Eintrag 1')
            # test all languages override
            response = c.get('/multilang/', HTTP_ACCEPT_LANGUAGE='de')
            self.assertEqual(len(response.context['object_list']), 4)
            self.assertEqual(response.status_code, 200)

        with translation.override('en'):
            response = c.get('/blog/', HTTP_ACCEPT_LANGUAGE='en')
            self.assertEqual(short_language_code(), 'en')
            self.assertEqual(len(response.context['object_list']), 1)
            self.assertEqual(response.status_code, 200)
            self.assertContains(response, u'Entry 1')
            self.assertNotContains(response, u'Eintrag 1')

        with translation.override('zh-cn'):
            self.assertEqual(translation.get_language(), 'zh-cn')
            self.assertEqual(short_language_code(), 'zh')
            response = c.get('/blog/', HTTP_ACCEPT_LANGUAGE='zh-cn')
            self.assertEqual(len(response.context['object_list']), 1)
            self.assertEqual(response.status_code, 200)
            self.assertContains(response, u'Entry 2 chinese traditional')
            self.assertNotContains(response, u'Eintrag 1')

        with translation.override('zh-tw'):
            self.assertEqual(translation.get_language(), 'zh-tw')
            self.assertEqual(short_language_code(), 'zh')
            response = c.get('/blog/', HTTP_ACCEPT_LANGUAGE='zh-tw')
            self.assertEqual(len(response.context['object_list']), 1)
            self.assertEqual(response.status_code, 200)
            self.assertContains(response, u'Entry 2 chinese simplified')
            self.assertNotContains(response, u'Eintrag 1')


# AttributeError: 'Settings' object has no attribute '_original_allowed_hosts'
# fixed in Django 1.6

# https://github.com/django/django/commit/e2b86571bfa3503fe43adfa92e9c9f4271a7a135
    def testURLs(self):
        # Make sure the Entry has no translation attribute
        entry = Entry()
        self.assertFalse(hasattr(entry, 'language'))
        self.assertFalse(hasattr(entry, 'translation_of'))

        c = Client()
        # Test Archive URL
        response = c.get('/blog/')
        self.assertTrue(isinstance(response.context['view'],
            blogviews.ArchiveIndexView ))
        self.assertEqual(len(response.context['object_list']), 2)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, u'Entry 1')
        self.assertContains(response, u'Eintrag 1')

        # Test year archive
        response = c.get('/blog/2012/')
        self.assertTrue(isinstance(response.context['view'],
                                        blogviews.YearArchiveView ))
        self.assertEqual(len(response.context['object_list']), 2)
        self.assertEqual(response.context['view'].get_template_names(),
                         [u'elephantblog/entry_archive.html'])
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, u'News for 2012')
        self.assertContains(response, u'Entry 1')
        self.assertContains(response, u'Eintrag 1')
        # No entries in 2011:
        response = c.get('/blog/2011/')
        self.assertEqual(response.status_code, 404)

        # Test month archive
        response = c.get('/blog/2012/10/')
        self.assertTrue(isinstance(response.context['view'],
                                        blogviews.MonthArchiveView ))
        self.assertEqual(len(response.context['object_list']), 1)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, u'News \nfor October 2012')
        self.assertContains(response, u'Eintrag 1')
        response = c.get('/blog/2012/08/')
        self.assertEqual(len(response.context['object_list']), 1)
        self.assertContains(response, u'News \nfor August 2012')
        self.assertContains(response, u'Entry 1')
        response = c.get('/blog/2012/06/')
        self.assertEqual(response.status_code, 404)

        # Test day archive
        response = c.get('/blog/2012/10/12/')
        self.assertTrue(isinstance(response.context['view'],
                                        blogviews.DayArchiveView ))
        self.assertEqual(len(response.context['object_list']), 1)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, u'News \n\nfor Oct. 12, 2012')
        self.assertContains(response, u'Eintrag 1')
        response = c.get('/blog/2012/08/12/')
        self.assertEqual(len(response.context['object_list']), 1)
        self.assertContains(response, u'News \n\nfor Aug. 12, 2012')
        self.assertContains(response, u'Entry 1')
        # No entries in 2011:
        response = c.get('/blog/2012/10/13/')
        self.assertEqual(response.status_code, 404)

        # Test category archive
        # assign a category to the entry
        category1 = create_category('Category 1')
        category2 = create_category('Category 2')
        entry = Entry.objects.get(slug='entry-1')
        entry.categories.add(category1)
        entry.categories.add(category2)
        entry = Entry.objects.get(slug='eintrag-1')
        entry.categories.add(category2)

        response = c.get('/blog/category/category-1/')
        self.assertEqual(response.status_code, 200)
        self.assertTrue(isinstance(response.context['view'],
            blogviews.CategoryArchiveIndexView ))
        self.assertEqual(len(response.context['object_list']), 1)
        self.assertContains(response, u'Entry 1')
        self.assertNotContains(response, u'Eintrag 1')

        response = c.get('/blog/category/category-2/')
        self.assertEqual(response.status_code, 200)
        self.assertTrue(isinstance(response.context['view'],
            blogviews.CategoryArchiveIndexView ))
        self.assertEqual(len(response.context['object_list']), 2)
        self.assertContains(response, u'Entry 1')
        self.assertContains(response, u'Eintrag 1')

        # Test detail view
        response = c.get('/blog/2012/08/12/entry-1/')
        self.assertEqual(response.status_code, 200)
        self.assertTrue(isinstance(response.context['view'],
                            blogviews.DateDetailView ))
        self.assertContains(response, u'Entry 1')
        self.assertContains(response, u'Category 1')
        self.assertContains(response, u'Category 2')
    def testTranslation(self):
        create_chinese_entries(EntryFactory)

        # Make sure the Entry has a translation extension
        entry = Entry()
        self.assertTrue(hasattr(entry, "language"))
        self.assertTrue(hasattr(entry, "translation_of"))

        # define the language of entry 2
        entries = Entry.objects.order_by("pk")
        entry1 = entries[0]
        self.assertEqual(entry1.pk, 1)
        self.assertEqual(entry1.title, "Entry 1")
        entry1.language = "en"
        entry1.save()
        entry2 = entries[1]
        self.assertEqual(entry2.pk, 2)
        self.assertEqual(entry2.title, "Eintrag 1")
        entry2.language = "de"
        entry2.translation_of = entry1
        entry2.save()
        entry3 = entries[2]
        entry4 = entries[3]
        self.assertEqual(entry3.language, "zh-hans")
        self.assertEqual(entry4.language, "zh-hant")

        entry = Entry.objects.get(language="de")
        self.assertEqual(entry.title, "Eintrag 1")

        with translation.override("de"):
            c = Client()
            self.assertEqual(short_language_code(), "de")
            # Test Archive URL
            response = c.get("/blog/", HTTP_ACCEPT_LANGUAGE="de")
            self.assertEqual(len(response.context["object_list"]), 1)
            self.assertEqual(response.status_code, 200)
            self.assertNotContains(response, "Entry 1")
            self.assertContains(response, "Eintrag 1")
            # test all languages override
            response = c.get("/multilang/", HTTP_ACCEPT_LANGUAGE="de")
            self.assertEqual(len(response.context["object_list"]), 4)
            self.assertEqual(response.status_code, 200)

        with translation.override("en"):
            c = Client()
            response = c.get("/blog/", HTTP_ACCEPT_LANGUAGE="en")
            self.assertEqual(short_language_code(), "en")
            self.assertEqual(len(response.context["object_list"]), 1)
            self.assertEqual(response.status_code, 200)
            self.assertContains(response, "Entry 1")
            self.assertNotContains(response, "Eintrag 1")

        with translation.override("zh-hans"):
            c = Client()
            self.assertEqual(translation.get_language(), "zh-hans")
            self.assertEqual(short_language_code(), "zh")
            response = c.get("/blog/", HTTP_ACCEPT_LANGUAGE="zh-hans")
            self.assertEqual(len(response.context["object_list"]), 1)
            self.assertEqual(response.status_code, 200)
            self.assertContains(response, "Entry 2 chinese traditional")
            self.assertNotContains(response, "Eintrag 1")

        with translation.override("zh-hant"):
            c = Client()
            self.assertEqual(translation.get_language(), "zh-hant")
            self.assertEqual(short_language_code(), "zh")
            response = c.get("/blog/", HTTP_ACCEPT_LANGUAGE="zh-hant")
            self.assertEqual(len(response.context["object_list"]), 1)
            self.assertEqual(response.status_code, 200)
            self.assertContains(response, "Entry 2 chinese simplified")
            self.assertNotContains(response, "Eintrag 1")
示例#8
0
    def testTranslation(self):
        create_chinese_entries(EntryFactory)

        # Make sure the Entry has a translation extension
        entry = Entry()
        self.assertTrue(hasattr(entry, 'language'))
        self.assertTrue(hasattr(entry, 'translation_of'))

        # define the language of entry 2
        entries = Entry.objects.order_by('pk')
        entry1 = entries[0]
        self.assertEqual(entry1.pk, 1)
        self.assertEqual(entry1.title, 'Entry 1')
        entry1.language = 'en'
        entry1.save()
        entry2 = entries[1]
        self.assertEqual(entry2.pk, 2)
        self.assertEqual(entry2.title, 'Eintrag 1')
        entry2.language = 'de'
        entry2.translation_of = entry1
        entry2.save()
        entry3 = entries[2]
        entry4 = entries[3]
        self.assertEqual(entry3.language, 'zh-hans')
        self.assertEqual(entry4.language, 'zh-hant')

        entry = Entry.objects.get(language='de')
        self.assertEqual(entry.title, 'Eintrag 1')

        with translation.override('de'):
            c = Client()
            self.assertEqual(short_language_code(), 'de')
            # Test Archive URL
            response = c.get('/blog/', HTTP_ACCEPT_LANGUAGE='de')
            self.assertEqual(len(response.context['object_list']), 1)
            self.assertEqual(response.status_code, 200)
            self.assertNotContains(response, 'Entry 1')
            self.assertContains(response, 'Eintrag 1')
            # test all languages override
            response = c.get('/multilang/', HTTP_ACCEPT_LANGUAGE='de')
            self.assertEqual(len(response.context['object_list']), 4)
            self.assertEqual(response.status_code, 200)

        with translation.override('en'):
            c = Client()
            response = c.get('/blog/', HTTP_ACCEPT_LANGUAGE='en')
            self.assertEqual(short_language_code(), 'en')
            self.assertEqual(len(response.context['object_list']), 1)
            self.assertEqual(response.status_code, 200)
            self.assertContains(response, 'Entry 1')
            self.assertNotContains(response, 'Eintrag 1')

        with translation.override('zh-hans'):
            c = Client()
            self.assertEqual(translation.get_language(), 'zh-hans')
            self.assertEqual(short_language_code(), 'zh')
            response = c.get('/blog/', HTTP_ACCEPT_LANGUAGE='zh-hans')
            self.assertEqual(len(response.context['object_list']), 1)
            self.assertEqual(response.status_code, 200)
            self.assertContains(response, 'Entry 2 chinese traditional')
            self.assertNotContains(response, 'Eintrag 1')

        with translation.override('zh-hant'):
            c = Client()
            self.assertEqual(translation.get_language(), 'zh-hant')
            self.assertEqual(short_language_code(), 'zh')
            response = c.get('/blog/', HTTP_ACCEPT_LANGUAGE='zh-hant')
            self.assertEqual(len(response.context['object_list']), 1)
            self.assertEqual(response.status_code, 200)
            self.assertContains(response, 'Entry 2 chinese simplified')
            self.assertNotContains(response, 'Eintrag 1')