From 1b99f720d18167a69c30093972c2320982485fea Mon Sep 17 00:00:00 2001 From: Cyprien Mangin Date: Sat, 2 Feb 2013 16:59:59 +0100 Subject: [PATCH] Add test for news Signed-off-by: Cyprien Mangin --- Makefile | 2 +- xnet/news/factories.py | 19 +++++++++++++++++-- xnet/news/models.py | 7 +++---- xnet/news/tests.py | 11 +++++++++++ 4 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 xnet/news/tests.py diff --git a/Makefile b/Makefile index 1753aa2..86cc29e 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ shell: $(MANAGE_PY) shell test: - $(MANAGE_PY) test example accounts site + $(MANAGE_PY) test example accounts site news resetdb: rm -f xnet/db.sqlite diff --git a/xnet/news/factories.py b/xnet/news/factories.py index 1158152..3d6324b 100644 --- a/xnet/news/factories.py +++ b/xnet/news/factories.py @@ -1,8 +1,23 @@ +# coding: utf-8 + +import datetime +from array import array +import Image + import factory from . import models +from xnet.accounts import factories as accountsFactories - -class GroupFactory(factory.DjangoModelFactory): +class NewsFactory(factory.DjangoModelFactory): FACTORY_FOR = models.News + title = factory.Sequence(lambda n: u"Annonce n°%s" % n) + content = u"Ceci est une annonce.\n\nC'est beau." + contacts = factory.Sequence(lambda n: u"pad%s@eltrai.net" % n) + expiration = datetime.date.today() + datetime.timedelta(days=1) + restricted = factory.Sequence(lambda n: n%2 == 0, type=int) + + author = factory.SubFactory(accountsFactories.AccountFactory) + group = factory.SubFactory(accountsFactories.XGroupFactory) + diff --git a/xnet/news/models.py b/xnet/news/models.py index 221d979..ef81f59 100644 --- a/xnet/news/models.py +++ b/xnet/news/models.py @@ -2,14 +2,14 @@ from django.db import models from django.utils.translation import ugettext_lazy as _ - +from xnet.utils.images.fields import ImageWithThumbsField class News(models.Model): title = models.CharField(max_length=200, verbose_name=u"titre") content = models.TextField(verbose_name=u"contenu") contacts = models.TextField(verbose_name=u"contacts", blank=True) - illustration = models.ImageField(upload_to='blah', verbose_name=u"illustration", null=True, blank=True) + illustration = ImageWithThumbsField(upload_to='news', verbose_name=u"illustration", null=True, blank=True) expiration = models.DateField(verbose_name=u"date de péremption") # TODO : attached_event = null @@ -22,8 +22,7 @@ class News(models.Model): group = models.ForeignKey('accounts.XGroup', related_name='news') class Meta: - verbose_name = _(u"news") - verbose_name_plural = _(u"news") + verbose_name = u"annonce" def __unicode__(self): return self.title diff --git a/xnet/news/tests.py b/xnet/news/tests.py new file mode 100644 index 0000000..9741612 --- /dev/null +++ b/xnet/news/tests.py @@ -0,0 +1,11 @@ + +from django import test + +from . import admin # pylint: disable=W0611 +from . import factories + + +class SimpleTest(test.TestCase): + + def test_factories(self): + factories.NewsFactory() -- 2.1.4