Return-Path: X-Original-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 70662EF98 for ; Fri, 7 Dec 2012 22:26:37 +0000 (UTC) Received: (qmail 65602 invoked by uid 500); 7 Dec 2012 22:26:37 -0000 Delivered-To: apmail-incubator-allura-commits-archive@incubator.apache.org Received: (qmail 65543 invoked by uid 500); 7 Dec 2012 22:26:37 -0000 Mailing-List: contact allura-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: allura-dev@incubator.apache.org Delivered-To: mailing list allura-commits@incubator.apache.org Received: (qmail 64743 invoked by uid 99); 7 Dec 2012 22:26:36 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 Dec 2012 22:26:36 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 5AD1931D682; Fri, 7 Dec 2012 22:26:36 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: brondsem@apache.org To: allura-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [32/49] git commit: [#5289] convert @twitter handles into URLs Message-Id: <20121207222636.5AD1931D682@tyr.zones.apache.org> Date: Fri, 7 Dec 2012 22:26:36 +0000 (UTC) [#5289] convert @twitter handles into URLs Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/17f7bc05 Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/17f7bc05 Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/17f7bc05 Branch: refs/heads/db/4803 Commit: 17f7bc051fa1eb9c62fe7d784c4d28877782d4f4 Parents: 01c20a1 Author: Dave Brondsema Authored: Mon Dec 3 21:39:33 2012 +0000 Committer: Dave Brondsema Committed: Mon Dec 3 22:20:23 2012 +0000 ---------------------------------------------------------------------- Allura/allura/model/auth.py | 28 ++++++----- Allura/allura/tests/functional/test_auth.py | 58 +++++++++++----------- 2 files changed, 44 insertions(+), 42 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/17f7bc05/Allura/allura/model/auth.py ---------------------------------------------------------------------- diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py index c1ff1f4..8ac3370 100644 --- a/Allura/allura/model/auth.py +++ b/Allura/allura/model/auth.py @@ -303,7 +303,7 @@ class User(MappedClass, ActivityNode, ActivityObject): #Personal data sex=FieldProperty( - S.OneOf('Male', 'Female', 'Other', 'Unknown', + S.OneOf('Male', 'Female', 'Other', 'Unknown', if_missing='Unknown')) birthdate=FieldProperty(S.DateTime, if_missing=None) @@ -341,6 +341,8 @@ class User(MappedClass, ActivityNode, ActivityObject): return plugin.UserPreferencesProvider.get().set_pref(self, pref_name, pref_value) def add_socialnetwork(self, socialnetwork, accounturl): + if socialnetwork == 'Twitter' and not accounturl.startswith('http'): + accounturl = 'http://twitter.com/%s' % accounturl.replace('@', '') self.socialnetworks.append(dict( socialnetwork=socialnetwork, accounturl=accounturl)) @@ -371,8 +373,8 @@ class User(MappedClass, ActivityNode, ActivityObject): def add_timeslot(self, weekday, starttime, endtime): self.availability.append( - dict(week_day=weekday, - start_time=starttime, + dict(week_day=weekday, + start_time=starttime, end_time=endtime)) def remove_timeslot(self, weekday, starttime, endtime): @@ -384,7 +386,7 @@ class User(MappedClass, ActivityNode, ActivityObject): def add_inactive_period(self, startdate, enddate): self.inactiveperiod.append( - dict(start_date=startdate, + dict(start_date=startdate, end_date=enddate)) def remove_inactive_period(self, startdate, enddate): @@ -395,7 +397,7 @@ class User(MappedClass, ActivityNode, ActivityObject): return def get_localized_availability(self, tz_name): - week_day = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', + week_day = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] avail = self.get_availability_timeslots() usertimezone = timezone(self.get_pref('timezone')) @@ -404,15 +406,15 @@ class User(MappedClass, ActivityNode, ActivityObject): for t in avail: today = datetime.today() start = datetime( - today.year, today.month, today.day, + today.year, today.month, today.day, t['start_time'].hour, t['start_time'].minute, 0) end = datetime( - today.year, today.month, today.day, - t['end_time'].hour, t['end_time'].minute, 0) + today.year, today.month, today.day, + t['end_time'].hour, t['end_time'].minute, 0) loctime1 = usertimezone.localize(start) loctime2 = usertimezone.localize(end) - convtime1 = loctime1.astimezone(chosentimezone) + convtime1 = loctime1.astimezone(chosentimezone) convtime2 = loctime2.astimezone(chosentimezone) dif_days_start = convtime1.weekday() - today.weekday() @@ -437,7 +439,7 @@ class User(MappedClass, ActivityNode, ActivityObject): end_time = convtime2.time())) return sorted( - retlist, + retlist, key=lambda k:(week_day.index(k['week_day']), k['start_time'])) def get_skills(self): @@ -456,12 +458,12 @@ class User(MappedClass, ActivityNode, ActivityObject): for el in self.availability: start, end = (el.get('start_time'), el.get('end_time')) (starth, startm) = (start.get('h'), start.get('m')) - (endh, endm) = (end.get('h'), end.get('m')) + (endh, endm) = (end.get('h'), end.get('m')) newdict = dict( week_day = el.get('week_day'), start_time= time(starth,startm,0), end_time = time(endh,endm,0)) - retval.append(newdict) + retval.append(newdict) return retval def get_inactive_periods(self, include_past_periods=False): @@ -470,7 +472,7 @@ class User(MappedClass, ActivityNode, ActivityObject): d1, d2 = (el.get('start_date'), el.get('end_date')) newdict = dict(start_date = d1, end_date = d2) if include_past_periods or newdict['end_date'] > datetime.today(): - retval.append(newdict) + retval.append(newdict) return retval def url(self): http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/17f7bc05/Allura/allura/tests/functional/test_auth.py ---------------------------------------------------------------------- diff --git a/Allura/allura/tests/functional/test_auth.py b/Allura/allura/tests/functional/test_auth.py index 1327fe6..fe31deb 100644 --- a/Allura/allura/tests/functional/test_auth.py +++ b/Allura/allura/tests/functional/test_auth.py @@ -385,7 +385,7 @@ class TestPreferences(TestController): result = self.app.get('/auth/prefs') #Check if personal data is properly set - r = self.app.post('/auth/prefs/change_personal_data', + r = self.app.post('/auth/prefs/change_personal_data', params=dict( sex=setsex, birthdate=setbirthdate, @@ -403,9 +403,9 @@ class TestPreferences(TestController): assert city == setcity timezone = user.timezone assert timezone == settimezone - + #Check if setting a wrong date everything works correctly - r = self.app.post('/auth/prefs/change_personal_data', + r = self.app.post('/auth/prefs/change_personal_data', params=dict(birthdate='30/02/1998')) assert 'Please enter a valid date' in str(r) user = M.User.query.get(username='test-admin') @@ -421,7 +421,7 @@ class TestPreferences(TestController): assert timezone == settimezone #Check deleting birthdate - r = self.app.post('/auth/prefs/change_personal_data', + r = self.app.post('/auth/prefs/change_personal_data', params=dict( sex=setsex, birthdate='', @@ -436,7 +436,7 @@ class TestPreferences(TestController): #Add skype account testvalue = 'testaccount' result = self.app.get('/auth/prefs') - r = self.app.post('/auth/prefs/skype_account', + r = self.app.post('/auth/prefs/skype_account', params=dict(skypeaccount=testvalue)) user = M.User.query.get(username='test-admin') assert user.skypeaccount == testvalue @@ -444,7 +444,7 @@ class TestPreferences(TestController): #Add social network account socialnetwork = 'Facebook' accounturl = 'http://www.facebook.com/test' - r = self.app.post('/auth/prefs/add_social_network', + r = self.app.post('/auth/prefs/add_social_network', params=dict(socialnetwork=socialnetwork, accounturl = accounturl)) user = M.User.query.get(username='test-admin') @@ -454,17 +454,17 @@ class TestPreferences(TestController): #Add second social network account socialnetwork2 = 'Twitter' - accounturl2 = 'http://www.twitter.com/test' - r = self.app.post('/auth/prefs/add_social_network', + accounturl2 = 'http://twitter.com/test' + r = self.app.post('/auth/prefs/add_social_network', params=dict(socialnetwork=socialnetwork2, - accounturl = accounturl2)) + accounturl = '@test')) user = M.User.query.get(username='test-admin') assert len(user.socialnetworks) == 2 and \ ({'socialnetwork':socialnetwork, 'accounturl':accounturl} in user.socialnetworks and \ {'socialnetwork':socialnetwork2, 'accounturl':accounturl2} in user.socialnetworks) #Remove first social network account - r = self.app.post('/auth/prefs/remove_social_network', + r = self.app.post('/auth/prefs/remove_social_network', params=dict(socialnetwork=socialnetwork, account = accounturl)) user = M.User.query.get(username='test-admin') @@ -472,7 +472,7 @@ class TestPreferences(TestController): {'socialnetwork':socialnetwork2, 'accounturl':accounturl2} in user.socialnetworks #Add invalid social network account - r = self.app.post('/auth/prefs/add_social_network', + r = self.app.post('/auth/prefs/add_social_network', params=dict(accounturl = accounturl, socialnetwork='')) user = M.User.query.get(username='test-admin') assert len(user.socialnetworks) == 1 and \ @@ -480,40 +480,40 @@ class TestPreferences(TestController): #Add telephone number telnumber = '+3902123456' - r = self.app.post('/auth/prefs/add_telnumber', + r = self.app.post('/auth/prefs/add_telnumber', params=dict(newnumber=telnumber)) user = M.User.query.get(username='test-admin') assert (len(user.telnumbers) == 1 and (user.telnumbers[0] == telnumber)) #Add second telephone number telnumber2 = '+3902654321' - r = self.app.post('/auth/prefs/add_telnumber', + r = self.app.post('/auth/prefs/add_telnumber', params=dict(newnumber=telnumber2)) user = M.User.query.get(username='test-admin') assert (len(user.telnumbers) == 2 and telnumber in user.telnumbers and telnumber2 in user.telnumbers) #Remove first telephone number - r = self.app.post('/auth/prefs/remove_telnumber', + r = self.app.post('/auth/prefs/remove_telnumber', params=dict(oldvalue=telnumber)) user = M.User.query.get(username='test-admin') assert (len(user.telnumbers) == 1 and telnumber2 in user.telnumbers) #Add website website = 'http://www.testurl.com' - r = self.app.post('/auth/prefs/add_webpage', + r = self.app.post('/auth/prefs/add_webpage', params=dict(newwebsite=website)) user = M.User.query.get(username='test-admin') assert (len(user.webpages) == 1 and (website in user.webpages)) #Add second website website2 = 'http://www.testurl2.com' - r = self.app.post('/auth/prefs/add_webpage', + r = self.app.post('/auth/prefs/add_webpage', params=dict(newwebsite=website2)) user = M.User.query.get(username='test-admin') assert (len(user.webpages) == 2 and website in user.webpages and website2 in user.webpages) #Remove first website - r = self.app.post('/auth/prefs/remove_webpage', + r = self.app.post('/auth/prefs/remove_webpage', params=dict(oldvalue=website)) user = M.User.query.get(username='test-admin') assert (len(user.webpages) == 1 and website2 in user.webpages) @@ -528,7 +528,7 @@ class TestPreferences(TestController): endtime = time(12, 0, 0) result = self.app.get('/auth/prefs') - r = self.app.post('/auth/prefs/add_timeslot', + r = self.app.post('/auth/prefs/add_timeslot', params=dict( weekday=weekday, starttime=starttime.strftime('%H:%M'), @@ -542,7 +542,7 @@ class TestPreferences(TestController): endtime2 = time(16, 0, 0) #Add second availability timeslot - r = self.app.post('/auth/prefs/add_timeslot', + r = self.app.post('/auth/prefs/add_timeslot', params=dict( weekday=weekday2, starttime=starttime2.strftime('%H:%M'), @@ -553,7 +553,7 @@ class TestPreferences(TestController): and timeslot2dict in user.get_availability_timeslots() #Remove availability timeslot - r = self.app.post('/auth/prefs/remove_timeslot', + r = self.app.post('/auth/prefs/remove_timeslot', params=dict( weekday=weekday, starttime=starttime.strftime('%H:%M'), @@ -562,7 +562,7 @@ class TestPreferences(TestController): assert len(user.availability) == 1 and timeslot2dict in user.get_availability_timeslots() #Add invalid availability timeslot - r = self.app.post('/auth/prefs/add_timeslot', + r = self.app.post('/auth/prefs/add_timeslot', params=dict( weekday=weekday2, starttime=endtime2.strftime('%H:%M'), @@ -580,7 +580,7 @@ class TestPreferences(TestController): startdate = datetime(2012, 12, 14) enddate = datetime(2012, 12, 20) result = self.app.get('/auth/prefs') - r = self.app.post('/auth/prefs/add_inactive_period', + r = self.app.post('/auth/prefs/add_inactive_period', params=dict( startdate=startdate.strftime('%d/%m/%Y'), enddate=enddate.strftime('%d/%m/%Y'))) @@ -591,7 +591,7 @@ class TestPreferences(TestController): #Add second inactivity period startdate2 = datetime(2012, 12, 24) enddate2 = datetime(2012, 12, 28) - r = self.app.post('/auth/prefs/add_inactive_period', + r = self.app.post('/auth/prefs/add_inactive_period', params=dict( startdate=startdate2.strftime('%d/%m/%Y'), enddate=enddate2.strftime('%d/%m/%Y'))) @@ -601,7 +601,7 @@ class TestPreferences(TestController): and period2dict in user.get_inactive_periods() #Remove first inactivity period - r = self.app.post('/auth/prefs/remove_inactive_period', + r = self.app.post('/auth/prefs/remove_inactive_period', params=dict( startdate=startdate.strftime('%d/%m/%Y'), enddate=enddate.strftime('%d/%m/%Y'))) @@ -609,7 +609,7 @@ class TestPreferences(TestController): assert len(user.inactiveperiod) == 1 and period2dict in user.get_inactive_periods() #Add invalid inactivity period - r = self.app.post('/auth/prefs/add_inactive_period', + r = self.app.post('/auth/prefs/add_inactive_period', params=dict( startdate='NOT/A/DATE', enddate=enddate2.strftime('%d/%m/%Y'))) @@ -626,7 +626,7 @@ class TestPreferences(TestController): level = 'low' comment = 'test comment' result = self.app.get('/auth/prefs/user_skills') - r = self.app.post('/auth/prefs/user_skills/save_skill', + r = self.app.post('/auth/prefs/user_skills/save_skill', params=dict( level=level, comment=comment, @@ -639,7 +639,7 @@ class TestPreferences(TestController): level = 'medium' comment = 'test comment 2' result = self.app.get('/auth/prefs/user_skills') - r = self.app.post('/auth/prefs/user_skills/save_skill', + r = self.app.post('/auth/prefs/user_skills/save_skill', params=dict( level=level, comment=comment, @@ -651,7 +651,7 @@ class TestPreferences(TestController): #Add an invalid skill level2 = 'not a level' comment2 = 'test comment 2' - r = self.app.post('/auth/prefs/user_skills/save_skill', + r = self.app.post('/auth/prefs/user_skills/save_skill', params=dict( level=level2, comment=comment2, @@ -662,7 +662,7 @@ class TestPreferences(TestController): #Remove a skill result = self.app.get('/auth/prefs/user_skills') - r = self.app.post('/auth/prefs/user_skills/remove_skill', + r = self.app.post('/auth/prefs/user_skills/remove_skill', params=dict( categoryid=str(skill_cat.trove_cat_id))) user = M.User.query.get(username='test-admin')