Esempio n. 1
0
 def test_get_delegates_to_render(self):
     view = TemplateView()
     (flexmock(view)
         .should_receive('render')
         .with_args(page=3)
         .and_return('a response'))
     assert view.get(page=3) == 'a response'
Esempio n. 2
0
 def test_renders_given_template_with_given_context(self):
     from flask.ext.generic_views import core
     view = TemplateView()
     (flexmock(view)
         .should_receive('get_template')
         .with_args()
         .and_return('template.html'))
     (flexmock(view)
         .should_receive('get_context')
         .with_args(page=3)
         .and_return({'foo': 'bar', 'params': {'page': 3}}))
     (flexmock(core)
         .should_receive('render_template')
         .with_args('template.html', foo='bar', params={'page': 3})
         .and_return('a response'))
     assert view.render(page=3) == 'a response'
edit_view = UpdateView.as_view('edit',
                               model=Post,
                               fields=('name', 'body'),
                               success_url='/{id}')

app.add_url_rule('/<int:pk>/edit', view_func=edit_view)

# delete

delete_view = DeleteView.as_view('delete', model=Post, success_url='/')

app.add_url_rule('/<int:pk>/delete', view_func=delete_view)

# about

about_view = TemplateView.as_view('about', template_name='about.html')

app.add_url_rule('/about', view_func=about_view)

# contact

contact_view = RedirectView.as_view('contact', endpoint='index')

app.add_url_rule('/redirect', view_func=contact_view)


@app.before_first_request
def init_stuff():
    try:
        db.create_all()
    except OperationalError as e:
Esempio n. 4
0
 def test_get_context_adds_kwargs_to_params_key(self):
     view = TemplateView()
     assert view.get_context(page=3) == {'params': {'page': 3}}
Esempio n. 5
0
 def test_get_context_returns_context_from_attribute(self):
     view = TemplateView(context={'foo': 'bar'})
     assert view.get_context() == {'foo': 'bar', 'params': {}}
Esempio n. 6
0
 def test_get_template_raises_exception_if_template_not_defined(self):
     view = TemplateView()
     with raises(ImproperlyConfigured):
         view.get_template()
Esempio n. 7
0
 def test_get_template_returns_template_attribute(self):
     view = TemplateView(template='template.html')
     assert view.get_template() == 'template.html'