Ejemplo n.º 1
0
    def test_confirm(self):
        fake_activate_key = 'secret-activate-key'

        with patch('tcms.auth.models.sha1') as sha1:
            sha1.return_value.hexdigest.return_value = fake_activate_key
            UserActivateKey.set_random_key_for_user(self.new_user)

        confirm_url = reverse('nitrate-activation-confirm',
                              args=[fake_activate_key])
        response = self.client.get(confirm_url)

        self.assertContains(
            response,
            'Your account has been activated successfully')

        self.assertContains(
            response,
            '<a href="{}">Continue</a>'.format(
                reverse('user-profile-redirect')),
            html=True)

        user = User.objects.get(username=self.new_user.username)
        self.assertTrue(user.is_active)
        activate_key_deleted = not UserActivateKey.objects.filter(user=user).exists()
        self.assertTrue(activate_key_deleted)
Ejemplo n.º 2
0
    def test_confirm(self):
        fake_activate_key = 'secret-activate-key'

        with patch('tcms.auth.models.sha1') as sha1:
            sha1.return_value.hexdigest.return_value = fake_activate_key
            UserActivateKey.set_random_key_for_user(self.new_user)

        confirm_url = reverse('nitrate-activation-confirm',
                              args=[fake_activate_key])
        response = self.client.get(confirm_url)

        self.assertContains(
            response,
            'Your account has been activated successfully')

        self.assertContains(
            response,
            '<a href="{}">Continue</a>'.format(
                reverse('user-profile-redirect')),
            html=True)

        user = User.objects.get(username=self.new_user.username)
        self.assertTrue(user.is_active)
        activate_key_deleted = not UserActivateKey.objects.filter(user=user).exists()
        self.assertTrue(activate_key_deleted)
Ejemplo n.º 3
0
 def test_set_random_key_forcely(self):
     new_activation_key = UserActivateKey.set_random_key_for_user(
         self.new_user, force=True)
     self.assertEqual(self.origin_activation_key.user,
                      new_activation_key.user)
     self.assertNotEqual(self.origin_activation_key.activation_key,
                         new_activation_key.activation_key)
Ejemplo n.º 4
0
    def test_set_random_key(self, random, mock_datetime):
        mock_datetime.datetime.today.return_value = datetime.datetime(2017, 5, 10)
        mock_datetime.timedelta.return_value = datetime.timedelta(7)
        fake_random = 0.12345678
        random.random.return_value = fake_random

        activation_key = UserActivateKey.set_random_key_for_user(self.new_user)

        self.assertEqual(self.new_user, activation_key.user)

        s_random = sha1(str(fake_random).encode('utf-8')).hexdigest()[:5]
        expected_key = sha1('{}{}'.format(
            s_random, self.new_user.username).encode('utf-8')).hexdigest()

        self.assertEqual(expected_key, activation_key.activation_key)
        self.assertEqual(datetime.datetime(2017, 5, 17),
                         activation_key.key_expires)
Ejemplo n.º 5
0
    def test_set_random_key(self, random, mock_datetime):
        mock_datetime.datetime.today.return_value = datetime.datetime(2017, 5, 10)
        mock_datetime.timedelta.return_value = datetime.timedelta(7)
        fake_random = 0.12345678
        random.random.return_value = fake_random

        activation_key = UserActivateKey.set_random_key_for_user(self.new_user)

        self.assertEqual(self.new_user, activation_key.user)

        if six.PY3:
            s_random = sha1(str(fake_random).encode('utf-8')).hexdigest()[:5]
            expected_key = sha1('{}{}'.format(
                s_random, self.new_user.username).encode('utf-8')).hexdigest()
        else:
            s_random = sha1(str(fake_random)).hexdigest()[:5]
            expected_key = sha1('{}{}'.format(
                s_random, self.new_user.username)).hexdigest()

        self.assertEqual(expected_key, activation_key.activation_key)
        self.assertEqual(datetime.datetime(2017, 5, 17),
                         activation_key.key_expires)
Ejemplo n.º 6
0
 def test_set_random_key_forcely(self):
     new_activation_key = UserActivateKey.set_random_key_for_user(self.new_user,
                                                                  force=True)
     self.assertEqual(self.origin_activation_key.user, new_activation_key.user)
     self.assertNotEqual(self.origin_activation_key.activation_key,
                         new_activation_key.activation_key)
Ejemplo n.º 7
0
 def setUpTestData(cls):
     cls.new_user = User.objects.create(username='******',
                                        email='*****@*****.**',
                                        password='******')
     cls.origin_activation_key = UserActivateKey.set_random_key_for_user(cls.new_user)
Ejemplo n.º 8
0
 def setUpTestData(cls):
     cls.new_user = User.objects.create(username='******',
                                        email='*****@*****.**',
                                        password='******')
     cls.origin_activation_key = UserActivateKey.set_random_key_for_user(cls.new_user)