Пример #1
0
class ValidUserFormTest(FormTest):

    def setUp(self):
        super(ValidUserFormTest, self).setUp()

        self.user_form = UserForm(self.data)
        self.user_form.is_valid()
        self.new_user = self.user_form.save()

    def test_form_must_be_valid(self):
        self.assertTrue(self.user_form.is_valid())

    def test_save_user(self):
        self.assertIsInstance(self.new_user, User)

    def test_should_store_first_name(self):
        self.assertEqual(self.new_user.first_name, 'Valder Gallo')

    def test_should_store_last_name(self):
        self.assertEqual(self.new_user.last_name, 'Jr')

    def test_should_store_email(self):
        self.assertEqual(self.new_user.email, self.data.get('email'))

    def test_should_store_username(self):
        self.assertEqual(self.new_user.username, 'valdergallojr')
Пример #2
0
def member_form(request):
    try:
        member = Member.objects.get(user=request.user)
    except Member.DoesNotExist:
        member = Member()
    user_form = UserForm(request.POST or None, instance=request.user)
    member_form = MemberForm(request.POST or None, instance=member)
    if request.POST:
        if member_form.is_valid() and user_form.is_valid():
            member_form.save(user=request.user)
            user_form.save()
            messages.add_message(request, messages.INFO, _('Your data was updated successfully'))
            return HttpResponseRedirect(reverse('members-dashboard'))
        else:
            messages.add_message(
                request, messages.ERROR,
                _('An error occurred while trying to save your data. check the form below. '))

    return render(
        request,
        "members/member_form.html", {
            "member_form": member_form,
            'user_form': user_form
        }
    )
Пример #3
0
    def setUp(self):
        self.user_form = UserForm(self.data)
        self.user_form.is_valid()

        self.member_form = MemberForm(self.data)
        self.member_form.is_valid()
        self.user_instance = self.user_form.save()
        self.member_instance = self.member_form.save(self.user_instance)
Пример #4
0
class ValidMemberFormTest(FormTest):

    def setUp(self):
        super(ValidMemberFormTest, self).setUp()

        self.user_form = UserForm(self.data)
        self.user_form.is_valid()

        self.member_form = MemberForm(self.data)
        self.member_form.is_valid()
        self.user_instance = self.user_form.save()
        self.member_instance = self.member_form.save(self.user_instance)

    def test_form_must_be_valid(self):
        self.assertTrue(self.member_form.is_valid())

    def test_should_create_an_user(self):
        self.assertEqual(self.user_instance.get_full_name(), self.data.get('full_name'))
        self.assertIsInstance(self.member_instance.user, User)

    def test_should_store_a_city(self):
        city = City.objects.get(name='Sao Paulo', state='SP')
        self.assertEqual(self.member_instance.city, city)

    def test_should_store_organization(self):
        organization = Organization.objects.get(name='Home')
        self.assertEqual(self.member_instance.organization, organization)

    def test_should_store_cpf(self):
        self.assertEqual(self.member_instance.cpf, self.data.get('cpf'))

    def test_should_store_phone(self):
        self.assertEqual(self.member_instance.phone, '11-9949-2911')

    def test_should_store_address(self):
        self.assertEqual(self.member_instance.address, self.data.get('address'))

    def test_should_store_public_key(self):
        self.assertEqual(self.member_instance.public_key, self.data.get('public_key'))

    def test_should_store_category(self):
        category = Category.objects.get(id=self.data.get('category'))
        self.assertEqual(self.member_instance.category, category)

    def test_should_store_relation_with_community(self):
        self.assertEqual(self.member_instance.relation_with_community, self.data.get('relation_with_community'))

    def test_should_store_mailing(self):
        self.assertEqual(self.member_instance.mailing, self.data.get('mailing'))

    def test_should_store_partner(self):
        self.assertEqual(self.member_instance.partner, self.data.get('partner'))
Пример #5
0
def register(request):
    member_form = MemberForm(request.POST or None)
    user_form = UserForm(request.POST or None)
    if request.method == 'POST' and user_form.is_valid() and member_form.is_valid():
        user = user_form.save()
        member_form.save(user)

    return render(request,
        'flatpages/form.html',
            {
            'flatpage': {'title': u'Pedido de associação à APyB'},
            'user_form': user_form,
            'member_form': member_form,
            })
Пример #6
0
def register(request):
    member_form = MemberForm(request.POST or None)
    user_form = UserForm(request.POST or None)
    saved = False

    if request.method == 'POST' and user_form.is_valid() and member_form.is_valid():
        user = user_form.save()
        member_form.save(user)
        saved = True

    return render(request,
        'members/member_register.html',
            {
            'saved': saved,
            'user_form': user_form,
            'member_form': member_form,
            })
