class TestUpdateUserData(TestCase): def setUp(self): self.user = User(openId="ose6Ut8Ir-41wB7gQx89BifYa49Q",name="test") self.user.save() self.data = { "plan_name": "test_name", "begintime": u"2016-01-01 10:10", "endtime": u"2016-01-04 10:10", "goal": 10000, "tag0": "test_tag_0", "tag1": "test_tag_1", "tags": "test_tag_s", "friend0": self.user.openId, "comment": "test_comment" } def test_plan_create(self): conn = httplib.HTTPConnection(wechat_tools.domain[7:]) params = urllib.urlencode({ "userId":self.user.openId, "plan_name":self.data["plan_name"], "begintime":self.data["begintime"], "endtime":self.data["endtime"], "goal":self.data["goal"], "tag0":self.data["tag0"], "tag1":self.data["tag1"], "tags":self.data["tags"], "friend0":self.data["friend0"], "comment":self.data["comment"]}) headers = {"Content-type": "application/x-www-form-urlencode"} conn.request("POST","/plan/submit/make",params,headers) res = conn.getresponse() self.assertEqual(1, Plan.objects.all().count())
def callback(request): # Get the state saved in session expected_state = request.session.pop('auth_state', '') # Make the token request token = get_token_from_code(request.get_full_path(), expected_state) # Get the user's profile user = get_user(token) print(profstat) print(studstat) print(user) # Save token and user store_token(request, token) store_user(request, user) if User.objects.filter(username=user['surname']).exists(): print("Exists") else: new_user = User() new_user.is_student = studstat new_user.is_professor = profstat new_user.username = user['surname'] new_user.first_name = user['displayName'].split(" ")[0] new_user.last_name = user['displayName'].split(" ")[1] new_user.email = user['mail'] if ( user['mail'] != None) else user['userPrincipalName'] print(new_user) new_user.save() store(new_user, studstat, profstat) if studstat == True: return HttpResponseRedirect(reverse('home')) else: return HttpResponseRedirect(reverse('profhome'))
def subEvent(msg): data = tools.client.user.get(msg.source) try: username = data["nickname"] users = User.objects.filter(openId=msg.source) if len(users) > 0: user = users[0] else: user = User(name=data["nickname"], sex=int(data["sex"]), openId=msg.source, comment=u"现在还是空的><") user.save() team = Team(name=basic_tools.teamName(None, username), type=0) team.save() team.members.add(user) user.name = username user.uid = int(random.random() * 100) if "headimgurl" in data: user.image = data["headimgurl"] user.save() date = basic_tools.getDate() #如果DayData不存在,则创建 if DayData.objects.filter(user=user, date=date).count() == 0: dayData = DayData(user=user, date=date) basic_tools.updateDayData(dayData, user) dayData.save() except: username = "" return HttpResponse( create_reply(u"%s!欢迎使用新中韩无敌了的手环公众号!\n%s" % (username, tools.help_text), message=msg))
def setUp(self): self.user = User(openId="ose6Ut8Ir-41wB7gQx89BifYa49Q",name="test") self.user.save() self.data = { "plan_name": "test_name", "begintime": u"2016-01-01 10:10", "endtime": u"2016-01-04 10:10", "goal": 10000, "tag0": "test_tag_0", "tag1": "test_tag_1", "tags": "test_tag_s", "friend0": self.user.openId, "comment": "test_comment" }
def subEvent(msg): data = tools.client.user.get(msg.source) try: username = data["nickname"] users = User.objects.filter(openId=msg.source) if len(users) > 0: user = users[0] else: user = User(name=data["nickname"],sex=int(data["sex"]),openId=msg.source,comment=u"现在还是空的><") user.save() team = Team(name=basic_tools.teamName(None, username),type=0) team.save() team.members.add(user) user.name = username user.uid = int(random.random() * 100) if "headimgurl" in data: user.image = data["headimgurl"] user.save() date = basic_tools.getDate() #如果DayData不存在,则创建 if DayData.objects.filter(user=user,date=date).count() == 0: dayData = DayData(user=user,date=date) basic_tools.updateDayData(dayData, user) dayData.save() except: username = "" return HttpResponse(create_reply(u"%s!欢迎使用新中韩无敌了的手环公众号!\n%s" % (username, tools.help_text), message=msg))
class TestUpdateUserData(TestCase): def setUp(self): self.user = User(openId="ose6Ut8Ir-41wB7gQx89BifYa49Q",name="test") self.user.save() self.value = [100,50,25,12] def test_update_height(self): conn = httplib.HTTPConnection(wechat_tools.domain[7:]) conn.request("GET", "/basic/profile/data?userId=%s&type=0&value=%d" % (self.user.openId, self.value[0])) res = conn.getresponse() self.assertEqual(res.status, 200) self.assertEqual(res.reason, "OK") self.assertEqual(self.user.height, self.value[0]) def test_update_weight(self): conn = httplib.HTTPConnection(wechat_tools.domain[7:]) conn.request("GET", "/basic/profile/data?userId=%s&type=1&value=%d" % (self.user.openId, self.value[1])) res = conn.getresponse() self.assertEqual(res.status, 200) self.assertEqual(res.reason, "OK") self.assertEqual(self.user.weight, self.value[1]) def test_update_dayPlan(self): conn = httplib.HTTPConnection(wechat_tools.domain[7:]) conn.request("GET", "/basic/profile/data?userId=%s&type=2&value=%d" % (self.user.openId, self.value[2])) res = conn.getresponse() self.assertEqual(res.status, 200) self.assertEqual(res.reason, "OK") self.assertEqual(self.user.dayPlan, self.value[2]) def test_update_sleepPlan(self): conn = httplib.HTTPConnection(wechat_tools.domain[7:]) conn.request("GET", "/basic/profile/data?userId=%s&type=3&value=%d" % (self.user.openId, self.value[3])) res = conn.getresponse() self.assertEqual(res.status, 200) self.assertEqual(res.reason, "OK") self.assertEqual(self.user.sleepPlan, self.value[3])
def register(): if current_user.is_authenticated: return redirect(url_for('main.hello')) form = RegisterForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashed_password) db.session.add(user) db.session.commit() flash('Your account have been created! you may now login !', 'success') return redirect(url_for('main.hello')) return render_template('register.html', title='Register', form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('index')) form = RegistrationForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashed_password) #creating account db.session.add(user) #adding user to the database db.session.commit() flash('Your account has been created! You are now able to log in', category='success') return redirect(url_for('login')) return render_template('register.html', title='Register', form=form)
def reset_token(token): if current_user.is_authenticated: return redirect(url_for('main.hello')) user = User.verify_reset_token(token) if user is None: flash('That is an invalid or expired token', 'warning') return redirect(url_for('users.reset_request')) form = ResetPasswordForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user.password = hashed_password db.session.commit() flash('Your Password has been updated! Now you are able to login!', 'success') return redirect(url_for('users.login')) return render_template('reset_token.html', title='Reset Password', form=form)
def setUp(self): self.user = User(openId="ose6Ut8Ir-41wB7gQx89BifYa49Q",name="test") self.user.save() self.value = [100,50,25,12]