Beispiel #1
0
    def test_account_changepassword(self):

        u = User(email='*****@*****.**')
        u.is_active = True
        u.set_password('Myunittest1!')
        u.save()

        self.client.force_login(u)

        response = self.client.get(reverse('profiles:user_change_password'))
        self.assertEqual(response.status_code, HTTPStatus.OK)

        response = self.client.post(reverse('profiles:user_change_password'), data={
            'old_password': '******',
            'new_password1': 'myunittest1!passchange',
            'new_password2': 'myunittest1!passchange',
        })

        self.assertEqual(response.status_code, HTTPStatus.OK)
        self.assertIn('old_password', response.context['form'].errors)

        response = self.client.post(reverse('profiles:user_change_password'), data={
            'old_password': '******',
            'new_password1': 'Myunittest1!passchange',
            'new_password2': 'Myunittest1!passchange',
        })

        self.assertEqual(response.status_code, HTTPStatus.FOUND)
        self.assertEqual(response.url, reverse('profiles:user'))
    def handle(self, *args, **kwargs):
        east_blocks = [
            'PAKYONG', 'GANGTOK', 'REGU', 'RHENOCK', 'KHAMDONG',
            'RAKDONG TINTEK', 'DUGA', 'RANKA', 'MARTAM', 'PARAKHA'
        ]
        west_blocks = [
            'GYALSHING', 'SORENG', 'KALUK', 'DENTAM', 'DARAMDIN', 'YUKSAM',
            'BERMIOK MARTAM', 'CHONGRANG', 'CHUMBONG'
        ]
        north_blocks = ['MANGAN', 'CHUNGTHANG', 'KABI', 'PASSINGDONG']
        south_blocks = [
            'YANGANG', 'SUMBUK', 'NAMCHI', 'RAVANGLA', 'TEMI', 'JORETHANG',
            'SIKKIP', 'NAMTHANG'
        ]
        districts = ['east', 'west', 'north', 'south']
        for district in districts:
            user_obj = User()
            user_obj.username = district + '_admin'
            user_obj.set_password('Pass@123')
            user_obj.is_district_admin = True
            user_obj.save()
            district_obj = District.objects.create(
                user=user_obj, district_name=district.upper() + ' SIKKIM')

            for block in eval(district + '_blocks'):
                b_user_obj = User()
                b_user_obj.username = block.lower() + '_admin'
                b_user_obj.set_password('Pass@123')
                b_user_obj.is_block_admin = True
                b_user_obj.save()
                block_obj = Block.objects.create(user=b_user_obj,
                                                 block_name=block,
                                                 block_district=district_obj)
        print("Done")
Beispiel #3
0
    def test_account_edit(self):

        u = User(email='*****@*****.**')
        u.username = '******'
        u.name = 'Unit Test'
        u.is_active = True
        u.set_password('Myunitarytest1!')
        u.save()

        self.client.force_login(u)
  
        with self.settings(EMAIL_BACKEND='django.core.mail.backends.locmem.EmailBackend'):
            response = self.client.post(reverse('profiles:user_edit'), {
                'username': u.username,
                'name': 'Another Unit Test',
                'email': u.email,
            })
            self.assertEqual(response.status_code, HTTPStatus.FOUND)
            self.assertEqual(response.url, reverse('profiles:user'))
            self.assertEqual(len(mail.outbox), 1)

        u.refresh_from_db()

        self.assertTrue(u.is_active)
        self.assertEqual(u.name, 'Another Unit Test')
Beispiel #4
0
 def create_user(self):
     user = User(
         first_name=chance.first(gender='m', language='ru'),
         last_name=chance.last(gender='m', language='ru'),
         email=chance.email(),
         is_active=True,
         is_email_confirmed=True,
     )
     user.set_password("@120804a")
     user.save()
     self.stdout.write('Successfully created user (%s)' % (user.email, ))
     return user
