Projet

Général

Profil

0001-rss-expose-published-announces-only-14731.patch

Serghei Mihai, 23 janvier 2017 11:03

Télécharger (3,03 ko)

Voir les différences:

Subject: [PATCH] rss: expose published announces only (#14731)

 corbo/views.py          |  7 ++++---
 tests/test_announces.py | 25 ++++++++++++++++++++++++-
 2 files changed, 28 insertions(+), 4 deletions(-)
corbo/views.py
1
from datetime import datetime
2 1
import urllib
3 2
import json
4 3

  
5 4
from django.conf import settings
6 5
from django.core import signing
6
from django.utils import timezone
7 7
from django.core.urlresolvers import reverse
8 8
from django.views.generic import CreateView, UpdateView, DeleteView, \
9 9
    ListView, TemplateView, RedirectView, DetailView
......
202 202
        self.__dict__.update(kwargs)
203 203

  
204 204
    def items(self):
205
        return models.Announce.objects.exclude(expiration_time__lt=datetime.now()).order_by('-publication_time')
205
        return models.Announce.objects.filter(publication_time__lte=timezone.now()).exclude(
206
            expiration_time__lt=timezone.now()).order_by('-publication_time')
206 207

  
207 208
    def item_title(self, item):
208 209
        return item.title
......
214 215
        return self.feed_item_link_template.format(item.pk)
215 216

  
216 217
    def item_pubdate(self, item):
217
        return item.publication_time or item.mtime
218
        return item.publication_time
218 219

  
219 220

  
220 221
atom = AtomView()
tests/test_announces.py
4 4
import feedparser
5 5

  
6 6
from django.core.files.storage import DefaultStorage
7
from django.utils import timezone
8
from django.core.urlresolvers import reverse
7 9

  
8
from corbo.models import Category
10
from corbo.models import Category, Announce
9 11

  
10 12
pytestmark = pytest.mark.django_db
11 13

  
......
62 64
            assert storage.url('logo.png') in announce.text
63 65
    # cleanup uploaded images
64 66
    os.unlink(storage.path('logo.png'))
67

  
68

  
69
def test_announces_publishing(app):
70
    c = Category.objects.create(name='Test announces')
71
    a = Announce.objects.create(category=c, title='Test 1',
72
                                text='text')
73
    feed_content = feedparser.parse(app.get(reverse('atom')).text)
74
    assert len(feed_content['entries']) == 0
75
    a.publication_time = timezone.now()
76
    a.save()
77
    feed_content = feedparser.parse(app.get(reverse('atom')).text)
78
    assert len(feed_content['entries']) == 1
79
    a.publication_time = timezone.now() + timezone.timedelta(days=1)
80
    a.save()
81
    feed_content = feedparser.parse(app.get(reverse('atom')).text)
82
    assert len(feed_content['entries']) == 0
83
    a.publication_time = timezone.now()
84
    a.expiration_time = timezone.now()
85
    a.save()
86
    feed_content = feedparser.parse(app.get(reverse('atom')).text)
87
    assert len(feed_content['entries']) == 0
65
-