Пример #7
0
    def setUp(self):
        self.user_form = UserForm(self.data)
        self.user_form.is_valid()

        self.member_form = MemberForm(self.data)
        self.member_form.is_valid()
        self.user_instance = self.user_form.save()
        self.member_instance = self.member_form.save(self.user_instance)
Пример #8
0
def register(request):
    member_form = MemberForm(request.POST or None)
    user_form = UserForm(request.POST or None)
    saved = False

    if request.method == 'POST' and user_form.is_valid() and member_form.is_valid():
        user = user_form.save()
        member = member_form.save(user)
        saved = True
        return HttpResponseRedirect(reverse('payment', kwargs={'member_id':member.id}))

    return render(request,
        'members/member_register.html',
            {
            'saved': saved,
            'user_form': user_form,
            'member_form': member_form,
            })
Пример #9
0
    def setUp(self):
        super(ValidMemberFormTest, self).setUp()

        self.user_form = UserForm(self.data)
        self.user_form.is_valid()

        self.member_form = MemberForm(self.data)
        self.member_form.is_valid()
        self.user_instance = self.user_form.save()
        self.member_instance = self.member_form.save(self.user_instance)
Пример #10
0
class ValidUserFormTest(UserFormTest):
    def setUp(self):
        self.user_form = UserForm(self.data)
        self.user_form.is_valid()
        self.new_user = self.user_form.save()

    def test_form_must_be_valid(self):
        self.assertTrue(self.user_form.is_valid())

    def test_save_user(self):
        self.assertIsInstance(self.new_user, User)

    def test_should_store_first_name(self):
        self.assertEqual(self.new_user.first_name, 'Valder')

    def test_should_store_last_name(self):
        self.assertEqual(self.new_user.last_name, 'Gallo Jr')

    def test_should_store_email(self):
        self.assertEqual(self.new_user.email, self.data.get('email'))
Пример #11
0
class ValidMemberFormTest(MemberFormTest):
    def setUp(self):
        self.user_form = UserForm(self.data)
        self.user_form.is_valid()

        self.member_form = MemberForm(self.data)
        self.member_form.is_valid()
        self.user_instance = self.user_form.save()
        self.member_instance = self.member_form.save(self.user_instance)

    def test_form_must_be_valid(self):
        self.assertTrue(self.member_form.is_valid())

    def test_should_store_location(self):
        self.assertEqual(self.member_instance.location, 'Sao Paulo')

    def test_should_store_organization(self):
        organization = Organization.objects.get(name='Home')
        self.assertEqual(self.member_instance.organization, organization)

    def test_should_store_cpf(self):
        self.assertEqual(self.member_instance.cpf, self.data.get('cpf'))

    def test_should_store_phone(self):
        self.assertEqual(self.member_instance.phone, '11-9949-2911')

    def test_should_store_address(self):
        self.assertEqual(self.member_instance.address, self.data.get('address'))

    def test_should_store_category(self):
        category = Category.objects.get(id=self.data.get('category'))
        self.assertEqual(self.member_instance.category, category)

    def test_should_store_relation_with_community(self):
        self.assertEqual(self.member_instance.relation_with_community, self.data.get('relation_with_community'))

    def test_should_store_mailing(self):
        self.assertEqual(self.member_instance.mailing, self.data.get('mailing'))

    def test_should_store_partner(self):
        self.assertEqual(self.member_instance.partner, self.data.get('partner'))
Пример #12
0
class InvalidUserFormTest(UserFormTest):
    def setUp(self):
        self.user_form = UserForm({})

    def test_must_be_invalid(self):
        self.assertFalse(self.user_form.is_valid())

    def test_with_no_data_should_return_email_error(self):
        self.assertTrue(self.user_form.errors.has_key('email'))

    def test_with_no_data_should_return_full_name_error(self):
        self.assertTrue(self.user_form.errors.has_key('full_name'))
Пример #13
0
def member_form(request):
    try:
        member = Member.objects.get(user=request.user)
    except Member.DoesNotExist:
        member = Member()
    user_form = UserForm(request.POST or None, instance=request.user)
    member_form = MemberForm(request.POST or None, instance=member)
    if request.POST:
        if member_form.is_valid() and user_form.is_valid():
            member_form.save(user=request.user)
            user_form.save()
            messages.add_message(request, messages.INFO, 'Seus dados foram atualizados com sucesso')
            return HttpResponseRedirect(reverse('members-dashboard'))
        else:
            messages.add_message(request, messages.ERROR, 'Ocorreu um erro ao tentar salvar seus dados. verifique o form abaixo.')

    return render(request,
        "members/member_form.html", {
            "member_form": member_form,
            'user_form': user_form
        }
    )
