Exemplo n.º 1
0
    def test_form_only_renders_who_paid_and_who_for_options_for_group(self):
        owner = User.objects.create_user(
            username='******', email='*****@*****.**')
        member = User.objects.create_user(
            username='******', email='*****@*****.**')
        not_member = User.objects.create_user(
            username='******', email='*****@*****.**')
        group = Group.objects.create(name='Members only')
        group.user_set.add(owner, member)
        form = NewPaymentForm(group_id=group.id)

        self.assertIn('*****@*****.**', form.as_p())
        self.assertEqual(form.as_p().count('*****@*****.**'), 2)
        self.assertIn('*****@*****.**', form.as_p())
        self.assertEqual(form.as_p().count('*****@*****.**'), 2)

        self.assertNotIn('*****@*****.**', form.as_p())
Exemplo n.º 2
0
    def test_form_only_renders_who_paid_and_who_for_options_for_group(self):
        owner = User.objects.create_user(username='******',
                                         email='*****@*****.**')
        member = User.objects.create_user(username='******',
                                          email='*****@*****.**')
        not_member = User.objects.create_user(username='******',
                                              email='*****@*****.**')
        group = Group.objects.create(name='Members only')
        group.user_set.add(owner, member)
        form = NewPaymentForm(group_id=group.id)

        self.assertIn('*****@*****.**', form.as_p())
        self.assertEqual(form.as_p().count('*****@*****.**'), 2)
        self.assertIn('*****@*****.**', form.as_p())
        self.assertEqual(form.as_p().count('*****@*****.**'), 2)

        self.assertNotIn('*****@*****.**', form.as_p())
Exemplo n.º 3
0
class NewPaymentFormIntegratedTest(DjangoTestCase):
    def setUp(self):
        group = Group.objects.create(name='Test')
        self.form = NewPaymentForm(group_id=group.id)

    def test_form_renders_icon_input(self):
        self.assertIn('id="input_icon"', self.form.as_p())

    def test_form_renders_date_input(self):
        today = '{dt:%d} {dt:%B} {dt:%Y}'.format(dt = date.today())
        self.assertIn('value="{}"'.format(today), self.form.as_p())
        self.assertIn('id="input_date"', self.form.as_p())

    def test_form_renders_amount_input(self):
        self.assertIn('placeholder="0.00"', self.form.as_p())
        self.assertIn('id="input_amount"', self.form.as_p())

    def test_form_renders_description_input(self):
        self.assertIn('placeholder="E.g. electricity bill"', self.form.as_p())
        self.assertIn('id="input_description"', self.form.as_p())

    def test_form_renders_who_paid_input(self):
        self.assertIn('id="input_who_paid"', self.form.as_p())

    def test_form_renders_who_for_input(self):
        self.assertIn('id="input_who_for"', self.form.as_p())

    def test_does_not_offer_none_as_who_paid_choice(self):
        self.assertNotIn('---------', self.form.as_p())

    def test_form_save_adds_payment_to_group(self):
        users = [User.objects.create_user(
            username='******'.format(str(i)),
            email='user{}@email.com'.format(str(i))
            ) for i in range(3)]
        group = Group.objects.create(name='Test Group')
        group.user_set.add(*users)
        form = NewPaymentForm(group_id=group.id, data={
            'icon': 'person_pin',
            'date': datetime.strptime('02 February 2011', '%d %B %Y'),
            'amount': '99.99',
            'description': 'bill',
            'who_paid': 1,
            'who_for': [1, 2],
        })
        form.save()
        payment = Payment.objects.first()
        self.assertEqual(payment.group, group)

    def test_form_only_renders_who_paid_and_who_for_options_for_group(self):
        owner = User.objects.create_user(
            username='******', email='*****@*****.**')
        member = User.objects.create_user(
            username='******', email='*****@*****.**')
        not_member = User.objects.create_user(
            username='******', email='*****@*****.**')
        group = Group.objects.create(name='Members only')
        group.user_set.add(owner, member)
        form = NewPaymentForm(group_id=group.id)

        self.assertIn('*****@*****.**', form.as_p())
        self.assertEqual(form.as_p().count('*****@*****.**'), 2)
        self.assertIn('*****@*****.**', form.as_p())
        self.assertEqual(form.as_p().count('*****@*****.**'), 2)

        self.assertNotIn('*****@*****.**', form.as_p())

    def test_form_save_does_not_add_new_payment_when_given_instance(self):
        users = [User.objects.create_user(
            username='******'.format(str(i))) for i in range(3)]
        group = Group.objects.create(name='Test Group')
        group.user_set.add(*users)
        payment = Payment.objects.create(
            date=datetime.strptime('02 February 2011', '%d %B %Y'),
            amount='99.99',
            description='bill',
            who_paid=users[0],
        )
        payment.who_for.add(*users)

        form = NewPaymentForm(group_id=group.id, instance=payment, data={
            'icon': 'person_pin',
            'date': datetime.strptime('11 March 2014', '%d %B %Y'),
            'amount': '22.50',
            'description': 'New Info',
            'who_paid': 3,
            'who_for': [2, 3],
        })
        self.assertTrue(form.is_valid())
        form.save()
        self.assertEqual(Payment.objects.count(), 1)

    def test_form_save_changes_attributes_for_existing_payment(self):
        users = [User.objects.create_user(
            username='******'.format(str(i))) for i in range(3)]
        group = Group.objects.create(name='Test Group')
        group.user_set.add(*users)
        payment = Payment.objects.create(
            date=datetime.strptime('02 February 2011', '%d %B %Y'),
            amount='99.99',
            description='bill',
            who_paid=users[0],
        )
        payment.who_for.add(*users)

        form = NewPaymentForm(group_id=group.id, instance=payment, data={
            'icon': 'person_pin',
            'date': datetime.strptime('11 March 2014', '%d %B %Y'),
            'amount': '22.50',
            'description': 'New Info',
            'who_paid': 3,
            'who_for': [2, 3],
        })
        self.assertTrue(form.is_valid())
        form.save()
        self.assertEqual(payment.date, datetime.strptime('11 March 2014', '%d %B %Y').date())
        self.assertEqual(payment.amount, 22.50)
        self.assertEqual(payment.description, 'New Info')
        self.assertEqual(payment.who_paid, users[2])
        self.assertListEqual(list(payment.who_for.all()), [users[1], users[2]])
