-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
146 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import unittest | ||
|
||
class ViewTests(unittest.TestCase): | ||
def setUp(self): | ||
import os | ||
import pkg_resources | ||
from pyramid.paster import bootstrap | ||
pkgroot = pkg_resources.get_distribution('shootout').location | ||
testing_ini = os.path.join(pkgroot, 'testing.ini') | ||
env = bootstrap(testing_ini) | ||
self.closer = env['closer'] | ||
from webtest import TestApp | ||
self.testapp = TestApp(env['app']) | ||
|
||
def tearDown(self): | ||
import transaction | ||
transaction.abort() | ||
self.closer() | ||
|
||
def login(self): | ||
self.testapp.post( | ||
'/register', | ||
{'form.submitted':'1', | ||
'username':'chris', | ||
'password':'chris', | ||
'confirm_password':'chris', | ||
'email':'chrism@plope.com', | ||
'name':'Chris McDonough', | ||
}, | ||
status=302, | ||
) | ||
self.testapp.post( | ||
'/login', | ||
{'login':'chris', 'password':'chris'}, | ||
status=302, | ||
) | ||
|
||
def add_idea(self): | ||
self.testapp.post( | ||
'/idea_add', | ||
{'form.submitted':True, | ||
'title':'title', | ||
'text':'text', | ||
'tags':'tag1'}, | ||
status=302, | ||
) | ||
|
||
def test_add_idea(self): | ||
self.login() | ||
self.add_idea() | ||
from shootout.models import Idea | ||
q = Idea.get_by_tagname('tag1') | ||
results = q.all() | ||
self.assertEqual(len(results), 1) | ||
idea = results[0] | ||
self.assertEqual(idea.title, 'title') | ||
|
||
def test_idea_vote(self): | ||
self.login() | ||
self.add_idea() | ||
from shootout.models import Idea | ||
q = Idea.get_by_tagname('tag1') | ||
target = q.one().idea_id | ||
self.testapp.post( | ||
'/idea_vote', | ||
{'target':target}, | ||
status=301, | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
[app:main] | ||
use = egg:shootout | ||
pyramid.reload_templates = false | ||
pyramid.debug_authorization = false | ||
pyramid.debug_notfound = false | ||
pyramid.debug_routematch = false | ||
pyramid.debug_templates = true | ||
pyramid.default_locale_name = en | ||
pyramid.includes = pyramid_exclog | ||
session.secret = ^5$309^vJ-* | ||
sqlalchemy.url = sqlite:///%(here)s/shootout.db | ||
#tm.commit_veto = shootout.tests.test_functional.never_commit | ||
|
||
[server:main] | ||
use = egg:waitress#main | ||
host = 0.0.0.0 | ||
port = 6543 | ||
|
||
# Begin logging configuration | ||
|
||
[loggers] | ||
keys = root, shootout, sqlalchemy, exc_logger | ||
|
||
[handlers] | ||
keys = console, exc_handler | ||
|
||
[formatters] | ||
keys = generic, exc_formatter | ||
|
||
[logger_root] | ||
level = INFO | ||
handlers = console | ||
|
||
[logger_shootout] | ||
level = DEBUG | ||
handlers = | ||
qualname = shootout | ||
|
||
[logger_exc_logger] | ||
level = ERROR | ||
handlers = exc_handler | ||
qualname = exc_logger | ||
|
||
[logger_sqlalchemy] | ||
level = INFO | ||
handlers = | ||
qualname = sqlalchemy.engine | ||
# "level = INFO" logs SQL queries. | ||
# "level = DEBUG" logs SQL queries and results. | ||
# "level = WARN" logs neither. (Recommended for production systems.) | ||
|
||
[logger_exc_logger] | ||
level = ERROR | ||
handlers = exc_handler | ||
qualname = exc_logger | ||
|
||
[handler_console] | ||
class = StreamHandler | ||
args = (sys.stderr,) | ||
level = NOTSET | ||
formatter = generic | ||
|
||
[handler_exc_handler] | ||
class = FileHandler | ||
args = ('%(here)s/exception.log',) | ||
level = ERROR | ||
formatter = exc_formatter | ||
|
||
[formatter_generic] | ||
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s | ||
|
||
[formatter_exc_formatter] | ||
format = %(asctime)s %(message)s | ||
|
||
# End logging configuration |