def add_team(request): user = request.user if not user: return request.redirect("/") uid = request.get_form_var('uid') or '' name = request.get_form_var('name') or '' description = request.get_form_var('description') or '' errors = "" if request.method == "POST": teams = Team.gets() team_uid_pattern = re.compile(r'[a-zA-Z0-9\_]*') if not uid: error = 'uid_not_exists' elif not name: error = 'name_not_exists' elif uid != re.findall(team_uid_pattern, uid)[0]: error = 'invilid_uid' elif uid in [team.uid for team in teams]: error = 'uid_existed' elif User.check_exist(uid): error = 'user_id_existed' elif name in [team.name for team in teams]: error = 'name_existed' else: team = Team.add(uid, name, description) if team: team_created_signal.send(user.name, team_name=team.name, team_uid=team.uid) team.add_user(user, TEAM_OWNER) return request.redirect(team.url) return st('/teams/add_team.html', **locals())
def ttest_at_team(self): # FIXME mention = "test_team" team_name = "测试team" description = "测试" team = Team.add(mention, team_name, description) ok_(team.uid == mention) content = "@test_team code" users = get_mentions_from_text(content) # ok_(len(users) == 0) team_id = team.id user_id = "chengeng" identity = 2 rl = TeamUserRelationship.create(team_id=team_id, user_id=user_id, identity=identity) ok_(rl.user_id == user_id) users = get_mentions_from_text(content) ok_(users[0] == user_id) rl.delete() users = get_mentions_from_text(content) ok_(len(users) == 0) team.delete() users = get_mentions_from_text(content) ok_(users[0] == mention)
def test_at_team(self): mention = "test_team" team_name = "测试team" description = "测试" team = Team.add(mention, team_name, description) ok_(team.uid == mention) content = "@test_team code" users = get_mentions_from_text(content) ok_(len(users) == 0) team_id = team.id user_id = "chengeng" identity = 2 rl = TeamUserRelationship.create(team_id=team_id, user_id=user_id, identity=identity) ok_(rl.user_id == user_id) users = get_mentions_from_text(content) ok_(users[0] == user_id) rl.delete() users = get_mentions_from_text(content) ok_(len(users) == 0) team.delete() users = get_mentions_from_text(content) ok_(users[0] == mention)
def test_new_team_issue_participant_count(self): app = TestApp(M.app) team = Team.add("test_team", "test team", "test") issue = TeamIssue.add('test', 'test description', 'test', team=team.id) resp = app.get(issue.url) assert resp.status_int == 200 assert 'Issues' in resp.body assert '<strong>1</strong> participant' in resp.text assert '<strong>1</strong> participants' not in resp.text
def test_add_and_delete_team(self): team_id = "test_team" team_name = "测试team" description = "测试" n_team = len(Team.gets()) team = Team.add(team_id, team_name, description) new_n_team = len(Team.gets()) ok_(new_n_team == n_team + 1) ok_(team_id == team.uid) team.delete() new_n_team = len(Team.gets()) ok_(new_n_team == n_team)