Beispiel #1
0
    def test_auth_views(self):
        """Test private views while logged in"""

        foia = FOIARequest.objects.get(pk=1)
        self.client.login(username='******', password='******')

        # get authenticated pages
        get_allowed(self.client, reverse('foia-create'))

        get_allowed(
            self.client,
            reverse('foia-draft',
                    kwargs={
                        'jurisdiction': foia.jurisdiction.slug,
                        'jidx': foia.jurisdiction.pk,
                        'idx': foia.pk,
                        'slug': foia.slug
                    }))

        get_404(
            self.client,
            reverse('foia-draft',
                    kwargs={
                        'jurisdiction': foia.jurisdiction.slug,
                        'jidx': foia.jurisdiction.pk,
                        'idx': foia.pk,
                        'slug': 'bad_slug'
                    }))
    def test_foia_detail(self):
        """Test the foia-detail view"""

        foia = FOIARequest.objects.get(pk=2)
        get_allowed(self.client,
                    reverse('foia-detail',
                        kwargs={'idx': foia.pk, 'slug': foia.slug,
                            'jurisdiction': foia.jurisdiction.slug,
                            'jidx': foia.jurisdiction.pk}))
    def test_action_views(self):
        """Test action views"""

        foia = FOIARequest.objects.get(pk=1)
        self.client.login(username='******', password='******')

        foia = FOIARequest.objects.get(pk=18)
        get_allowed(self.client, reverse('foia-pay',
            kwargs={'jurisdiction': foia.jurisdiction.slug,
                'jidx': foia.jurisdiction.pk,
                'idx': foia.pk, 'slug': foia.slug}))
Beispiel #4
0
 def test_news_archive_month(self):
     """Should return all articel from the given month"""
     response = get_allowed(self.client,
             reverse('news-archive-month', kwargs={'year': 1999, 'month': 'jan'}))
     eq_(len(response.context['object_list']), 3)
     ok_(all(article.pub_date.year == 1999 and article.pub_date.month == 1
                        for article in response.context['object_list']))
Beispiel #5
0
 def test_news_archive_author(self):
     """Should return all articles for the given author"""
     author = Article.objects.get(slug='test-article-5').authors.first()
     response = get_allowed(
         self.client,
         reverse('news-author', kwargs={'username': author.username})
     )
     eq_(len(response.context['object_list']), Article.objects.filter(authors=author).count())
Beispiel #6
0
    def test_foia_list(self):
        """Test the foia-list view"""

        response = get_allowed(self.client, reverse('foia-list'))
        nose.tools.eq_(
            set(response.context['object_list']),
            set(
                FOIARequest.objects.get_viewable(
                    AnonymousUser()).order_by('-date_submitted')[:12]))
Beispiel #7
0
 def test_news_archive_day(self):
     """Should return all article for the given day"""
     response = get_allowed(self.client,
             reverse('news-archive-day',
                 kwargs={'year': 1999, 'month': 'jan', 'day': 1}))
     eq_(len(response.context['object_list']), 2)
     ok_(all(article.pub_date.year == 1999 and article.pub_date.month == 1 and
                        article.pub_date.day == 1
                        for article in response.context['object_list']))
Beispiel #8
0
 def test_news_detail(self):
     """News detail should display the given article"""
     response = get_allowed(self.client,
             reverse('news-detail',
                 kwargs={
                     'year': 1999,
                     'month': 'jan',
                     'day': 1,
                     'slug': 'test-article-5'}))
     eq_(response.context['object'], Article.objects.get(slug='test-article-5'))
    def test_foia_list_user(self):
        """Test the foia-list-user view"""

        for user_pk in [1, 2]:
            response = get_allowed(self.client,
                    reverse('foia-list-user', kwargs={'user_pk': user_pk}))
            user = User.objects.get(pk=user_pk)
            nose.tools.eq_(set(response.context['object_list']),
                           set(FOIARequest.objects.get_viewable(AnonymousUser()).filter(user=user)))
            nose.tools.ok_(all(foia.user == user for foia in response.context['object_list']))
Beispiel #10
0
    def test_foia_sorted_list(self):
        """Test sorting on foia-list view"""

        for field in ['title', 'date_submitted', 'status']:
            for order in ['asc', 'desc']:
                response = get_allowed(self.client, reverse('foia-list') +
                        '?sort=%s&order=%s' % (field, order))
                nose.tools.eq_([f.title for f in response.context['object_list']],
                               [f.title for f in sorted(response.context['object_list'],
                                                        key=attrgetter(field),
                                                        reverse=(order == 'desc'))])
Beispiel #11
0
    def test_feeds(self):
        """Test the RSS feed views"""

        get_allowed(self.client, reverse('foia-submitted-feed'))
        get_allowed(self.client, reverse('foia-done-feed'))
Beispiel #12
0
 def test_foia_bad_sort(self):
     """Test sorting against a non-existant field"""
     response = get_allowed(self.client,
                            reverse('foia-list') + '?sort=test')
     nose.tools.eq_(response.status_code, 200)
Beispiel #13
0
 def test_news_archive_day_empty(self):
     """Should return nothing for a day with no articles"""
     response = get_allowed(self.client,
             reverse('news-archive-day',
                 kwargs={'year': 1999, 'month': 'mar', 'day': 1}))
     eq_(len(response.context['object_list']), 0)
Beispiel #14
0
 def test_news_archive_year(self):
     """Should return all articles in the given year"""
     response = get_allowed(self.client, reverse('news-archive-year', kwargs={'year': 1999}))
     eq_(len(response.context['object_list']), 4)
     ok_(all(article.pub_date.year == 1999
                        for article in response.context['object_list']))
Beispiel #15
0
 def test_news_index(self):
     """Should redirect to list"""
     get_allowed(self.client, reverse('news-index'))
Beispiel #16
0
 def test_feed(self):
     """Should have a feed"""
     get_allowed(self.client, reverse('news-feed'))