Beispiel #1
0
    def test_latest_newsitem(self):
        """
        Pass the most-recently-created visible NewsItem to the template
        context.
        """
        old_newsitem = NewsItemFactory.create(visible=True)
        old_newsitem.created = aware_datetime(2014, 1, 1)
        old_newsitem.save()

        non_visible_newsitem = NewsItemFactory.create(visible=False)
        non_visible_newsitem.created = aware_datetime(2014, 1, 5)
        non_visible_newsitem.save()

        visible_newsitem = NewsItemFactory.create(visible=True)
        visible_newsitem.created = aware_datetime(2014, 1, 4)
        visible_newsitem.save()

        request = Mock()
        with patch('affiliates.base.views.render') as render:
            views.dashboard(request)

        render.assert_called_with(request, 'base/dashboard.html', {
            'newsitem': visible_newsitem,
            'milestones': ANY,
        })
Beispiel #2
0
    def test_latest_newsitem(self):
        """
        Pass the most-recently-created visible NewsItem to the template
        context.
        """
        old_newsitem = NewsItemFactory.create(visible=True)
        old_newsitem.created = aware_datetime(2014, 1, 1)
        old_newsitem.save()

        non_visible_newsitem = NewsItemFactory.create(visible=False)
        non_visible_newsitem.created = aware_datetime(2014, 1, 5)
        non_visible_newsitem.save()

        visible_newsitem = NewsItemFactory.create(visible=True)
        visible_newsitem.created = aware_datetime(2014, 1, 4)
        visible_newsitem.save()

        request = Mock(user=UserFactory.create())
        with patch('affiliates.base.views.render') as render:
            views.dashboard(request)

        render.assert_called_with(request, 'base/dashboard.html', {
            'newsitem': visible_newsitem,
            'milestones': ANY,
            'links': ANY,
        })
Beispiel #3
0
    def test_no_available_newsitem(self):
        """
        If there are no visible NewsItems, pass None to the template
        context.
        """
        NewsItemFactory.create_batch(3, visible=False)

        request = Mock(user=UserFactory.create())
        with patch('affiliates.base.views.render') as render:
            views.dashboard(request)

        render.assert_called_with(request, 'base/dashboard.html', {
            'links': ANY,
        })
Beispiel #4
0
    def test_no_available_newsitem(self):
        """
        If there are no visible NewsItems, pass None to the template
        context.
        """
        NewsItemFactory.create_batch(3, visible=False)

        request = Mock()
        with patch('affiliates.base.views.render') as render:
            views.dashboard(request)

        render.assert_called_with(request, 'base/dashboard.html', {
            'newsitem': None,
            'milestones': ANY,
        })
Beispiel #5
0
    def test_save_model_no_pk(self):
        """
        If a NewsItem isn't saved yet (has no pk), set the author to the
        request's current user.
        """
        newsitem = NewsItemFactory.build()
        request = Mock(user=UserFactory.create())

        self.model_admin.save_model(request, newsitem, None, False)
        eq_(newsitem.author, request.user)
Beispiel #6
0
    def test_save_model_with_pk(self):
        """
        If a NewsItem exists in the DB (has a pk), do not change the
        author.
        """
        original_author = UserFactory.create()
        newsitem = NewsItemFactory.create(author=original_author)
        request = Mock(user=UserFactory.create())

        self.model_admin.save_model(request, newsitem, None, False)
        eq_(newsitem.author, original_author)
Beispiel #7
0
    def test_render(self):
        newsitem = NewsItemFactory.create(title='foo', html='<p>bar</p>')

        result = newsitem.render()
        ok_(isinstance(result, jinja2.Markup))
        eq_(result, 'rendered_html')
        self.bleach.clean.assert_called_with('<p>bar</p>', tags=ANY, attributes=ANY)
        self.render_to_string.assert_called_with('base/newsitem.html', {
            'title': 'foo',
            'html': 'cleaned_html'
        })
Beispiel #8
0
    def test_render(self):
        newsitem = NewsItemFactory.create(title='foo', html='<p>bar</p>')

        result = newsitem.render()
        ok_(isinstance(result, jinja2.Markup))
        eq_(result, 'rendered_html')
        self.bleach.clean.assert_called_with('<p>bar</p>',
                                             tags=ANY,
                                             attributes=ANY)
        self.render_to_string.assert_called_with('base/newsitem.html', {
            'title': 'foo',
            'html': 'cleaned_html'
        })
Beispiel #9
0
    def test_render_with_invalid_locale(self):
        """
        If an invalid locale is passed to render, use the title and html
        from the base NewsItem.
        """
        newsitem = NewsItemFactory.create(title='foo', html='<p>bar</p>')
        NewsItemTranslationFactory.create(newsitem=newsitem, locale='de', title='baz',
                                          html='<p>biff</p>')

        result = newsitem.render(locale='fr')
        ok_(isinstance(result, jinja2.Markup))
        eq_(result, 'rendered_html')
        self.bleach.clean.assert_called_with('<p>bar</p>', tags=ANY, attributes=ANY)
        self.render_to_string.assert_called_with('base/newsitem.html', {
            'title': 'foo',
            'html': 'cleaned_html'
        })
Beispiel #10
0
    def test_render_with_invalid_locale(self):
        """
        If an invalid locale is passed to render, use the title and html
        from the base NewsItem.
        """
        newsitem = NewsItemFactory.create(title='foo', html='<p>bar</p>')
        NewsItemTranslationFactory.create(newsitem=newsitem,
                                          locale='de',
                                          title='baz',
                                          html='<p>biff</p>')

        result = newsitem.render(locale='fr')
        ok_(isinstance(result, jinja2.Markup))
        eq_(result, 'rendered_html')
        self.bleach.clean.assert_called_with('<p>bar</p>',
                                             tags=ANY,
                                             attributes=ANY)
        self.render_to_string.assert_called_with('base/newsitem.html', {
            'title': 'foo',
            'html': 'cleaned_html'
        })