Add test for news
authorCyprien Mangin <cyprien.mangin@m4x.org>
Sat, 2 Feb 2013 15:59:59 +0000 (16:59 +0100)
committerCyprien Mangin <cyprien.mangin@m4x.org>
Sat, 2 Feb 2013 16:01:45 +0000 (17:01 +0100)
Signed-off-by: Cyprien Mangin <cyprien.mangin@m4x.org>
Makefile
xnet/news/factories.py
xnet/news/models.py
xnet/news/tests.py [new file with mode: 0644]

index 1753aa2..86cc29e 100644 (file)
--- 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
index 1158152..3d6324b 100644 (file)
@@ -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)
+
index 221d979..ef81f59 100644 (file)
@@ -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 (file)
index 0000000..9741612
--- /dev/null
@@ -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()