Пример #14
0
def member_form(request):
    try:
        member = Member.objects.get(user=request.user)
    except Member.DoesNotExist:
        member = Member()
    user_form = UserForm(request.POST or None, instance=request.user)
    member_form = MemberForm(request.POST or None, instance=member)
    if request.POST:
        if member_form.is_valid() and user_form.is_valid():
            member_form.save(user=request.user)
            user_form.save()
            messages.add_message(request, messages.INFO, _('Your data was updated successfully'))
            return HttpResponseRedirect(reverse('members-dashboard'))
        else:
            messages.add_message(request, messages.ERROR, _('An error occurred while trying to save your data. check the form below. '))

    return render(
        request,
        "members/member_form.html", {
            "member_form": member_form,
            'user_form': user_form
        }
    )
Пример #15
0
class InvalidUserFormTest(TestCase):
    def setUp(self):
        self.user_form = UserForm({})

    def test_must_be_invalid(self):
        self.assertFalse(self.user_form.is_valid())

    def test_with_no_data_should_return_first_name_error(self):
        self.assertIn('first_name', self.user_form.errors)

    def test_with_no_data_should_return_last_name_error(self):
        self.assertIn('last_name', self.user_form.errors)

    def test_with_no_data_should_return_email_error(self):
        self.assertIn('email', self.user_form.errors)
Пример #16
0
class InvalidUserFormTest(TestCase):
    def setUp(self):
        self.user_form = UserForm({})

    def test_must_be_invalid(self):
        self.assertFalse(self.user_form.is_valid())

    def test_with_no_data_should_return_first_name_error(self):
        self.assertIn('first_name', self.user_form.errors)

    def test_with_no_data_should_return_last_name_error(self):
        self.assertIn('last_name', self.user_form.errors)

    def test_with_no_data_should_return_email_error(self):
        self.assertIn('email', self.user_form.errors)
Пример #17
0
class MemberFormTest(TestCase):

    def setUp(self):
        self.data = {
        'full_name': 'Valder Gallo Jr',
        'organization': 'Home',
        'cpf': '94463643104',
        'email': '*****@*****.**',
        'phone': '1199492911',
        'city': 'Sao Paulo',
        'state': 'SP',
        'category': '1',
        'relationship': 'think',
        'mailling': 1,
        'contact': 1,
        }
        self.user_form = UserForm(self.data)
        self.user_form.is_valid()

        self.member_form = MemberForm(self.data)
        self.member_form.is_valid()

    def test_clean_full_name_firstname(self):
        self.assertEqual(self.user_form.cleaned_data.get('first_name'), 'Valder')

    def test_clean_full_name_lastname(self):
        self.assertEqual(self.user_form.cleaned_data.get('last_name'), 'Gallo Jr')

    def test_clean_organization(self):
        self.assertIsInstance(self.member_form.cleaned_data.get('organization'), Organization)

    def test_clean_city(self):
        self.assertIsInstance(self.member_form.cleaned_data.get('city'), City)

    def test_save(self):
        new_user = self.user_form.save()
        self.assertIsInstance(new_user, User)

    def test_created_object_city(self):
        user_instance = self.user_form.save()
        self.member_form.save(user_instance)
        city = City.objects.get()
        self.assertEqual(city.name, self.data.get('city'))

    def test_created_object_organization(self):
        user_instance = self.user_form.save()
        self.member_form.save(user_instance)
        organization = Organization.objects.get()
        self.assertEqual(organization.name, self.data.get('organization'))

    def test_should_create_an_user(self):
        user_instance = self.user_form.save()
        self.member_form.save(user_instance)
        self.assertEqual(user_instance.get_full_name(), self.data.get('full_name'))
Пример #18
0
    def setUp(self):
        self.data = {
        'full_name': 'Valder Gallo Jr',
        'organization': 'Home',
        'cpf': '94463643104',
        'email': '*****@*****.**',
        'phone': '1199492911',
        'city': 'Sao Paulo',
        'state': 'SP',
        'category': '1',
        'relationship': 'think',
        'mailling': 1,
        'contact': 1,
        }
        self.user_form = UserForm(self.data)
        self.user_form.is_valid()

        self.member_form = MemberForm(self.data)
        self.member_form.is_valid()
Пример #19
0
    def setUp(self):
        super(ValidUserFormTest, self).setUp()

        self.user_form = UserForm(self.data)
        self.user_form.is_valid()
        self.new_user = self.user_form.save()
