Exemplo n.º 1
0
 def test_form_save_does_not_recreate_existing_users_by_email(self):
     existing_users = self.create_users()
     group = Group.objects.create(name='Existing')
     form = AddMembersForm(group_id=group.id, user=self.create_owner(), data={
         'emails_0': '*****@*****.**',
         })
     form.save()
     self.assertListEqual(list(User.objects.exclude(username='******')), existing_users)
Exemplo n.º 2
0
 def add_email_members(self, number=5):
     emails = ['test_{}@email.com'.format(str(i)) for i in range(number)]
     data = {}
     for i in range(len(emails)):
         data['emails_{}'.format(str(i))] = emails[i]
     group = Group.objects.create(name='Existing')
     form = AddMembersForm(group_id=group.id, user=self.create_owner(), data=data)
     form.save()
     return {'group': group, 'emails': emails}
Exemplo n.º 3
0
    def test_form_renders_email_input(self):
        user = User.objects.create_user(username='******')

        group = Group.objects.create(name='Existing')
        # group.user_set.add(user)

        form = AddMembersForm(group_id=group.id, user=user)
        self.assertIn('placeholder="Email address"', form.as_p())
        for i in range(5):
            self.assertIn('id="input_emails_{}'.format(str(i)), form.as_p())
Exemplo n.º 4
0
 def add_email_members(self, number=5):
     emails = ['test_{}@email.com'.format(str(i)) for i in range(number)]
     data = {}
     for i in range(len(emails)):
         data['emails_{}'.format(str(i))] = emails[i]
     group = Group.objects.create(name='Existing')
     form = AddMembersForm(group_id=group.id,
                           user=self.create_owner(),
                           data=data)
     form.save()
     return {'group': group, 'emails': emails}
Exemplo n.º 5
0
 def test_form_save_does_not_recreate_existing_quits_users_by_email(self):
     existing_quits_users = self.create_quits_users()
     group = Group.objects.create(name='Existing')
     form = AddMembersForm(group_id=group.id,
                           user=self.create_owner(),
                           data={
                               'emails_0': '*****@*****.**',
                           })
     form.save()
     self.assertListEqual(
         list(QuitsUser.objects.exclude(user__username='******')),
         existing_quits_users)
Exemplo n.º 6
0
    def test_form_renders_email_input(self):
        user = User.objects.create_user(username='******')

        group = Group.objects.create(name='Existing')
        # group.user_set.add(user)

        form = AddMembersForm(group_id=group.id, user=user)
        self.assertIn('placeholder="Email address"',
            form.as_p())
        for i in range(5):
            self.assertIn(
                'id="input_emails_{}'.format(str(i)),
                form.as_p()
            )
Exemplo n.º 7
0
    def test_form_validation_for_no_contacts_no_emails(self):
        user = self.create_owner()
        contacts = self.create_users()
        other_group = Group.objects.create(name="Other")
        other_group.user_set.add(user)
        other_group.user_set.add(*contacts)
        contact_ids = [contact.id for contact in contacts]

        group = Group.objects.create(name='Existing')

        data = {}
        for i in range(5):
            data['emails_{}'.format(str(i))] = ''
        form = AddMembersForm(group_id=group.id, user=user, data=data)
        self.assertFalse(form.is_valid())
Exemplo n.º 8
0
    def test_form_renders_only_fellow_group_members_as_contact_input(self):
        contacts = self.create_users()
        owner = User.objects.create_user(username='******')
        members = list(contacts)
        members.append(owner)
        other_group = Group.objects.create(name="Other")
        other_group.user_set.add(*members)
        not_contact = User.objects.create_user(username='******')

        group = Group.objects.create(name='Existing')

        form = AddMembersForm(group_id=group.id, user=owner)
        for contact in contacts:
            self.assertIn(contact.username, form.as_p())
        self.assertNotIn(not_contact.username, form.as_p())
Exemplo n.º 9
0
    def test_form_validation_for_no_contacts_no_emails(self):
        user = self.create_owner()
        contacts = self.create_users()
        other_group = Group.objects.create(name="Other")
        other_group.user_set.add(user)
        other_group.user_set.add(*contacts)
        contact_ids = [contact.id for contact in contacts]

        group = Group.objects.create(name='Existing')

        data = {}
        for i in range(5):
            data['emails_{}'.format(str(i))] = ''
        form = AddMembersForm(group_id=group.id, user=user, data=data)
        self.assertFalse(form.is_valid())
