assert not user.is_anonymous() assert user.get_id() == u"1" @login.test def user_equality(): class MyUser(UserMixin): def __init__(self, id): self.id = id idOneA = MyUser(1) idOneB = MyUser(1) idTwo = MyUser(2) assert idOneA == idOneA assert idOneA == idOneB assert idOneA != idTwo @login.test def anonymous_user(): anon = AnonymousUser() assert not anon.is_authenticated() assert not anon.is_active() assert anon.is_anonymous() assert anon.get_id() is None if __name__ == '__main__': login.main()
assert session["_fresh"] is False # user objects @login.test def user_mixin(): class MyUser(UserMixin): def __init__(self, id): self.id = id user = MyUser(1) assert user.is_authenticated() assert user.is_active() assert not user.is_anonymous() assert user.get_id() == u"1" @login.test def anonymous_user(): anon = AnonymousUser() assert not anon.is_authenticated() assert not anon.is_active() assert anon.is_anonymous() assert anon.get_id() is None if __name__ == "__main__": login.main()
# encoding: utf-8 from attest import Tests from drive.drive_ import Drive from drive.keys import * from stream import ImageStream fat32 = Tests() @fat32.context def build_fs(): with ImageStream('d:/edt.raw') as s: c = Drive.parse_stream(s) yield c['%s%s' % (k_Partition, 0)] @fat32.test def test_fat32(c): assert c[k_FAT32BootSector][k_filesystem_type] == 'FAT32 ' if __name__ == '__main__': fat32.main()
"""Make sure login and logout works""" rv = client.login(flaskr.app.config['USERNAME'], flaskr.app.config['PASSWORD']) assert 'You were logged in' in rv.data rv = client.logout() assert 'You were logged out' in rv.data rv = client.login(flaskr.app.config['USERNAME'] + 'x', flaskr.app.config['PASSWORD']) assert 'Invalid username' in rv.data rv = client.login(flaskr.app.config['USERNAME'], flaskr.app.config['PASSWORD'] + 'x') assert 'Invalid password' in rv.data @app.test def messages(client): """Test that messages work""" client.login(flaskr.app.config['USERNAME'], flaskr.app.config['PASSWORD']) rv = client.post('/add', data=dict( title='<Hello>', text='<strong>HTML</strong> allowed here' ), follow_redirects=True) assert 'No entries here so far' not in rv.data assert '<Hello>' in rv.data assert '<strong>HTML</strong> allowed here' in rv.data if __name__ == '__main__': app.main()
from attest import Tests, assert_hook samples = Tests() @samples.test def number_and_sequence(): number = 2 + 3 sequence = [1, 2, 3] assert number in sequence and isinstance(number, float) if __name__ == '__main__': samples.main()
class User(ActivationMixin): pass user = User() assert user.is_active assert user.activation_key is None user.is_active = False assert user.is_active == False assert user.activation_key is not None user.is_active = True assert user.is_active assert user.activation_key is None @mixin.test def gravatar_mixin(): class User(GravatarMixin): GRAVATAR_FALLBACK = 'monsterid' GRAVATAR_DEFAULT_SIZE = 128 user = User('*****@*****.**') GRAVATAR_URL = 'http://www.gravatar.com/avatar/5658ffccee7f0ebfda2b226238b1eb6e?s=128&d=monsterid' assert user.avatar_url == GRAVATAR_URL assert user.get_gravatar_url() == GRAVATAR_URL if __name__ == '__main__': mixin.main()
@staticutils.test def rewrite_rule(app): setup(app) with app.test_client() as c: assert app.testing rv = c.get('static/js/app-d41d8cd98f00.js') assert rv.status_code == 302 assert rv.headers['Location'] == 'http://localhost/static/js/app.js' rv = c.get('static/js/app-d41d8cd98f00.js', follow_redirects=True) assert rv.data == 'well\n' @staticutils.test def custom_rewrite_rule(app): app.config[key('FORMATSTR')] = '/%(path)s-rev:%(rev)s%(ext)s' setup(app) with app.test_client() as c: rv = c.get('/static/js/app-rev:d41d8cd98f00.js') assert rv.status_code == 302 assert rv.headers['Location'] == 'http://localhost/static/js/app.js' suite = Tests(tests=(utils, staticutils)) if __name__ == '__main__': suite.main()
def test_logout(app): client = app.test_client() # todo: log user in, test that user is actually logged out # good logout res = client.post(app.config['BROWSERID_LOGOUT_URL']) assert res.status_code == 200 @flask_browserid.test def test_static_file(app): # todo: test that "auth.js" is compiled and # available in the request contexts pass @flask_browserid.test def test_multiple_applications(self): """ ensures that the extension supports multiple applications. """ # todo: figure out how to test no conflict # between multiple applications. pass if __name__ == '__main__': if len(sys.argv) > 1 and sys.argv[1] == '-i': generate_app().run() else: flask_browserid.main()
instance.route(string) Assert(L[-1]) == 'ORG ADDRESS: %s' % string.split(':')[1].split('@')[0] @roadmap_tests.test def route_object_by_key(instance, L): class Email(object): def __init__(self, adr): self.address = adr string = 'com:[email protected]' obj = Email(string) instance.route(obj, key=obj.address) Assert(L[-1]) == 'COM ADDRESS: %s' % string @roadmap_tests.test def get_function(instance, L): Assert(instance.get_function('com:[email protected]').__name__) == \ 'com_address' @roadmap_tests.test def argument_passing(instance, L): string = 'endbeforewwwwafter' objs = ('woot', 'scoot') instance.route(objs, key=string) Assert(L[-1]) == (('woot', 'scoot', 'before'), {'after_w': 'after'}) if __name__ == '__main__': roadmap_tests.main()
conn = RiakConnection() conn.register(User) @mock_connection.test def test_get(): instance = User.get(key) Assert(instance._lazy).is_not(None) Assert(instance.to_dict()) == data Assert(instance.name) == data['name'] Assert(instance._lazy).is_(None) @mock_connection.test def test_map(User, key): all_users = User.map( '''function(v) { var data = JSON.parse(v.values[0].data); return [[v.key, data]]; }''') iter(all_users) len(all_users) all_users[0], all_users[-1], all_users[1:-1] bool(all_users) tests = Tests([init, mock_connection]) if __name__ == '__main__': tests.main()
# todo: good login @flask_browserid.test def test_logout(app): client = app.test_client() # todo: log user in, test that user is actually logged out # good logout res = client.post(app.config['BROWSERID_LOGOUT_URL']) assert res.status_code == 200 @flask_browserid.test def test_static_file(app): # todo: test that "auth.js" is compiled and # available in the request contexts pass @flask_browserid.test def test_multiple_applications(self): """ ensures that the extension supports multiple applications. """ # todo: figure out how to test no conflict # between multiple applications. pass if __name__ == '__main__': if len(sys.argv) > 1 and sys.argv[1] == '-i': generate_app().run() else: flask_browserid.main()