Esempio n. 1
0
    def testDeleteEmail(self):
        user = self.user
        user_email = UserEmail(user=user,
                               email='*****@*****.**',
                               verified=True,
                               default=False,
                               verification_key=UserEmail.VERIFIED)
        user_email.save()

        response = self.client.post('/account/deleteemail/%s/' % user_email.id,
                                    {
                                        'yes': 'yes',
                                    })

        self.assertRedirects(response, '/account/')

        user_emails = UserEmail.objects.filter(user=self.user)
        self.assertEqual(len(user_emails), 1)

        response = self.client.post(
            '/account/deleteemail/%s/' % user_emails[0].id, {
                'yes': 'yes',
            })

        self.assertStatusCode(response, Status.OK)
Esempio n. 2
0
 def testDeleteUnverifiedEmail(self):
     user_email = UserEmail(user=self.user, email='*****@*****.**', verified=False,
         default=False, verification_key=UserEmail.VERIFIED)
     user_email.save()
     
     response = self.client.post('/account/deleteemail/%s/' % user_email.id, {
         'yes': 'yes',
     })
     self.assertStatusCode(response, Status.NOT_FOUND)
Esempio n. 3
0
    def testResendEmail(self):
        user = self.user
        user_email = UserEmail(user=user, email='*****@*****.**', verified=False,
            default=False, verification_key='abcdef')
        user_email.save()

        response = self.client.get('/account/resendemail/%s/' % user_email.id)
        self.assertRedirects(response,
            '/account/addemail/continue/user%40example.org/')
        self.assertEqual(len(mail.outbox), 1)
Esempio n. 4
0
    def testDeleteEmail(self):
        user_email = UserEmail(user=self.user, email='*****@*****.**', verified=True,
            default=False, verification_key=UserEmail.VERIFIED)
        user_email.save()

        page_url = '/account/deleteemail/%s/' % user_email.id

        response = self.client.get(page_url)
        self.assertStatusCode(response, Status.OK)

        response = self.client.post(page_url, {'yes': 'yes'})
        self.assertRedirects(response, '/account/')
Esempio n. 5
0
    def createActiveUser(self, username='******', email='*****@*****.**',
        password='******'):

        user = User(username=username, email=email, is_active=True)
        user.first_name = 'John'
        user.set_password(password)
        user.save()

        user_email = UserEmail(user=user, email=email, verified=True,
            default=True, verification_key=UserEmail.VERIFIED)
        user_email.save()
        return user, user_email
Esempio n. 6
0
    def testSetDefaultEmail(self):
        user = self.user
        user_email = UserEmail(user=user, email='*****@*****.**', verified=True,
            default=False, verification_key=UserEmail.VERIFIED)
        user_email.save()

        response = self.client.post('/account/setdefaultemail/%s/' % user_email.id, {
            'yes': 'yes',
        })

        self.assertRedirects(response, '/account/')

        new_default_email = user_email.email

        for email in UserEmail.objects.filter():
            self.assertEqual(email.default, email.email == new_default_email)

        user = User.objects.get(id=self.user.id)
        self.assertEqual(user.email, new_default_email)
Esempio n. 7
0
    def testDeleteEmail(self):
        user = self.user
        user_email = UserEmail(user=user, email='*****@*****.**', verified=True,
            default=False, verification_key=UserEmail.VERIFIED)
        user_email.save()

        response = self.client.post('/account/deleteemail/%s/' % user_email.id, {
            'yes': 'yes',
        })

        self.assertRedirects(response, '/account/')

        user_emails = UserEmail.objects.filter(user=self.user)
        self.assertEqual(len(user_emails), 1)

        response = self.client.post('/account/deleteemail/%s/' % user_emails[0].id, {
            'yes': 'yes',
        })

        self.assertStatusCode(response, Status.OK)
Esempio n. 8
0
    def testCleanup(self):
        user1 = User(username='******',
                     email='*****@*****.**',
                     is_active=True)
        user1.save()

        old_enough = (datetime.now() -
                      timedelta(days=email_verification_days() + 1))
        not_old_enough = (datetime.now() -
                          timedelta(days=email_verification_days() - 1))

        email1 = UserEmail(user=user1,
                           email='*****@*****.**',
                           verified=True,
                           default=True,
                           verification_key=UserEmail.VERIFIED + 'asd',
                           code_creation_date=old_enough)
        email1.save()

        user2 = User(username='******',
                     email='*****@*****.**',
                     is_active=False)
        user2.save()

        email2 = UserEmail(user=user2,
                           email='*****@*****.**',
                           verified=False,
                           default=True,
                           verification_key='key1',
                           code_creation_date=old_enough)
        email2.save()

        user3 = User(username='******',
                     email='*****@*****.**',
                     is_active=False)
        user3.save()

        email3 = UserEmail(user=user3,
                           email='*****@*****.**',
                           verified=False,
                           default=True,
                           verification_key='key2',
                           code_creation_date=not_old_enough)
        email3.save()

        UserEmail.objects.delete_expired()

        user_ids = [user.id for user in User.objects.all()]
        user_email_ids = [
            user_email.id for user_email in UserEmail.objects.all()
        ]

        self.assertEqual(list(sorted(user_ids)),
                         list(sorted([user1.id, user3.id])))
        self.assertEqual(list(sorted(user_email_ids)),
                         list(sorted([email1.id, email3.id])))
Esempio n. 9
0
    def testCleanup(self):
        user1 = User(username='******', email='*****@*****.**', is_active=True)
        user1.save()

        old_enough = (datetime.now() - timedelta(days=email_verification_days() + 1))
        not_old_enough = (datetime.now() -
            timedelta(days=email_verification_days() - 1))

        email1 = UserEmail(user=user1, email='*****@*****.**',
            verified=True, default=True, 
            verification_key=UserEmail.VERIFIED + 'asd',
            code_creation_date=old_enough)
        email1.save() 

        user2 = User(username='******', email='*****@*****.**', is_active=False)
        user2.save()

        email2 = UserEmail(user=user2, email='*****@*****.**',
            verified=False, default=True, 
            verification_key='key1',
            code_creation_date=old_enough)
        email2.save()

        user3 = User(username='******', email='*****@*****.**', is_active=False)
        user3.save()

        email3 = UserEmail(user=user3, email='*****@*****.**',
            verified=False, default=True, 
            verification_key='key2',
            code_creation_date=not_old_enough)
        email3.save()

        UserEmail.objects.delete_expired()

        user_ids = [user.id for user in User.objects.all()]
        user_email_ids = [user_email.id for user_email in UserEmail.objects.all()]

        self.assertEqual(list(sorted(user_ids)), list(sorted([user1.id, user3.id])))
        self.assertEqual(list(sorted(user_email_ids)), list(sorted([email1.id, email3.id])))