Exemplo n.º 10
0
    def test_form_renders_only_fellow_group_members_as_contact_input(self):
        contacts = self.create_users()
        owner = User.objects.create_user(username='******')
        members = list(contacts)
        members.append(owner)
        other_group = Group.objects.create(name="Other")
        other_group.user_set.add(*members)
        not_contact = User.objects.create_user(username='******')

        group = Group.objects.create(name='Existing')

        form = AddMembersForm(group_id=group.id, user=owner)
        for contact in contacts:
            self.assertIn(contact.username, form.as_p())
        self.assertNotIn(not_contact.username, form.as_p())
Exemplo n.º 11
0
def edit_group(request, group_id):
    group = confirm_user_in_group(request.user, group_id)
    if not group:
        raise Http404

    if request.method == 'POST':
        group_form = EditGroupForm(instance=group, data=request.POST)
        if group_form.is_valid():
            group_form.save()
            Edit.objects.create(
                group=group,
                user=request.user,
                change='name'
                )

        quits_group_form = EditQuitsGroupForm(
            instance=group.quitsgroup, data=request.POST)
        if quits_group_form.is_valid():
            quits_group_form.save()
            Edit.objects.create(
                group=group,
                user=request.user,
                change='curren'
                )

        return redirect('view_group', group_id)

    context = {
        'group_id': group_id,
        'group_form': EditGroupForm(instance=group),
        'quits_group_form': EditQuitsGroupForm(instance=group.quitsgroup),
        'add_members_form': AddMembersForm(group_id=group_id, user=request.user)
    }
    return render(request, 'quits/edit_group.html', context)
Exemplo n.º 12
0
    def test_form_save_adds_contacts_to_group(self):
        user = self.create_owner()
        contacts = self.create_users()
        gang = list(contacts)
        gang.append(user)
        other_group = Group.objects.create(name="Other")
        other_group.user_set.add(*gang)
        contact_ids = [contact.id for contact in contacts]

        group = Group.objects.create(name='Existing')

        form = AddMembersForm(group_id=group.id, user=user, data={
            'name': 'Household expenses',
            'contacts': contact_ids,
            })
        form.save()
        self.assertEqual(list(group.user_set.exclude(username='******')), contacts)
Exemplo n.º 13
0
def add_members(request, group_id):
    group = confirm_user_in_group(request.user, group_id)
    if not group:
        raise Http404
    form = None
    user = request.user

    if request.method == 'POST':
        form = AddMembersForm(group_id=group_id, user=user, data=request.POST)
        if form.is_valid():
            form.save()
            members = [c for c in form.cleaned_data.get('contacts')]
            members += form.email_users
            for member in members:
                Edit.objects.create(
                    group=group,
                    user=user,
                    change='addmem',
                    added_member=member,
                    )
            send_invitations(request=request, user=user,
                emails=[user.email for user in form.email_users])
            return redirect('view_group', group_id)

    if not form:
        form = AddMembersForm(group_id=group_id, user=user)
    context = {
        'group_name': group.name,
        'group_id': group_id,
        'form': form,
    }
    return render(request, 'quits/add_members.html', context)
Exemplo n.º 14
0
    def test_form_save_adds_contacts_to_group(self):
        user = self.create_owner()
        contacts = self.create_users()
        gang = list(contacts)
        gang.append(user)
        other_group = Group.objects.create(name="Other")
        other_group.user_set.add(*gang)
        contact_ids = [contact.id for contact in contacts]

        group = Group.objects.create(name='Existing')

        form = AddMembersForm(group_id=group.id,
                              user=user,
                              data={
                                  'name': 'Household expenses',
                                  'contacts': contact_ids,
                              })
        form.save()
        self.assertEqual(
            list(group.user_set.exclude(username='******')), contacts)
Exemplo n.º 15
0
 def test_form_renders_contact_input(self):
     group = Group.objects.create(name='Existing')
     form = AddMembersForm(group_id=1, user=self.create_owner())
     self.assertIn('id="input_contacts"', form.as_p())
Exemplo n.º 16
0
 def test_form_renders_contact_input(self):
     group = Group.objects.create(name='Existing')
     form = AddMembersForm(group_id=1, user=self.create_owner())
     self.assertIn('id="input_contacts"', form.as_p())