Esempio n. 1
0
def user_activation(request, code,
                    template_name="users/user_activation.html"):
    try:
        activation = UserActivationCode.objects.get(code=code)
        active = activation.is_active()
    except UserActivationCode.DoesNotExist:
        activation = active = False
    if active:
        user = activation.user
        user.is_active = True
        user.save()
        
        try:
            consumer = Consumer.objects.get(user=user)
        except Consumer.DoesNotExist:
            consumer = Consumer(name=user.username, user=user,
                                status='accepted')
            consumer.generate_random_codes()
            consumer.save()
        
        try:
            token = Token.objects.get(user=user, consumer=consumer)
        except Token.DoesNotExist:
            token = Token(user=user, consumer=consumer, is_approved=True,
                          timestamp=time.time(),
                          token_type=Token.ACCESS)
            token.generate_random_codes()
            token.save()
        
    extra_context = {
        'active': active,
        'activation': activation
    }
    return direct_to_template(request, template_name,
                              extra_context=extra_context)
Esempio n. 2
0
    def setUp(self):
        self.user = User.objects.create_user('username', '*****@*****.**',
                                             'userpassword')
        self.user.save()

        self.client = Client()
        self.client.login(username='******', password='******')

        self.consumer = Consumer(name=self.user.username,
                                 status='accepted',
                                 user=self.user)
        self.consumer.generate_random_codes()
        self.consumer.save()

        self.token = Token(token_type=Token.ACCESS,
                           timestamp=time.time(),
                           is_approved=True,
                           user=self.user,
                           consumer=self.consumer)
        self.token.generate_random_codes()
        self.token.save()
Esempio n. 3
0
def user_activation(request, code,
                    template_name="users/user_activation.html"):
    try:
        activation = UserActivationCode.objects.get(code=code)
        active = activation.is_active()
    except UserActivationCode.DoesNotExist:
        activation = active = False
    if active:
        user = activation.user
        user.is_active = True
        user.save()
        try:
            consumer = Consumer.objects.get(user=user)
        except Consumer.DoesNotExist:
            consumer = Consumer(name=user.username, user=user,
                                status='accepted')
            consumer.generate_random_codes()
            consumer.save()
        
        try:
            token = Token.objects.get(user=user, consumer=consumer)
        except Token.DoesNotExist:
            token = Token(user=user, consumer=consumer, is_approved=True,
                          timestamp=time.time(),
                          token_type=Token.ACCESS)
            token.generate_random_codes()
            token.save()
        
    extra_context = {
        'active': active,
        'activation': activation
    }
    return direct_to_template(request, template_name,
                              extra_context=extra_context)
Esempio n. 4
0
 def setUp(self):
     self.user = User.objects.create_user('user', '*****@*****.**',
         'userpassword')
     self.user.save()
     
     self.client = Client()
     self.client.login(username='******', password='******')
     
     self.consumer = Consumer(name=self.user.username, status='accepted',
                              user=self.user)
     self.consumer.generate_random_codes()
     self.consumer.save()
     
     self.token = Token(token_type=Token.ACCESS, timestamp=time.time(),
                           is_approved=True, user=self.user,
                           consumer=self.consumer)
     self.token.generate_random_codes()
     self.token.save()
Esempio n. 5
0
class UserTest(TestCase):
    """Tests for users
    """
    
    def setUp(self):
        self.user = User.objects.create_user('user', '*****@*****.**',
            'userpassword')
        self.user.save()
        
        self.client = Client()
        self.client.login(username='******', password='******')
        
        self.consumer = Consumer(name=self.user.username, status='accepted',
                                 user=self.user)
        self.consumer.generate_random_codes()
        self.consumer.save()
        
        self.token = Token(token_type=Token.ACCESS, timestamp=time.time(),
                              is_approved=True, user=self.user,
                              consumer=self.consumer)
        self.token.generate_random_codes()
        self.token.save()
        
    def test_user_profile(self):
        profile = self.user.get_profile()
        self.assertEqual(profile.in_search, True)
        self.assertEqual(profile.is_public, True)

    def test_private_profile(self):
        response = self.client.get('/user/profile/')
        self.assertEqual(response.status_code, 200)
        
    def test_my_public_profile(self):
        response = self.client.get('/user/public/%s/' % self.user.username)
        self.assertEqual(response.status_code, 200)
        
    def test_public_profile(self):
        another_user = User.objects.create_user('another_user',
            '*****@*****.**', 'userpassword')
        another_user.save()
        
        response = self.client.get('/user/public/%s/' % another_user.username)
        self.assertEqual(response.status_code, 200)
        
        profile = another_user.get_profile()
        profile.is_public = False
        profile.save()
        response = self.client.get('/user/public/%s/' % another_user.username)
        self.assertEqual(response.status_code, 403)
        
    def test_refresh_access_token(self):
        token_key = self.token.key
        token_secret = self.token.secret
        
        response = self.client.get('/user/refresh_access_token/')
        self.assertEqual(response.status_code, 200)
        
        token = Token.objects.get(user=self.user)
        
        self.assertNotEqual(token.key, token_key)
        self.assertNotEqual(token.secret, token_secret)
Esempio n. 6
0
class UserTest(TestCase):
    """Tests for users
    """
    def setUp(self):
        self.user = User.objects.create_user('username', '*****@*****.**',
                                             'userpassword')
        self.user.save()

        self.client = Client()
        self.client.login(username='******', password='******')

        self.consumer = Consumer(name=self.user.username,
                                 status='accepted',
                                 user=self.user)
        self.consumer.generate_random_codes()
        self.consumer.save()

        self.token = Token(token_type=Token.ACCESS,
                           timestamp=time.time(),
                           is_approved=True,
                           user=self.user,
                           consumer=self.consumer)
        self.token.generate_random_codes()
        self.token.save()

    def test_user_profile(self):
        profile = self.user.get_profile()
        self.assertEqual(profile.in_search, True)
        self.assertEqual(profile.is_public, True)

    def test_private_profile(self):
        response = self.client.get('/user/profile/')
        self.assertEqual(response.status_code, 200)

    def test_my_public_profile(self):
        response = self.client.get('/user/public/%s/' % self.user.username)
        self.assertEqual(response.status_code, 200)

    def test_public_profile(self):
        another_user = User.objects.create_user('another_user',
                                                '*****@*****.**',
                                                'userpassword')
        another_user.save()

        response = self.client.get('/user/public/%s/' % another_user.username)
        self.assertEqual(response.status_code, 200)

        profile = another_user.get_profile()
        profile.is_public = False
        profile.save()
        response = self.client.get('/user/public/%s/' % another_user.username)
        self.assertEqual(response.status_code, 403)

    def test_refresh_access_token(self):
        token_key = self.token.key
        token_secret = self.token.secret

        response = self.client.get('/user/refresh_access_token/')
        self.assertEqual(response.status_code, 200)

        token = Token.objects.get(user=self.user)

        self.assertNotEqual(token.key, token_key)
        self.assertNotEqual(token.secret, token_secret)

    def test_is_staffStatus(self):
        self.user.is_staff = True
        self.user.save()
        self.user.is_staff = False
        self.user.save()

    def test_is_activeStatus(self):
        self.user.is_active = True
        self.user.save()
        self.user.is_acive = False
        self.user.save()

    def test_is_authorize(self):
        self.user.is_staff = False
        response = self.client.get('/user/users/')
        self.assertEqual(response.status_code, 404)