示例#1
0
 def test_timer_proxy(self):
     u = fh.create_user()
     self.flush()
     self.login(u)
     
     response = self.post(self.form_url, {
         'a_number': 32,
         'a_string': 'aodij'
     })
     
     assert response.tmpl_context.show_debug == False
     assert response.tmpl_context.queries == ''
     
     u = fh.create_user(is_admin=True)
     self.flush()
     self.login(u)
     
     response = self.post(self.form_url, {
         'a_number': 32,
         'a_string': 'aodij'
     })
     
     assert response.tmpl_context.show_debug == True
     assert len(response.tmpl_context.queries) == 3
     assert response.tmpl_context.querie_time > 0.0
     
     for q, t in response.tmpl_context.queries:
         assert q
         assert t > 0.0
示例#2
0
 def test_auth_owns_pretend(self):
     u, p = self._create_ad_user()
     
     rando = fh.create_user()
     u2 = fh.create_user()
     adm = fh.create_user(is_admin=True)
     
     assert auth_owns_fn_user(u, p)
     assert auth_owns_fn_actual_user(u, p)
     assert auth_enforce_owns_fn(u, p)
     assert auth_owns_fn_user(adm, p)
     
     assert self.throws_exception(lambda: auth_owns_fn_user(u2, p)).code == FORBIDDEN
     assert self.throws_exception(lambda: auth_enforce_owns_fn(u2, p)).code == FORBIDDEN
示例#3
0
 def test_teather(self):
     u = fh.create_user()
     
     p1 = fh.create_profile(email=u'*****@*****.**')
     p2 = fh.create_profile(email=u'*****@*****.**')
     self.flush()
     
     k = {
         'notes': u'I met this guy here and there.',
         'phone:work': u'510-234-1245',
         'phone:home': u'510-234-2341'
     }
     profile = api.profile.teather(p1.user, p1.user, email=u'*****@*****.**', **k)
     self.flush()
     
     assert p2 == profile
     
     phone = data.PhoneHandler()
     d = p2.fetch_data(user=p1.user)
     assert len(d) == 5 # name, phone*2, notes, email
     for dp in d:
         if dp.key == 'notes': assert dp.value == k['notes']
         if dp.key == 'phone' and dp.type == 'work': assert dp.value == phone.normalize(k['phone:work'])
         if dp.key == 'phone' and dp.type == 'home': assert dp.value == phone.normalize(k['phone:home'])
     
     
     profile = api.profile.teather(p1.user, p1.user, email=u'*****@*****.**', name=u'Some Guy')
     assert profile
     
     dps = profile.fetch_data(user=p1.user)
     print dps
     d = dict([(p.key, p.value) for p in dps])
     assert 'name' in d
     assert 'email' in d
     
示例#4
0
 def test_get(self):
     u = fh.create_user()
     
     profile = fh.create_profile(email=u'*****@*****.**')
     self.flush()
     
     pro = api.profile.get(u,u, profile=profile.eid)
     assert pro == profile
     
     pro = api.profile.get(u,u, email=u'*****@*****.**')
     assert pro == profile
示例#5
0
 def test_teathering_accept(self):
     u = fh.create_user()
     p = fh.create_profile(u)
     
     u2 = fh.create_user()
     p2 = fh.create_profile(u2)
     self.flush()
     
     l = len(p.fetch_teathers())
     assert l == 0
     
     # user u wants to connect to u2
     p.teather(p2)
     self.flush()
     
     teathers = p.fetch_teathers()
     l = len(teathers)
     assert l == 1
     assert teathers[0].owning_profile.id == p.id
     assert teathers[0].teathered_profile.id == p2.id
     assert teathers[0].status == STATUS_PENDING
     assert teathers[0].reciprocated_teather == None
     
     teathers[0].accept()
     self.flush()
     
     teathers = p.fetch_teathers()
     teathers2 = p2.fetch_teathers()
     l = len(teathers)
     l2 = len(teathers2)
     assert l == l2 == 1
     
     assert teathers[0].owning_profile.id == p.id
     assert teathers[0].teathered_profile.id == p2.id
     assert teathers[0].status == STATUS_ACCEPTED
     assert teathers[0].reciprocated_teather.id == teathers2[0].id
     
     assert teathers2[0].owning_profile.id == p2.id
     assert teathers2[0].teathered_profile.id == p.id
     assert teathers2[0].status == STATUS_ACCEPTED
     assert teathers2[0].original_teather.id == teathers[0].id
示例#6
0
 def test_creation(self):
     u = fh.create_user()
     p = fh.create_profile(u)
     self.flush()
     
     l = len(p.data_points)
     assert l == 2
     
     assert p.is_active
     keys = ['name', 'email']
     for dp in p.data_points:
         assert dp.key in keys
