def delete_all(): users=User.objects.all() client=Client(MockRequest()) for user in users: results=client.user_get_user(user.username) if results and int(results[0])>0: client.user_delete(results[0])
def update_user_reference_id(username): users=User.objects.all() from django.db import connection client=Client(MockRequest()) results=client.user_get_user(username) print results id= int(results[0]) if results and id>0: print 'test' try: rs=connection.cursor() rs.execute('update auth_user set reference_id=%s where username=%s',[id,username]) except: transaction.rollback() raise else: transaction.commit() rs.close()
def update_reference_id(): users=User.objects.all() from django.db import connection client=Client(MockRequest()) for user in users: results=client.user_get_user(user.username) if results and int(results[0])>0: rs=connection.cursor() rs.execute('update auth_user set reference_id=%s where id=%s',[results[0],user.id])
def import_user(): '''导入亿脉通所有用户''' users=User.objects.all() from django.db import connection client=Client(MockRequest()) for user in users: print 'import %s ' % user.username username=user.username id= client.user_register(username,'123456',user.email) if int(id)>0: rs=connection.cursor() rs.execute('update auth_user set reference_id=%s where id=%s',[id,user.id]) rs.close()
def import_user_by_name(username,password): '''导入亿脉通所有用户''' user=User.objects.get(username=username) from django.db import connection client=Client(MockRequest()) print 'import %s ' % username s= client.user_register(username,password,user.email) print s return if int(id)>0: try: rs=connection.cursor() rs.execute('update auth_user set reference_id=%s where id=%s',[id,user.id]) rs.close() except: transaction.rollback() raise else: transaction.commit()
def setUp(self): request=MockRequest() self.client=Client(request)
class ClientTestCase(unittest.TestCase): def setUp(self): request=MockRequest() self.client=Client(request) # def testUserRegister(self): # print self.client.user_register('ggl','123456','*****@*****.**') def testAPPLs(self): print self.client.app_ls() def testSynLogin(self): uid=self.client.user_login('ucenter','123456')[0] self.assertTrue(int(uid)>0) print self.client.user_synlogin(uid) def testCheckEmail(self): self.assertEquals(int(self.client.user_check_email('*****@*****.**')),1) #已经存在,但后台允许重复注册的情况下 def testGetUser(self): print self.client.user_get_user('ucenter') def testUserLogin(self): self.assertTrue( int(self.client.user_login('admin','123456')[0])>0) print self.client.user_login('ucenter','12345678') self.assertEquals( int(self.client.user_login('ucenter','12345678')[0]),-2) #密码错 self.assertEquals( int(self.client.user_login('ucednter','12345678')[0]),-1) #用户不存在,或者被删除 def testCheckUserName(self): self.assertTrue(int( self.client.user_check_username('ucenter'))==-3) #用户名已经存在 self.assertTrue(int( self.client.user_check_username(u'蒋建校'.encode('gbk')))==1) #合法
def test(request): if request.method=='POST': username=request.REQUEST.get('username','') password=request.REQUEST.get('password','') try: user=User.objects.get(username=username) except User.DoesNotExist: return HttpResponse(u'用户不存在') email=user.email from it.ucenter.client import Client client=Client(request) result=client.user_register(username,password,email) if not (result in REGISTER_STATUS): try: result=int(result) if result>0: try: from django.db import connection rs=connection.cursor() rs.execute('update auth_user set reference_id=%s where username=%s',[result,username]) rs.close() except: transaction.rollback() raise else: transaction.commit() return HttpResponse(u'注册成功 返回 uid %s ' % result) return HttpResponse(u'未知错误,返回代码 %s' % result) except: raise return HttpResponse(u'未知错误,返回 %s' % result) else: return HttpResponse(REGISTER_STATUS[result]) else: return HttpResponse(''' <html> <head> <title>手动同步账号到bbs</title> </head> <body> <form action='.' method='POST'> <table> <tr><td colspan='2'>输入您在亿脉通中的账号和密码</td></tr> <tr> <td>用户名</td><td><input type='text' name='username'></td> </tr> <tr> <td>口令</td> <td> <input type='password' name='password'> </td> </tr> </table> <center> <input type='submit' value='test register'/> </center> </form> </body> </html> ''')