Browse Source

added pages

rework
Holger Frey 7 years ago
parent
commit
93dc403dd6
  1. 1
      ordr/resources/__init__.py
  2. 8
      ordr/templates/pages/faq.jinja2
  3. 2
      ordr/templates/pages/welcome.jinja2
  4. 11
      ordr/tests/__init__.py
  5. 40
      ordr/tests/_functional/__init__.py
  6. 8
      ordr/tests/_functional/errors.py
  7. 13
      ordr/tests/_functional/pages.py
  8. 8
      ordr/tests/views/errors.py
  9. 14
      ordr/tests/views/pages.py
  10. 20
      ordr/views/pages.py
  11. 14
      ordr/views/public.py

1
ordr/resources/__init__.py

@ -28,6 +28,5 @@ def includeme(config):
Initialize the resources for traversal in a Pyramid app. Initialize the resources for traversal in a Pyramid app.
Activate this setup using ``config.include('ordr2.resources')``. Activate this setup using ``config.include('ordr2.resources')``.
''' '''
config.set_root_factory(RootResource) config.set_root_factory(RootResource)

8
ordr/templates/pages/faq.jinja2

@ -0,0 +1,8 @@
{% extends "ordr:templates/layout.jinja2" %}
{% block content %}
<div class="content">
<h1>FAQ</h1>
<p class="lead">Welcome to <span class="font-normal">Ordr</span>, a&nbsp;Pyramid application generated&nbsp;by<br><span class="font-normal">Cookiecutter</span>.</p>
</div>
{% endblock content %}

2
ordr/templates/pages/welcome.jinja2

@ -2,7 +2,7 @@
{% block content %} {% block content %}
<div class="content"> <div class="content">
<h1><span class="font-semi-bold">Pyramid</span> <span class="smaller">Alchemy project</span></h1> <h1>Ordr</h1>
<p class="lead">Welcome to <span class="font-normal">Ordr</span>, a&nbsp;Pyramid application generated&nbsp;by<br><span class="font-normal">Cookiecutter</span>.</p> <p class="lead">Welcome to <span class="font-normal">Ordr</span>, a&nbsp;Pyramid application generated&nbsp;by<br><span class="font-normal">Cookiecutter</span>.</p>
</div> </div>
{% endblock content %} {% endblock content %}

11
ordr/tests/__init__.py

@ -38,14 +38,3 @@ def dbsession(app_config):
transaction.abort() transaction.abort()
Base.metadata.drop_all(engine) Base.metadata.drop_all(engine)
def test_passing_view(dbsession):
from ordr.views.default import my_view
from ordr.models import MyModel
model = MyModel(name='one', value=55)
dbsession.add(model)
info = my_view(None, testing.DummyRequest(dbsession=dbsession))
assert info['one'].name == 'one'
assert info['project'] == 'Ordr'

40
ordr/tests/_functional/__init__.py

@ -0,0 +1,40 @@
''' functional tests for ordr2 '''
import pytest
import transaction
import webtest
from .. import APP_SETTINGS
WEBTEST_SETTINGS = APP_SETTINGS.copy()
# WEBTEST_SETTINGS['pyramid.includes'].append('pyramid_mailer.testing')
class CustomTestApp(webtest.TestApp):
''' might add custom functionality to webtest.TestApp '''
pass
@pytest.fixture(scope='module')
def testapp():
''' fixture for using webtest '''
from ordr.models.meta import Base
from ordr.models import get_tm_session
from ordr import main
app = main({}, **WEBTEST_SETTINGS)
testapp = CustomTestApp(app)
session_factory = app.registry['dbsession_factory']
engine = session_factory.kw['bind']
Base.metadata.create_all(engine)
with transaction.manager:
# set up test data here
dbsession = get_tm_session(session_factory, transaction.manager)
# create_users(dbsession)
yield testapp
Base.metadata.drop_all(engine)

8
ordr/tests/_functional/errors.py

@ -0,0 +1,8 @@
''' functional tests for ordr2.views.errors '''
from . import testapp
def test_404(testapp):
result = testapp.get('/unknown', status=404)
assert '404' in result

13
ordr/tests/_functional/pages.py

@ -0,0 +1,13 @@
''' functional tests for ordr2.views.pages '''
from . import testapp
def test_welcome(testapp):
result = testapp.get('/')
assert 'Ordr' in result
def test_faq(testapp):
result = testapp.get('/faq')
assert 'FAQ' in result

8
ordr/tests/views/errors.py

@ -0,0 +1,8 @@
from pyramid.testing import DummyRequest
def test_welcome():
from ordr.views.errors import notfound_view
request = DummyRequest()
result = notfound_view(None, request)
assert result == {}
assert request.response.status == '404 Not Found'

14
ordr/tests/views/pages.py

@ -0,0 +1,14 @@
def test_welcome():
from ordr.views.pages import welcome
result = welcome(None, None)
assert result == {}
def test_faq():
from ordr.views.pages import faq
result = faq(None, None)
assert result == {}

20
ordr/views/pages.py

@ -0,0 +1,20 @@
from pyramid.view import view_config
@view_config(
context='ordr.resources.RootResource',
permission='view',
renderer='ordr:templates/pages/welcome.jinja2',
)
def welcome(context, request):
return {}
@view_config(
context='ordr.resources.RootResource',
name='faq',
permission='view',
renderer='ordr:templates/pages/faq.jinja2'
)
def faq(context, request):
return {}

14
ordr/views/public.py

@ -1,14 +0,0 @@
from pyramid.response import Response
from pyramid.view import view_config
from sqlalchemy.exc import DBAPIError
from ..models import MyModel
@view_config(
context='ordr.resources.RootResource',
renderer='ordr:templates/pages/welcome.jinja2'
)
def home(context, request):
return {}