def create_test_petition_to_congress(db): petition_exists = db.select('petition', where='id=$test_pid_to_cong', vars=dict(test_pid_to_cong=test_pid_to_cong)) if not petition_exists: b = AppBrowser(app) b.open('/c/new') f = b.select_form() f['ptitle'] = test_pid_to_cong.replace('_', ' ') f['pid'] = test_pid_to_cong f['msg'] = 'All the signatures of it are claimed to be sent to reps' f['tocongress'] = ['on'] f['prefix'] = ['Ms.'] f['lname'] = 'tester' f['fname'] = 'here' f['addr1'] = '103, Reach St.' f['city'] = 'City of Flowers' f['phone'] = '999-100-9999' f['zip5'], f['zip4'], f['state'] = '80132', '0001', ['CO'] #CO-05 b.submit() assert b.path == '/c/new' form = b.select_form(name='login') b['useremail'] = test_email b['password'] = test_passwd b.submit() assert 'Congratulations' in b.data, 'creating test petition failed'
def create_test_user(db): userexists = db.select('users', where='email=$test_email', vars=dict(test_email=test_email)) if not userexists: b = AppBrowser(app) b.open('/u/login') b.select_form(name='signup') b['email'] = test_email b['password'] = b['password_again'] = test_passwd b.submit() assert b.path == '/', b.path b.open('/c/new') assert 'Hi,' in b.data, 'creating test user failed'
def create_test_petition(db): petition_exists = db.select('petition', where='id=$test_pid', vars=dict(test_pid=test_pid)) if not petition_exists: b = AppBrowser(app) b.open('/c/new') b.select_form() b['ptitle'] = test_pid.replace('_', ' ') b['pid'] = test_pid b['msg'] = 'Here is a test petition with a not-so-worthy description, just for testing purpose' b.submit() assert b.path == '/c/new' form = b.select_form(name='login') b['useremail'] = test_email b['password'] = test_passwd b.submit() assert 'Congratulations' in b.data, 'creating test petition failed'
def get_text(self, e=None, name=None, **kw): if name or kw: e = self.get_soup().find(name=name, **kw) return AppBrowser.get_text(self, e)
def browser(self): self.b = AppBrowser(app) return self.b
class TestCase(webtest.TestCase): def setUp(self): self.t = db.transaction() self.ctx = dict(self.t.ctx) def tearDown(self): self.t.ctx = web.storage(self.ctx) self.t.rollback() def browser(self): self.b = AppBrowser(app) return self.b def login(self, uemail=None, password=None): self.b.open('/u/login') self.b.select_form(name='login') self.b['useremail'] = uemail or loaddb.test_email self.b['password'] = password or loaddb.test_passwd self.b.submit() def logout(self): self.b.open('/u/logout') self.b.select_form() self.b.submit() def get_errors(self): soup = self.b.get_soup() errs = soup.findAll(attrs={'class': ['error', 'wrong']}) return [self.b.get_text(e) for e in errs]
import web import webapp import petition import inspect, types, itertools, gzip, os from web.browser import AppBrowser single_pages = ('/', '/about', '/about/team', '/about/api', '/about/feedback', '/about/help', '/contribute/', '/blog/', '/lob/c/', '/lob/f/', '/lob/o/', '/lob/pa/', '/lob/pe/', '/b/', '/e/', '/p/', '/c/', '/writerep/') b = AppBrowser(webapp.app) def test(klass): index = klass().index() for path in do_flatten(take(2, iter(index))): try: b.open(path) assert (b.status == 200) except: print b.status, path, klass def get_class_index(klass, _test=False): try: if _test: return test(klass) return klass().index() except AttributeError: return []
import os os.environ['WEB_ENV'] = 'test' import unittest import web from web.browser import AppBrowser import app import seed import model as m b = AppBrowser(app.app) class AppTest(unittest.TestCase): def setUp(self): seed.init() # Add global setup here pass class TestIntegration(AppTest): def test_index(self): b.open('/') self.assertEqual(200, b.status) class TestUser(AppTest): def test_password_is_crypted(self): u = m.User.create(email='*****@*****.**', password='******')