示例#7
0
 def test_field_editor(self):
     
     u = fh.create_user()
     adm = fh.create_user(is_admin=True)
     
     class SomeForm(formencode.Schema):
         things = fv.Number(not_empty=False, min=0)
         yo_mammas = fv.Int(not_empty=False, min=0)
         admin_only = fv.Int(not_empty=False, min=0)
         error_1 = fv.UnicodeString(not_empty=False)
         error_2 = fv.UnicodeString(not_empty=False)
     
     edit_fields = ['things', 'yo_mammas', 'error_1', 'error_2']
     admin_edit_fields = ['admin_only']
     
     class Editor(FieldEditor):
         def __init__(self):
             super(Editor, self).__init__(edit_fields, admin_edit_fields, SomeForm)
         
         def edit_error_1(self, actual_user, user, obj, key, value):
             raise ClientException('error_1')
         def edit_error_2(self, actual_user, user, obj, key, value):
             raise ClientException('error_2')
         
         def edit_things(self, actual_user, user, obj, key, value):
             assert actual_user
             assert user
             assert key == 'things'
             obj['things'] = value
         
         def edit_random(self, actual_user, user, obj, key, value):
             obj['random'] = value
         
         def edit_admin_only(self, actual_user, user, obj, key, value):
             assert key == 'admin_only'
             obj['admin_only'] = value
         
         #not defining yo_mammas intentionally
     
     editor =  Editor()
     
     #basic case, non admin
     obj = {}
     editor.edit(u, u, obj, things='3.0')
     assert obj['things'] == 3.0
     
     obj = {}
     editor.edit(u, u, obj, key='things', value='4.0')
     assert obj['things'] == 4.0
     
     #basic case, admin, multiple fields
     obj = {}
     editor.edit(adm, u, obj, things='5.0', admin_only=34)
     assert obj['things'] == 5.0
     assert obj['admin_only'] == 34
     
     #FAIL case, non-admin. will not edit admin!
     obj = {}
     editor.edit(u, u, obj, things='5.0', admin_only=34)
     assert obj['things'] == 5.0
     assert 'admin_only' not in obj
     
     # should not run the validator on the admin_only field
     editor.edit(u, u, obj, things='5.0', admin_only='dont breaK!')
     assert obj['things'] == 5.0
     assert 'admin_only' not in obj
     
     ce = (ClientException,)
     
     #FAIL case, empty
     assert self.throws_exception(lambda: editor.edit(u, u, obj), types=ce).code == INCOMPLETE
     
     #FAIL case, dont edit random stuff we dont care about
     obj = {}
     assert self.throws_exception(lambda: editor.edit(u, u, obj, random='poo'), types=ce).code == INCOMPLETE
     assert not obj
     assert self.throws_exception(lambda: editor.edit(u, u, obj, admin_only='poo'), types=ce).code == INCOMPLETE
     assert not obj
     editor.edit(u, u, obj, things=4.5, random='poo')
     assert 'things' in obj
     assert 'random' not in obj
     editor.edit(u, u, obj, things=4.5, random_foo='poo')
     assert 'things' in obj
     assert 'random_foo' not in obj
     
     #this cant call the function cause it isnt defined
     obj = {}
     assert self.throws_exception(lambda: editor.edit(u, u, obj, yo_mammas='2'), types=(AppException,)).code == INCOMPLETE
     
     exc = self.throws_exception(lambda: editor.edit(u, u, obj, error_1='blah', error_2='blah'), types=(CompoundException,))
     assert exc.has_exceptions
     assert len(exc.exceptions) == 2
     assert 'error_1' in [e.msg for e in exc.exceptions]
     assert 'error_2' in [e.msg for e in exc.exceptions]
     
     ##
     #validation!
     ##
     
     i = (formencode.validators.Invalid,)
     exc = self.throws_exception(lambda: editor.edit(u, u, obj, things='asd', yo_mammas='qw'), types=i)
     assert exc
     assert len(exc.error_dict.keys()) == 2
     assert 'things' in exc.error_dict.keys()
     assert 'yo_mammas' in exc.error_dict.keys()
示例#8
0
 def test_auth_admin(self):
     u = fh.create_user()
     adm = fh.create_user(is_admin=True)
     
     assert auth_admin_fn(adm)
     assert self.throws_exception(lambda: auth_admin_fn(u)).code == FORBIDDEN
示例#9
0
 def _create_ad_user(self, make_admin=False):
     u = make_admin and fh.create_user(is_admin=True) or fh.create_user()
     p = u.set_preference(u'omg', u'wow')
     return u, p