Пример #20
0
class ValidMemberFormTest(MemberFormTest):
    def setUp(self):
        self.user_form = UserForm(self.data)
        self.user_form.is_valid()

        self.member_form = MemberForm(self.data)
        self.member_form.is_valid()
        self.user_instance = self.user_form.save()
        self.member_instance = self.member_form.save(self.user_instance)

    def test_form_must_be_valid(self):
        self.assertTrue(self.member_form.is_valid())

    def test_should_store_location(self):
        self.assertEqual(self.member_instance.location, 'Sao Paulo')

    def test_should_store_organization(self):
        organization = Organization.objects.get(name='Home')
        self.assertEqual(self.member_instance.organization, organization)

    def test_should_store_cpf(self):
        self.assertEqual(self.member_instance.cpf, self.data.get('cpf'))

    def test_should_store_phone(self):
        self.assertEqual(self.member_instance.phone, '11-9949-2911')

    def test_should_store_address(self):
        self.assertEqual(self.member_instance.address, self.data.get('address'))

    def test_should_store_category(self):
        category = Category.objects.get(id=self.data.get('category'))
        self.assertEqual(self.member_instance.category, category)

    def test_change_category_with_pending_payments(self):
        payment = Payment.objects.create(
            member=self.member_instance,
            type=PaymentType.objects.get(id=1)
        )

        transaction = Transaction.objects.create(
            payment=payment,
            status=0,
            code='fakecode',
            price='0.0'
        )

        self.member_instance.save()

        member_form = MemberForm(instance=self.member_instance, data={'category': 2})

        self.assertFalse(self.member_instance.get_payment_status())
        self.assertFalse(member_form.is_valid())

        self.assertEqual(member_form.errors['category'], [u"You can't change your category with pending payments"])

    def test_should_store_relation_with_community(self):
        self.assertEqual(self.member_instance.relation_with_community, self.data.get('relation_with_community'))

    def test_should_store_mailing(self):
        self.assertEqual(self.member_instance.mailing, self.data.get('mailing'))

    def test_should_store_partner(self):
        self.assertEqual(self.member_instance.partner, self.data.get('partner'))
Пример #21
0
class ValidMemberFormTest(MemberFormTest):
    def setUp(self):
        self.user_form = UserForm(self.data)
        self.user_form.is_valid()

        self.member_form = MemberForm(self.data)
        self.member_form.is_valid()
        self.user_instance = self.user_form.save()
        self.member_instance = self.member_form.save(self.user_instance)

    def test_form_must_be_valid(self):
        self.assertTrue(self.member_form.is_valid())

    def test_should_store_location(self):
        self.assertEqual(self.member_instance.location, 'Sao Paulo')

    def test_should_store_organization(self):
        organization = Organization.objects.get(name='Home')
        self.assertEqual(self.member_instance.organization, organization)

    def test_should_store_cpf(self):
        self.assertEqual(self.member_instance.cpf, self.data.get('cpf'))

    def test_should_store_phone(self):
        self.assertEqual(self.member_instance.phone, '11-9949-2911')

    def test_should_store_address(self):
        self.assertEqual(self.member_instance.address,
                         self.data.get('address'))

    def test_should_store_category(self):
        category = Category.objects.get(id=self.data.get('category'))
        self.assertEqual(self.member_instance.category, category)

    def test_change_category_with_pending_payments(self):
        payment = Payment.objects.create(member=self.member_instance,
                                         type=PaymentType.objects.get(id=1))

        transaction = Transaction.objects.create(payment=payment,
                                                 status=0,
                                                 code='fakecode',
                                                 price='0.0')

        self.member_instance.save()

        member_form = MemberForm(instance=self.member_instance,
                                 data={'category': 2})

        self.assertFalse(self.member_instance.get_payment_status())
        self.assertFalse(member_form.is_valid())

        self.assertEqual(
            member_form.errors['category'],
            [u"You can't change your category with pending payments"])

    def test_should_store_relation_with_community(self):
        self.assertEqual(self.member_instance.relation_with_community,
                         self.data.get('relation_with_community'))

    def test_should_store_mailing(self):
        self.assertEqual(self.member_instance.mailing,
                         self.data.get('mailing'))

    def test_should_store_partner(self):
        self.assertEqual(self.member_instance.partner,
                         self.data.get('partner'))
Пример #22
0
 def setUp(self):
     self.user_form = UserForm({})
Пример #23
0
 def setUp(self):
     self.user_form = UserForm(self.data)
     self.user_form.is_valid()
     self.new_user = self.user_form.save()
Пример #24
0
 def setUp(self):
     self.user_form = UserForm(self.data)
     self.user_form.is_valid()
     self.new_user = self.user_form.save()
Пример #25
0
 def setUp(self):
     self.user_form = UserForm({})