def test_invalid_form_not_enough_funds_in_the_account_2(self): data = {'user_send_id': '1', 'summ': Decimal('0.01'), 'inn': 1234} form = TransactionForm(data=data) self.assertFalse(form.is_valid()) self.assertEqual(form.errors, {'user_send_id': ['На счете списания не достаточно средств.']} )
def test_invalid_form_(self): data = {'user_send_id': '6', 'summ': Decimal('20.00'), 'inn': 2222} form = TransactionForm(data=data) self.assertFalse(form.is_valid()) self.assertEqual(form.errors, {'inn': ['Это ИНН отправителя. Других пользователей с этим ИНН в базе нет.']} )
def test_invalid_form_lack_of_users_with_this_inn(self): data = {'user_send_id': '1', 'summ': Decimal('10.00'), 'inn': 123} form = TransactionForm(data=data) self.assertFalse(form.is_valid()) self.assertEqual(form.errors, {'inn': ['Пользователей с указанным ИНН нет в базе данных.']} )
def test_invalid_form_inn_field_can_not_null_inn_field_can_not_null(self): data = {'user_send_id': '1', 'summ': Decimal('0.00'), 'inn': 0} form = TransactionForm(data=data) self.assertFalse(form.is_valid()) self.assertEqual(form.errors, {'inn': ['ИНН не может быть равным нулю.'], 'summ': ['Сумма перевода не должна быть равной нулю.']} )
def test_invalid_form_not_enough_funds_in_the_account_lack_of_inn_field(self): data = {'user_send_id': '1', 'summ': Decimal('121.00')} form = TransactionForm(data=data) self.assertFalse(form.is_valid()) self.assertEqual(form.errors, {'user_send_id': ['На счете списания не достаточно средств.'], 'inn': ['Обязательное поле.']} )
def get_context_data(self, **kwargs): current_site = get_current_site(self.request) context = super(UserDetailView, self).get_context_data(**kwargs) context['domain'] = current_site.domain context['products'] = Products.objects.order_by('level') context['transaction_form'] = TransactionForm(self.request.POST) context['password_change_form'] = PasswordChangeForm(self.request.POST) context['transfer_form'] = TransferForm(self.request.POST) return context
def get(self, request, pk=None, account=None): if pk: instance = get_object_or_404(TransactionEntry, pk=pk) form = TransactionForm(instance=instance) else: form = TransactionForm( initial={ 'date': datetime.date.today(), 'from_account': account, 'entry_type': 'T' }) context = { 'accounts': self.get_accounts(), 'account_subtypes': self.get_account_groups(), 'form': form, 'active': self.get_active_account(account) } return render(request, 'main/create_edit.html', context)
def new_transtaction(request): TEST = False # Retrieve post by id if request.method == 'POST': # Form was submitted form = TransactionForm(request.POST) if form.is_valid(): if TEST: pass else: form_clean = form_processing(form, request.user) to_cl_out = scv_cl_out(form_clean) to_ag_out = scv_ag_out(form_clean) trans = cs_trans_form(form_clean, to_cl_out, to_ag_out) return HttpResponseRedirect(reverse_lazy('transtaction-list')) #Create a new transaction with default status to delivered else: data = {'from_agent_number': request.user.username} form = TransactionForm(initial=data) return render(request, 'main/new_transtaction.html', {'form': form})
def post(self, request, pk=None, account=None): redirect = reverse('transactions', kwargs={'account': account}) try: form = TransactionForm( request.POST, instance=TransactionEntry.objects.get(pk=pk)) except ObjectDoesNotExist: form = TransactionForm(request.POST) context = { 'accounts': self.get_accounts(), 'account_subtypes': self.get_account_groups(), 'form': form, 'active': self.get_active_account(account) } if form.is_valid(): form.save() self.update_balance() return HttpResponseRedirect(redirect) else: return render(request, 'main/create_edit.html', context)
def get(self, request): id_from_account = request.GET.get('from_account') form = TransactionForm(initial={'from_account': id_from_account}) return render(request, 'main/to_account_list_options.html', {'form': form})
def test_invalid_form_field_inn_required_field_summ_required(self): data = {'user_send_id': '1',} form = TransactionForm(data=data) self.assertFalse(form.is_valid()) self.assertEqual(form.errors, {'summ': ['Обязательное поле.'], 'inn': ['Обязательное поле.']})
def test_valid_form(self): data = {'user_send_id': '1', 'summ': Decimal('10.00'), 'inn': 1234} form = TransactionForm(data=data) self.assertTrue(form.is_valid()) self.assertEqual(form.errors, {})