Skip to content

Commit

Permalink
clean up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BartSaelen committed Apr 15, 2014
1 parent 2a21946 commit ab08e21
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 66 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[run]
source = atramhasis
omit = atramhasis/scripts/*

[report]
show_missing = True
40 changes: 3 additions & 37 deletions atramhasis/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,56 +11,22 @@
class TestMyViewSuccessCondition(unittest.TestCase):
def setUp(self):
self.config = testing.setUp()
from sqlalchemy import create_engine
engine = create_engine('sqlite://')
from .models import (
Base,
MyModel,
)
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
with transaction.manager:
model = MyModel(name='one', value=55)
DBSession.add(model)

def tearDown(self):
DBSession.remove()
testing.tearDown()

def test_passing_view(self):
from .views import my_view
request = testing.DummyRequest()
info = my_view(request)
self.assertEqual(info['one'].name, 'one')
print('info' + info['project'])
self.assertEqual(info['project'], 'atramhasis')


class TestMyViewFailureCondition(unittest.TestCase):
def setUp(self):
self.config = testing.setUp()
from sqlalchemy import create_engine
engine = create_engine('sqlite://')
from .models import (
Base,
MyModel,
)
DBSession.configure(bind=engine)

def tearDown(self):
DBSession.remove()
testing.tearDown()

def test_failing_view(self):
from .views import my_view
request = testing.DummyRequest()
info = my_view(request)
self.assertEqual(info.status_int, 500)


class TestScaffolding(unittest.TestCase):
def test_scaffolding(self):
atemp= AtramhasisTemplate('test')
atempdemo= AtramhasisDemoTemplate('demo')
atemp = AtramhasisTemplate('test')
atempdemo = AtramhasisDemoTemplate('demo')
self.assertEqual(atemp.summary, 'Create an Atramhasis implementation')
self.assertEqual(atempdemo.summary, 'Create an Atramhasis demo')
self.assertEqual(atemp.name, 'test')
Expand Down
31 changes: 2 additions & 29 deletions atramhasis/views.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,8 @@
from pyramid.response import Response
from pyramid.view import view_config

from sqlalchemy.exc import DBAPIError

from .models import (
DBSession,
MyModel,
)


@view_config(route_name='home', renderer='templates/atramhasis.jinja2')
def my_view(request):
try:
one = DBSession.query(MyModel).filter(MyModel.name == 'one').first()
except DBAPIError:
return Response(conn_err_msg, content_type='text/plain', status_int=500)
return {'one': one, 'project': 'atramhasis'}

conn_err_msg = """\
Pyramid is having a problem using your SQL database. The problem
might be caused by one of the following things:
1. You may need to run the "initialize_atramhasis_db" script
to initialize your database tables. Check your virtual
environment's "bin" directory for this script and try to run it.
2. Your database server may not be running. Check that the
database server referred to by the "sqlalchemy.url" setting in
your "development.ini" file is running.
After you fix the problem, please restart the Pyramid application to
try it again.
"""
test = 'test 1 2 3'
return {'test': test, 'project': 'atramhasis'}

0 comments on commit ab08e21

Please sign in to comment.