Beispiel #5
0
 def create_user(self):
     user = User(
         first_name="Davit",
         last_name="Vardanyan",
         email="*****@*****.**",
         is_active=True,
         is_email_confirmed=True,
         is_superuser=True,
         is_staff=True,
     )
     user.set_password("@120804a")
     user.save()
     self.stdout.write('Successfully created user (%s)' % (user.email, ))
     return user
Beispiel #6
0
    def test_account_login(self):

        u = User(email='*****@*****.**')
        u.is_active = True
        u.set_password('Myunitarytest1!')
        u.save()

        next = reverse('profiles:user_edit')
        response = self.client.get(reverse('profiles:login') + '?next=' + next)

        response = self.client.post(reverse('profiles:login'), {
            'username': '******',
            'password': '******',
        })
        self.assertEqual(response.status_code, HTTPStatus.FOUND)
        self.assertEqual(response.url, next)
Beispiel #7
0
    def test_account_edit_email(self):

        u = User(email='*****@*****.**')
        u.username = '******'
        u.name = 'Unit Test'
        u.is_active = True
        u.set_password('Myunitarytest1!')
        u.save()

        self.client.force_login(u)

        with self.settings(
                EMAIL_BACKEND='django.core.mail.backends.locmem.EmailBackend'):
            response = self.client.post(reverse('profiles:user_edit'), {
                'username': u.username,
                'name': 'Another Unit Test',
                'email': '*****@*****.**',
            },
                                        follow=True)
            self.assertRedirects(
                response,
                reverse('profiles:login') + '?next=' +
                reverse('profiles:user'))
            self.assertEqual(response.status_code, HTTPStatus.OK)
            self.assertEqual(len(mail.outbox), 2)
            self.assertEqual(mail.outbox[0].to, ['*****@*****.**'])
            self.assertEqual(mail.outbox[1].to, ['*****@*****.**'])

        u.refresh_from_db()

        self.assertFalse(u.is_active)
        self.assertEqual(u.name, 'Another Unit Test')
        self.assertEqual(u.email, '*****@*****.**')

        token = mail.outbox[0].context['token']

        self.assertTrue('user_confirmation_token' in self.client.session)
        self.assertEqual(self.client.session['user_confirmation_token'], token)

        response = self.client.get(reverse('profiles:signup_confirm'),
                                   data={
                                       'token': token,
                                   })
        self.assertEqual(response.status_code, HTTPStatus.FOUND)
        self.assertEqual(response.url, reverse('profiles:user'))
Beispiel #8
0
    def save(self, commit=True):
        employee = super().save(commit=False)
        user = User()

        user.username = f'emp_{randint(1000, 9999)}'
        user.set_password('Pass@123')
        user.first_name = self.cleaned_data['first_name']
        user.middle_name = self.cleaned_data['middle_name']
        user.last_name = self.cleaned_data['last_name']
        user.date_of_birth = self.cleaned_data['date_of_birth']
        user.gender = self.cleaned_data['gender']
        user.is_employee = True
        user.is_teacher = self.cleaned_data['is_teacher']
        user.save()

        employee.employee_user = user

        if commit:
            return employee.save()
        return employee
Beispiel #9
0
from hackathons.models import Hackathon, Tier, Perk, Sponsorship, Lead

fake = Faker()

print("Generating users...")
users = []
for i in range(10):
    username = fake.user_name()
    user = User(
        first_name=fake.first_name(),
        last_name=fake.last_name(),
        email=fake.email(),
        username=username,
    )
    user.save()
    user.set_password(username)
    user.save()
    users.append(user)

print("Generating industries...")
industries = []
colors = {
    "Web Dev": "blue",
    "ML": "green",
    "Software": "purple",
    "Systems": "orange",
    "Data": "yellow",
}
for t in colors.keys():
    industry = Industry(name=t, color=colors[t])
    industry.save()
Beispiel #10
0
 def create_test_user(self, email=None, password=None):
     user = User(email=email or REGISTER_EMAIL)
     user.set_password(REGISTER_PASS or REGISTER_PASS)
     user.save()
     return user