Exemplo n.º 1
0
def login(user, password=None, **kwargs):
    if not password:
        password = '******'

    if 'context' in kwargs:
        context = kwargs['context']
        if hasattr(context, 'client'):
            if context.client.user.username == user:
                #如果已经登录了,且登录用户与user相同,直接返回
                return context.client
            else:
                #如果已经登录了,且登录用户不与user相同,退出登录
                context.client.logout()

    #client = WeappClient(HTTP_USER_AGENT='WebKit MicroMessenger Mozilla')
    client = Client()
    client.login(username=user, password='******')
    client.user = User.objects.get(username=user)
    client.user.profile = UserProfile.objects.get(user=client.user)

    if 'context' in kwargs:
        context = kwargs['context']
        context.client = client

    return client
Exemplo n.º 2
0
Arquivo: tests.py Projeto: boxed/curia
    def answer_invitation_email(self, community, password):
        invitation_url = re.compile(
            r'%s\.eldmyra\.se(.*?)"' % community).search(
                mail.outbox[0].html_message).groups(0)[0].replace(
                    '&', '&')
        invitation_url, params = split_url_and_params(invitation_url)

        new_client = Client()
        new_client.community = 'test'
        response = new_client.post(
            invitation_url, {
                'first_name': params['email'].replace('@', '_').replace(
                    '.', '_'),
                'last_name': 'User',
                'birthday': '1980-04-17',
                'gender': 'M',
                'password': password,
                'confirm_password': password,
                'email': params['email'],
                'email': params['email'],
                'code': params['code'],
                'user_contract': 'checked'
            })
        self.assertEquals(response.status_code, 302)
        self.assertEquals(
            response['Location'],
            'http://community.%s.eldmyra.se/' % new_client.community)
        new_client.user = User.objects.get(email=params['email'])
        del mail.outbox[0]
        return new_client
Exemplo n.º 3
0
Arquivo: tests.py Projeto: boxed/curia
    def answer_invitation_email(self, community, password):
        invitation_url = re.compile(r'%s\.eldmyra\.se(.*?)"' % community).search(mail.outbox[0].html_message).groups(0)[0].replace('&', '&')
        invitation_url, params = split_url_and_params(invitation_url)

        new_client = Client()
        new_client.community = 'test'
        response = new_client.post(invitation_url, {'first_name':params['email'].replace('@', '_').replace('.', '_'), 'last_name':'User', 'birthday':'1980-04-17', 'gender':'M', 'password':password, 'confirm_password':password, 'email':params['email'], 'email':params['email'], 'code':params['code'], 'user_contract':'checked'})
        self.assertEquals(response.status_code, 302)
        self.assertEquals(response['Location'], 'http://community.%s.eldmyra.se/' % new_client.community)
        new_client.user = User.objects.get(email=params['email'])
        del mail.outbox[0]
        return new_client
Exemplo n.º 4
0
 def create_request(cls, request_url, username, password):
     # Initialize request
     request = Client().get(request_url).wsgi_request
     # Create user
     request.user = get_user_model().objects.create_user(username=username,
                                                         email=username,
                                                         password=password)
     # Create couch user
     request.couch_user = CouchUser()
     # Login
     assert Client().login(username=username, password=password)
     # Activate middleware
     OTPMiddleware().process_request(request)
     return request
Exemplo n.º 5
0
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.test.client import Client
import unittest

client = Client()
client.user = User.objects.create_user('john', '*****@*****.**', 'johnpassword')
client.login(username='******', password='******')

class LoginTestCase(unittest.TestCase):
    def setUp(self):
        self.client = Client()
        self.user = User.objects.create_user('john', '*****@*****.**', 'johnpassword')

    def testLogin(self):
        response = client.get(reverse('initLayersLayout'))
        self.assertEqual(response.status_code, 200)