Exemplo n.º 4
0
class NewPaymentFormIntegratedTest(DjangoTestCase):
    def setUp(self):
        group = Group.objects.create(name='Test')
        self.form = NewPaymentForm(group_id=group.id)

    def test_form_renders_icon_input(self):
        self.assertIn('id="input_icon"', self.form.as_p())

    def test_form_renders_date_input(self):
        today = '{dt:%d} {dt:%B} {dt:%Y}'.format(dt=date.today())
        self.assertIn('value="{}"'.format(today), self.form.as_p())
        self.assertIn('id="input_date"', self.form.as_p())

    def test_form_renders_amount_input(self):
        self.assertIn('placeholder="0.00"', self.form.as_p())
        self.assertIn('id="input_amount"', self.form.as_p())

    def test_form_renders_description_input(self):
        self.assertIn('placeholder="E.g. electricity bill"', self.form.as_p())
        self.assertIn('id="input_description"', self.form.as_p())

    def test_form_renders_who_paid_input(self):
        self.assertIn('id="input_who_paid"', self.form.as_p())

    def test_form_renders_who_for_input(self):
        self.assertIn('id="input_who_for"', self.form.as_p())

    def test_does_not_offer_none_as_who_paid_choice(self):
        self.assertNotIn('---------', self.form.as_p())

    def test_form_save_adds_payment_to_group(self):
        users = [
            User.objects.create_user(
                username='******'.format(str(i)),
                email='user{}@email.com'.format(str(i))) for i in range(3)
        ]
        group = Group.objects.create(name='Test Group')
        group.user_set.add(*users)
        form = NewPaymentForm(group_id=group.id,
                              data={
                                  'icon':
                                  'person_pin',
                                  'date':
                                  datetime.strptime('02 February 2011',
                                                    '%d %B %Y'),
                                  'amount':
                                  '99.99',
                                  'description':
                                  'bill',
                                  'who_paid':
                                  1,
                                  'who_for': [1, 2],
                              })
        form.save()
        payment = Payment.objects.first()
        self.assertEqual(payment.group, group)

    def test_form_only_renders_who_paid_and_who_for_options_for_group(self):
        owner = User.objects.create_user(username='******',
                                         email='*****@*****.**')
        member = User.objects.create_user(username='******',
                                          email='*****@*****.**')
        not_member = User.objects.create_user(username='******',
                                              email='*****@*****.**')
        group = Group.objects.create(name='Members only')
        group.user_set.add(owner, member)
        form = NewPaymentForm(group_id=group.id)

        self.assertIn('*****@*****.**', form.as_p())
        self.assertEqual(form.as_p().count('*****@*****.**'), 2)
        self.assertIn('*****@*****.**', form.as_p())
        self.assertEqual(form.as_p().count('*****@*****.**'), 2)

        self.assertNotIn('*****@*****.**', form.as_p())

    def test_form_save_does_not_add_new_payment_when_given_instance(self):
        users = [
            User.objects.create_user(
                username='******'.format(str(i))) for i in range(3)
        ]
        group = Group.objects.create(name='Test Group')
        group.user_set.add(*users)
        payment = Payment.objects.create(
            date=datetime.strptime('02 February 2011', '%d %B %Y'),
            amount='99.99',
            description='bill',
            who_paid=users[0],
        )
        payment.who_for.add(*users)

        form = NewPaymentForm(group_id=group.id,
                              instance=payment,
                              data={
                                  'icon':
                                  'person_pin',
                                  'date':
                                  datetime.strptime('11 March 2014',
                                                    '%d %B %Y'),
                                  'amount':
                                  '22.50',
                                  'description':
                                  'New Info',
                                  'who_paid':
                                  3,
                                  'who_for': [2, 3],
                              })
        self.assertTrue(form.is_valid())
        form.save()
        self.assertEqual(Payment.objects.count(), 1)

    def test_form_save_changes_attributes_for_existing_payment(self):
        users = [
            User.objects.create_user(
                username='******'.format(str(i))) for i in range(3)
        ]
        group = Group.objects.create(name='Test Group')
        group.user_set.add(*users)
        payment = Payment.objects.create(
            date=datetime.strptime('02 February 2011', '%d %B %Y'),
            amount='99.99',
            description='bill',
            who_paid=users[0],
        )
        payment.who_for.add(*users)

        form = NewPaymentForm(group_id=group.id,
                              instance=payment,
                              data={
                                  'icon':
                                  'person_pin',
                                  'date':
                                  datetime.strptime('11 March 2014',
                                                    '%d %B %Y'),
                                  'amount':
                                  '22.50',
                                  'description':
                                  'New Info',
                                  'who_paid':
                                  3,
                                  'who_for': [2, 3],
                              })
        self.assertTrue(form.is_valid())
        form.save()
        self.assertEqual(payment.date,
                         datetime.strptime('11 March 2014', '%d %B %Y').date())
        self.assertEqual(payment.amount, 22.50)
        self.assertEqual(payment.description, 'New Info')
        self.assertEqual(payment.who_paid, users[2])
        self.assertListEqual(list(payment.who_for.all()), [users[1], users[2]])